Should you upgrade?
Tailwind CSS v4 brings significant improvements:- 5x faster full builds and over 100x faster incremental builds
- Zero configuration with automatic content detection
- CSS-first configuration using native CSS features
- Modern CSS features like cascade layers,
@property, andcolor-mix() - First-party integrations including a Vite plugin and CLI
- Modernized color palette with P3 color support
- Container queries and new 3D transforms built-in
Before you upgrade
Prerequisites
- Ensure you’re on Tailwind CSS v3.x - The upgrade tool only supports migrating from v3 to v4
- Commit your changes - The upgrade tool requires a clean git directory
- Backup your project - While the tool is robust, having a backup is always wise
- Review your dependencies - Some third-party plugins may need updates
Version compatibility
The@tailwindcss/upgrade tool will verify that:
- Your installed version matches your
package.json - You’re running Tailwind CSS v3.x (not v2 or earlier)
- All dependencies are properly installed
Migration approaches
There are two ways to upgrade your project:Automated upgrade (recommended)
Use the@tailwindcss/upgrade tool to automatically migrate your entire project:
- Migrate CSS files from v3 syntax to v4
- Convert JavaScript config files to CSS
@themeblocks - Update all template files with renamed utilities
- Install the latest Tailwind CSS packages
- Update PostCSS configuration if needed
Manual upgrade
For more control, you can upgrade manually:/* Before (v3) */
@tailwind base;
@tailwind components;
@tailwind utilities;
/* After (v4) */
@import "tailwindcss";
Convert your JavaScript config to CSS theme variables. See the v3 to v4 Migration Guide for specific breaking changes.
What the upgrade changes
The upgrade process modifies:CSS files
- Converts
@tailwinddirectives to@import "tailwindcss" - Migrates
@layer utilitiesto@utilitysyntax - Converts
@applystatements to use updated class names - Adds
@themeblocks with your customizations - Updates
@importstatements to includelayer()where needed
JavaScript configuration
- Converts
tailwind.config.jsto CSS@themeblocks - Migrates theme customizations to CSS variables
- Converts custom variants to
@custom-variant - Handles plugin configurations
- Removes the config file if fully migrated
Template files
- Updates all renamed utility classes (see v3 to v4 guide)
- Migrates arbitrary values to named values where possible
- Updates variant syntax to v4 conventions
- Canonicalizes class names to their preferred form
Dependencies
Updates these packages to their latest versions:tailwindcss@tailwindcss/cli@tailwindcss/postcss@tailwindcss/viteprettier-plugin-tailwindcss
Common upgrade scenarios
Vite projects
For Vite projects, the upgrade tool will:- Install
@tailwindcss/vite - Update your Vite configuration
- Remove PostCSS config if no longer needed
- Update your CSS imports
PostCSS projects
For PostCSS-based projects:- Updates to use
@tailwindcss/postcss - Removes autoprefixer (now built-in)
- Updates PostCSS configuration
Next.js projects
For Next.js:- Updates CSS imports in your global stylesheet
- Migrates configuration to CSS
- Preserves Next.js-specific optimizations
Monorepo projects
For monorepos:- Supports multiple config files
- Handles workspace dependencies correctly
- Updates all packages that use Tailwind CSS
Verification steps
After upgrading, verify everything works:@theme {
--color-*: initial; /* Your colors */
}
@media (prefers-color-scheme: dark) {
@theme {
--color-*: initial; /* Dark colors */
}
}
Troubleshooting
Git directory not clean
If you see “Git directory is not clean”:Version mismatch errors
Configuration not migrating
Some configuration options can’t be automatically migrated:- Complex plugin configurations
- Custom variant functions
- Dynamic theme values
Class names not updating
If some class names aren’t updated:- Check if they’re in ignored files (node_modules, etc.)
- Verify file extensions are recognized
- Look for dynamic class generation that can’t be statically analyzed
Getting help
If you encounter issues:- Check the v3 to v4 Migration Guide for breaking changes
- Review the Codemods documentation for tool details
- Visit the GitHub Discussions
- Report bugs on GitHub Issues
Next steps
After upgrading:- Review the CHANGELOG for new features
- Explore new utilities like container queries and 3D transforms
- Take advantage of CSS-first configuration for better IDE support
- Consider using the Vite plugin for optimal performance