Ggaibianshiji

tailwind-v3-to-v4

Automated migration from Tailwind CSS v3 to v4. Covers 90%+ of deterministic changes: class renames, opacity syntax, config migration, directive updates, and deprecated utility replacements.

tailwindtailwindcssmigrationv3v4cssfrontendcodemod
Public
1 executions

Run locally

npx codemod tailwind-v3-to-v4

tailwind-v3-to-v4

Automated codemod for migrating Tailwind CSS v3 codebases to v4.

What it does

This codemod automates ~90% of the deterministic migration patterns from Tailwind CSS v3 to v4:

  • Class renames (size shift): shadow-smshadow-xs, rounded-smrounded-xs, blur-smblur-xs
  • Default→sm shift: shadowshadow-sm, roundedrounded-sm, blurblur-sm
  • Outline: outline-noneoutline-hidden, outline-2outline-md, outline-4outline-lg
  • Opacity merge: bg-blue-500 bg-opacity-50bg-blue-500/50 (slash notation)
  • CSS directives: @tailwind base/components/utilities@import "tailwindcss"
  • Deprecated utilities: flex-growgrow, flex-shrinkshrink, overflow-ellipsistext-ellipsis
  • Box decoration: decoration-clonebox-decoration-clone, decoration-slicebox-decoration-slice

Usage

bash

Or run the migration script directly:

bash

What's NOT automated

These patterns require semantic understanding and should be handled manually or with @tailwindcss/upgrade:

  • Config file conversiontailwind.config.js@theme CSS blocks
  • Plugin migration — Custom Tailwind plugins need manual rewriting
  • Dynamic class generation — Template literal classes like `shadow-${size}`

Testing

bash

Case Study

See CASE_STUDY.md for the full migration analysis of Flowbite React.

How it works

The codemod uses class-attribute-scoped regex transforms to ensure zero false positives:

  1. All class renames are restricted to class="..." and className="..." attributes
  2. Word boundary matching prevents partial matches (e.g., shadow-lg won't be affected by shadowshadow-sm)
  3. Prefix-aware matching handles hover:, md:, focus: etc.

Ready to contribute?

Build your own codemod and share it with the community.