How to Upgrade TailwindCSS

Upgrading TailwindCSS might sound tricky, but it’s manageable if you follow the right steps. Whether you’re moving from v2 to v3 or v3 to v4, this guide will help you update your project smoothly. We’ll cover everything from preparation to testing, with simple explanations and handy tips. Ready? Let’s dive in!


Why Upgrade TailwindCSS?

Before we jump into the “how,” let’s talk about the “why.” TailwindCSS v4.0, released in early 2025, brings some awesome improvements:

  • Faster Builds: Up to 5x faster full builds and 100x faster incremental rebuilds.
  • Simpler Setup: No more complex configuration files by default—just one line of CSS.
  • Modern Features: Support for container queries, 3D transforms, and a refreshed color palette.
  • Better Performance: A new engine written in Rust makes it lightning-fast.

Upgrading keeps your project modern, efficient, and ready for the latest web trends. Now, let’s get your project up to speed!


Prerequisites: What You’ll Need

To upgrade TailwindCSS, make sure you have these basics in place:

  • Node.js: Version 20 or higher (v4 requires it for the upgrade tool). Check your version with node -v in your terminal.
  • npm or Yarn: You’ll use one of these package managers to install updates.
  • A Git Repository (Optional): It’s smart to commit your current project to Git before upgrading, so you can roll back if needed.
  • Existing TailwindCSS Setup: This guide assumes you’re already using Tailwind v2 or v3 in your project.

Got all that? Great—let’s move on!


Step 1: Check Your Current Version

First, figure out which version of TailwindCSS you’re using. Open your project’s package.json file and look under devDependencies or dependencies for something like this:

"devDependencies": {
  "tailwindcss": "^3.4.1"
}

The number (e.g., ^3.4.1) tells you your current version. If it’s below v4 (like v2.x or v3.x), you’re ready to upgrade!


Step 2: Review the Upgrade Guide

TailwindCSS provides official upgrade guides for each major version jump:

These guides list breaking changes—like renamed utilities or config updates—so read the one that matches your jump. For v3 to v4, key changes include a new CSS-first approach and removed PostCSS dependencies by default. Don’t skip this—it’ll save you headaches later!


TailwindCSS v4 comes with a handy upgrade tool that automates most of the process. Here’s how to use it:

1. Install the Latest TailwindCSS CLI

Run this command in your project’s root directory (where package.json lives):

npm install -D @tailwindcss/cli@latest

This installs the v4 CLI tool, which includes the upgrade command.

2. Run the Upgrade Command

Now, let the tool do the heavy lifting:

npx @tailwindcss/upgrade

What it does:

  • Updates your package.json with the latest Tailwind dependencies.
  • Migrates your tailwind.config.js (if you have one) to the new v4 format or removes it if unnecessary.
  • Updates your CSS files to use @import "tailwindcss" instead of old @tailwind directives.
  • Adjusts class names that changed in v4 (e.g., shadow-sm becomes shadow-xs).

3. Check the Output

The tool will log what it changed. Review these updates in a new Git branch to keep things safe.

Note: The tool requires Node.js 20+. If you’re on an older version, update Node first (nvm install 20 if you use nvm).


Step 4: Manual Updates (If Needed)

The upgrade tool handles most changes, but some projects need a little extra love. Here’s what to check:

Update Your CSS File

In v3, you might have a CSS file like this:

@tailwind base;
@tailwind components;
@tailwind utilities;

In v4, simplify it to:

@import "tailwindcss";

That’s it! v4 bundles everything into one import. If you have custom styles, keep them below this line.

Update Configuration (Optional)

v4 doesn’t require a tailwind.config.js file anymore—it auto-detects your content. If you have one and want to keep it, update it to the new format. Old v3 config:

module.exports = {
  content: ["./src/**/*.{html,js}"],
  theme: {
    extend: {},
  },
};

New v4 CSS-based config (optional):

@import "tailwindcss";

@theme {
  --color-primary: #1fb6ff;
}

Move customizations to your CSS file unless you prefer JavaScript (still supported but less common now).

Rename Utilities

Some class names changed in v4 for consistency. Examples:

  • shadow-smshadow-xs
  • ring defaults to 1px (was 3px) with currentColor.

Search your codebase for outdated classes and update them. The upgrade tool usually catches these, but double-check!

Remove Old Dependencies

v4 handles imports and prefixes internally, so uninstall these if you have them:

npm uninstall postcss autoprefixer postcss-import

Step 5: Test Your Project

After upgrading, test everything:

  1. Build Your CSS: Run your usual build command (e.g., npx tailwindcss -i input.css -o output.css).
  2. Check Your Site: Open it in a browser and look for broken styles or errors.
  3. Fix Issues: If something looks off (e.g., borders or shadows), tweak your classes based on the v4 docs.

Pro tip: Use npm run dev (or equivalent) to watch for changes as you test.


Step 6: Optimize for Your Framework (Optional)

If you’re using a framework like React, Next.js, or Vite, there’s extra magic in v4:

  • Vite Users: Switch to the Vite plugin for better performance:
npm install -D @tailwindcss/vite

Update vite.config.js:

import { defineConfig } from "vite";
import tailwindcss from "@tailwindcss/vite";

export default defineConfig({
  plugins: [tailwindcss()],
});
  • Next.js Users: New projects skip tailwind.config.js in v4, but for upgrades, keep it if you need custom content paths.

Troubleshooting Common Issues

Ran into a snag? Here’s how to fix common problems:

  • “Error: Cannot find module ‘tailwindcss’”
    Ensure you ran npm install after updating package.json.
  • Styles Not Applying:
    Check your content paths in tailwind.config.js (if used) or confirm your CSS file imports Tailwind correctly.
  • Upgrade Tool Fails:
    Verify Node.js is 20+ and try running npx @tailwindcss/upgrade --force to skip checks.

Still stuck? Ask me—or the Tailwind community on X!


Final Thoughts

Upgrading TailwindCSS to v4 is a breeze with the automated tool, and the performance boosts are worth it. By following these steps—checking your version, running the tool, making manual tweaks, and testing—you’ll have a modern, speedy setup in no time.

Leave a Comment