Tailwind v3 to v4 migration
Skill a-tokyo/agent-skills/skills/tailwind-v3-to-v4-migration
π§ AI Agent skills for LLMs and AI Agents - Claude, Codex, Cursor etc.
npx -y skills add a-tokyo/agent-skills --skill tailwind-v3-to-v4-migrationAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 14 stars14 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Migrate a project from Tailwind CSS v3 to v4 safely and completely. Runs the official `@tailwindcss/upgrade` codemod, then drives the judgment the codemod can't: reconciling dependencies and PostCSS/Vite/CLI plumbing, porting JS config to CSS-first `@theme` (or keeping it via `@config`), auditing the v4 changed-defaults that silently alter appearance (border/ring/placeholder/cursor/dialog/hover) and applying compat shims, sweeping for renamed/removed utilities, and proving the migration is a visual no-op. Framework-agnostic (Next.js, Vite, Tailwind CLI, plain PostCSS; Vue/Svelte/Astro/CSS-module caveats). USE FOR: upgrading Tailwind 3 to 4, "tailwind v4 migration", `@tailwind` directives error, `@tailwindcss/postcss` setup, tailwind.config.js to CSS @theme, shadow-sm/rounded/ring/ outline-none renames, bg-gradient-to to bg-linear-to. Activate only when an existing Tailwind v3 install is being upgraded. DO NOT USE FOR: setting up Tailwind v4 in a fresh project (no v3 present), downgrading v4βv3, building a new design system from scratch, or non-Tailwind CSS.
The file declares its own license as MIT. That is the authorβs claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
13.3 KB, as published. Nobody here has run it
tailwind-v3-to-v4-migration
Upgrade a codebase from Tailwind CSS v3 to v4. The codemod does ~80% of the mechanical work; this skill supplies the 20% of judgment where migrations actually break β changed defaults, config porting, plugin/animation swaps, and proving nothing moved.
When to use
- Upgrading any project from Tailwind v3.x to v4.x.
- Build errors after a partial upgrade:
@tailwinddirectives unknown, missing@tailwindcss/postcss,Cannot apply unknown utility class,tailwind.configno longer picked up. - Converting
tailwind.config.{js,ts}to CSS-first@theme.
Skip if: the project is already on v4; you need to downgrade; or you only need a brand-new design
system (use tailwind-design-system). Note v4 targets Safari 16.4+, Chrome 111+, Firefox 128+ β
if you must support older browsers, stay on v3.4 (flag this to the operator before proceeding).
The one idea that makes this safe
A correct migration is a visual no-op. Every renamed utility is a pure alias β shadow-smβ
shadow-xs, roundedβrounded-sm, ringβring-3, outline-noneβoutline-hidden all compile to
the same CSS as before. So what changes pixels is almost entirely v4's changed defaults (Step 3);
the few non-default exceptions β the space-x/y-* & divide-* selector change, gradient-variant
preservation, and container config removal β are flagged in Step 4. Rename mechanically, neutralize
the changed defaults, fix those few exceptions, and the rendered output is identical. That is also how
you verify success (Step 5): capture the UI before, prove it's unchanged after.
Procedure
Always work on a branch. Run the steps in order; do not skip Step 0 or Step 3.
Step 0 β Pre-flight & baseline (do not skip)
- Confirm Node 20+ (
node -v) and that the working tree is clean. Create a branch (e.g.tailwind-v4). - Inventory every Tailwind entry point β there may be more than one: each CSS file with
@tailwind/@import "tailwindcss", everytailwind.config.*, everypostcss.config.*, the bundler config (next/vite/webpack), andpackage.json. Monorepos: do this per package. - Record the current setup:
darkModevalue, customtheme.extend,plugins, the package manager (npm/yarn/pnpm/bun), and two easy-to-miss config options that need special handling later:prefix(v4 changestw-flexβtw:flex) andtheme.container(center/paddingare gone in v4 β recreate via@utility container). - Capture a baseline of how the app looks now so you can prove the migration changed nothing:
a screenshot set or a visual-regression run on v3 (see
references/05-verification-playwright.md), or at minimum a list of key pages to eyeball. Confirm the project builds green on v3 first.
Step 1 β Run the official upgrade tool
npx @tailwindcss/upgrade@latest # clean git tree requiredβ¦
npx @tailwindcss/upgrade@latest --force # β¦or pass --force if untracked/uncommitted files exist
The tool refuses to run on a dirty tree (so you can review its diff). Commit/stash unrelated changes,
or use --force. It updates dependencies, migrates the config to CSS where it can, rewrites
@tailwind directives, and codemods most renamed/removed utilities in templates. Review the full
diff β it is a starting point, not the finish line. If it errors (offline, exotic setup, unsupported
config), fall back to the manual path in references/01-breaking-changes.md +
references/02-css-first-config.md and continue. Monorepos: run the tool once per package root and
confirm tailwindcss resolves to 4.x in every package's node_modules β a half-migrated workspace
compiles some packages against v3.
Step 2 β Reconcile dependencies & build plumbing
Verify the tool did these; finish any it missed (references/04-framework-setups.md for your stack):
- Deps: remove
tailwindcss@3; addtailwindcss@^4. Removeautoprefixerandpostcss-import(v4 does prefixing + import inlining itself). - PostCSS:
postcss.config.*β{ plugins: { '@tailwindcss/postcss': {} } }(add the@tailwindcss/postcssdep). Vite: prefer@tailwindcss/viteover PostCSS. CLI:npx tailwindcssβnpx @tailwindcss/cli. - CSS entry:
@tailwind base/components/utilities;β@import "tailwindcss";. - Plugins: delete now-built-in ones (
@tailwindcss/container-queries,@tailwindcss/aspect-ratio, line-clamp) β and remove their deadtheme/usage.@tailwindcss/typographystays but is loaded in CSS via@plugin "@tailwindcss/typography";and must be bumped to a v4-compatible release (β₯0.5.16). containercustomization: if v3 settheme.container.center/padding, those options are gone β recreate as@utility container { margin-inline: auto; padding-inline: 2rem; }or everycontainerloses its centering/padding silently.- Reinstall with the project's package manager so the lockfile updates; the
tailwindcssversion must resolve to 4.x.
Step 3 β Changed-defaults audit + compat shims (the parity killers)
These changed defaults are the main thing that moves pixels (see Step 4 for the few non-default
exceptions). Walk the checklist; for each "relied on", paste the shim into your main CSS (after
@import "tailwindcss";). Full rationale in references/03-compat-shims.md.
- Border/divide color is now
currentColor(wasgray-200). If you use bareborder/dividewithout a color anywhere, add:@layer base { *, ::after, ::before, ::backdrop, ::file-selector-button { border-color: var(--color-gray-200, currentColor); } } - Ring is now 1px /
currentColor(was 3px /blue-500). Replace bareringβring-3; if you relied on the blue default addring-blue-500. (Compat-only escape:@theme { --default-ring-width: 3px; --default-ring-color: var(--color-blue-500); }.) - Placeholder is now current text @ 50% (was
gray-400). To keep v3 look:@layer base { input::placeholder, textarea::placeholder { color: var(--color-gray-400); } } - Buttons now use
cursor: default(waspointer):@layer base { button:not(:disabled), [role="button"]:not(:disabled) { cursor: pointer; } } -
<dialog>margins are reset (was centered):@layer base { dialog { margin: auto; } }if needed. - Hover now applies only on
(hover: hover)devices. If your UI depends on tap-to-hover, add@custom-variant hover (&:hover);. - Dark mode: if v3 used
darkMode: 'class'(or a custom selector), add@custom-variant dark (&:is(.dark, .dark *));. If it used'media', v4's default already matches β do nothing (adding the class variant would break media-driven dark mode).
Two of these are invisible to a screenshot harness: the button-cursor and hover-on-tap shims change behavior, not painted pixels, so visual parity (Step 5) can't confirm them. Decide them by reasoning about the markup (do real
<button>s / touch interactions rely on the v3 default?), not by the pixel diff. Same foroutline-noneβoutline-hidden(the difference only shows in forced-colors mode).
Step 4 β Residual sweep (catch what the codemod missed)
Grep, then fix each real hit against the tables in references/01-breaking-changes.md (which cover the
mechanical rewrites: *-opacity-*β/<n>, flex-shrink/growβshrink/grow, bg-gradient-toβ
bg-linear-to, arbitrary bg-[--x]βbg-(--x), !flexβflex!, theme()βvar(--β¦), etc.):
grep -rEn '@tailwind |bg-gradient-to-|flex-shrink-|flex-grow-|overflow-ellipsis|decoration-slice|decoration-clone|[a-z]+-opacity-[0-9]|outline-none' src
grep -rEn '\b(shadow|rounded|blur|drop-shadow|backdrop-blur)(["'"'"'`[:space:]])' src # bare scales β review, don't blind-replace
grep -rEn 'transition(-colors)?\b' src # if paired with a focus-state outline-* color β set outline-color unconditionally
# only if v3 used a prefix (Step 0): grep -rEn '\bPFX-[a-z]' src # PFX-flex β PFX:flex
Three judgment calls the tables don't make for you:
- Order bare renames after explicit ones:
shadow-smβshadow-xsbefore bareshadowβshadow-sm(same for rounded/blur/drop-shadow/backdrop-blur); word-boundary the bare form sorounded-md/shadow-lgare untouched. The grep is noisy βblur/shadowcollide withplaceholder="blur"and prose; fix only real class lists. space-x/y-*÷-x/y-*selectors changed to:not(:last-child)(no shim). If a list/inline layout shifts, move it to flex/grid +gap.- Gradients now preserve stops across variants β add
via-noneto reset a 3-stop in a state.
Step 5 β Verify (build + browser parity)
build,lint,typecheck, and unit tests must pass.- Prove the visual no-op: re-run the baseline from Step 0 and confirm zero unintended diffs. Pay
special attention to: borders, focus rings, placeholders, dark mode, and any
prose(typography) content. Any diff maps to a missed Step 3 shim or Step 4 rename β fix it, don't accept it. - Check the screenshot-invisible changes by hand: button cursor, hover-on-touch, and forced-colors outline behavior (see the Step 3 note) β confirm these in a real browser, since no pixel diff will.
Decision points
- Port JS config to CSS, or keep it? Default: port
theme.extendto a CSS@theme {}block (nested objects β flat vars:colors.brand.500β--color-brand-500,boxShadow.cardβ--shadow-card,fontFamily.sansβ--font-sans; use@theme inlineforhsl(var(--x))references). Keep the JS file via@config "../tailwind.config.js";when it carries plugin theming that's hard to express in CSS β the classic case is@tailwindcss/typographytheme.extend.typographycustomization (customprose-*modifiers).@configis officially supported v4 usage.corePlugins,safelist,separatorare NOT supported in JS config under v4 (safelist β@source inline(...)). Note: Tailwind's default theme tokens (e.g.--color-gray-200,--color-gray-400) stay available even when you keep a JS config via@config, so the Step 3 compat shims that reference them still resolve. Seereferences/02-css-first-config.md. - CSS directive order:
@import "tailwindcss";must come first; place@config "β¦";and any@theme { β¦ }block after it. - Custom
@layer utilities/@layer componentsclasses β convert to@utility name { β¦ }. - Animation libs:
tailwindcss-animate(v3) βtw-animate-css(@import "tw-animate-css";), utility names unchanged. - Scoped styles (Vue/Svelte/Astro
<style>, CSS modules) lose theme access β add@reference "../app.css";or use raw CSS vars. No Sass/Less/Stylus with v4.
Manual fallback (no codemod)
deps β postcss.config β @import "tailwindcss"; β port theme to @theme (or @config) β Step 3
shims β Step 4 sweep β Step 5 verify. Exhaustive tables: references/01-breaking-changes.md,
references/02-css-first-config.md, references/03-compat-shims.md.
References
references/00-official-upgrade-guide.mdβ the official Tailwind v3βv4 upgrade guide, verbatim (source of truth; everything below distills it). https://tailwindcss.com/docs/upgrade-guidereferences/01-breaking-changes.mdβ complete renamed / removed / syntax-change tables.references/02-css-first-config.mdβ JS theme β@theme;@configfallback; plugins;@utility.references/03-compat-shims.mdβ every changed default + its copy-paste shim and when it's needed.references/04-framework-setups.mdβ Next.js, Vite, CLI, PostCSS, Astro, Vue, Svelte, CSS modules.references/05-verification-playwright.mdβ capture-baseline-then-assert visual-parity recipe.references/06-gotchas.mdβ rename ordering, typography prose port, gradientvia-none, hover-on-tap, monorepos.