search
React star Featured

How to Upgrade Tailwind CSS v3 to v4 in a React + Vite Project (Step-by-Step)

Learn how to upgrade Tailwind CSS from v3 to v4 in a React Vite project. This guide explains every change, updated configs, directory structure, and common migration issues.

person By Gautam Sharma
calendar_today January 1, 2026
schedule 3 min read
Tailwind CSS React Vite Frontend CSS

Upgrading Tailwind CSS from v3 to v4 is one of the biggest frontend improvements for modern projects. Tailwind v4 introduces a faster Rust-based engine, removes unnecessary configuration files, and adopts a CSS-first configuration approach, making it perfect for React + Vite projects.

This article walks you through the complete migration process, explains why each step is required, and provides clean code examples and directory structure.


What’s New in Tailwind CSS v4

Before upgrading, let’s understand the major changes:

  • πŸš€ New Rust-based compiler (much faster)
  • ❌ No tailwind.config.js by default
  • ❌ No postcss.config.js
  • βœ… CSS-first configuration using @theme and @layer
  • ⚑ Faster builds with Vite

Existing Tailwind v3 Project Structure

A typical React + Vite + Tailwind v3 setup looks like this:

my-app/
β”œβ”€β”€ index.html
β”œβ”€β”€ postcss.config.js
β”œβ”€β”€ tailwind.config.js
β”œβ”€β”€ package.json
β”œβ”€β”€ vite.config.js
└── src/
    β”œβ”€β”€ App.jsx
    β”œβ”€β”€ main.jsx
    └── index.css

Step 1: Remove Tailwind v3 Dependencies

Uninstall Tailwind v3 and related tooling:

npm uninstall tailwindcss postcss autoprefixer

Tailwind v4 no longer relies on PostCSS or Autoprefixer.


Step 2: Install Tailwind CSS v4

Install the latest Tailwind CSS version:

npm install tailwindcss@latest

No initialization command is needed.


Step 3: Remove Old Configuration Files

Delete the following files:

tailwind.config.js
postcss.config.js

Why?

Tailwind v4 automatically detects your files and uses CSS-based configuration instead of JavaScript.


Step 4: Update Your Main CSS File

Open src/index.css.

Tailwind v3 Syntax (Old)

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

Tailwind v4 Syntax (New)

@import "tailwindcss";

This single line replaces all previous Tailwind directives.


Step 5: Configure Theme and Utilities (CSS-First)

Tailwind v4 moves configuration into CSS.

@import "tailwindcss";

@theme {
  --color-brand: #2563eb;
  --font-display: "Inter", sans-serif;
}

@layer utilities {
  .center {
    @apply flex items-center justify-center;
  }
}

Benefits

  • No JavaScript config file
  • Faster builds
  • Easier maintenance

Step 6: Ensure CSS Is Imported in React

Update src/main.jsx:

import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import "./index.css";

ReactDOM.createRoot(document.getElementById("root")).render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

Step 7: Test Tailwind v4

Update App.jsx:

export default function App() {
  return (
    <div className="min-h-screen bg-slate-900 text-white flex items-center justify-center">
      <h1 className="text-4xl font-bold text-brand">
        Tailwind CSS v4 with React + Vite πŸš€
      </h1>
    </div>
  );
}

Run the project:

npm run dev

If styles apply correctly, the upgrade is successful.


Final Project Structure (Tailwind v4)

my-app/
β”œβ”€β”€ index.html
β”œβ”€β”€ package.json
β”œβ”€β”€ vite.config.js
└── src/
    β”œβ”€β”€ App.jsx
    β”œβ”€β”€ main.jsx
    └── index.css

Cleaner, faster, and easier to maintain.


Common Migration Issues

Tailwind styles not working

  • Restart the dev server
  • Ensure @import "tailwindcss"; exists
  • Ensure CSS is imported in main.jsx

Custom theme missing

  • Move theme values to @theme in CSS
  • Do not use tailwind.config.js

Performance Improvements After Upgrade

  • Faster cold starts
  • Instant rebuilds
  • Smaller dependency tree
  • Ideal for Vite-powered projects

Conclusion

Tailwind CSS v4 simplifies frontend development by removing unnecessary configuration and embracing modern tooling. For React + Vite projects, upgrading from v3 to v4 results in cleaner code, faster builds, and a better developer experience.

If you’re building modern web apps in 2026, Tailwind v4 is the right choice.


Gautam Sharma

About Gautam Sharma

Full-stack developer and tech blogger sharing coding tutorials and best practices

Related Articles

React

Fix: process is not defined error in React Vite - Complete Solution Guide

Learn how to fix the 'process is not defined' error in React Vite projects. This guide covers environment variables, Node.js compatibility, and best practices for Vite configuration.

January 1, 2026
React

How to Fix CORS Error in React Vite Project: Complete Guide 2026

Learn how to fix CORS errors in React Vite projects with step-by-step solutions. This guide covers proxy setup, server configurations, and best practices for handling cross-origin requests.

January 1, 2026
React

How to Upgrade React Version in an Existing Project (Step-by-Step Guide)

Learn how to safely upgrade the React version in an existing project. This step-by-step guide explains dependencies, breaking changes, testing, and best practices.

January 1, 2026