Sub topic 13
Differences from v3 setup
This chapter assumes you have a working Vite project with Tailwind v4 installed through @tailwindcss/vite, as built in the earlier chapters. It compares that setup with the v3 setup you may know, so you can migrate a project or read older tutorials without confusion.
What changed in the setup
Most v3 installation steps either disappear or move into CSS. The table maps each v3 step to its v4 replacement.
| Concern | v3 | v4 with Vite |
|---|---|---|
| Packages | `tailwindcss`, `postcss`, `autoprefixer` | `tailwindcss`, `@tailwindcss/vite` |
| Build integration | PostCSS config listing `tailwindcss` and `autoprefixer` | `tailwindcss()` in the `plugins` array of `vite.config.ts` |
| Config file | `tailwind.config.js`, created with `npx tailwindcss init` | None required |
| CSS entry | Three `@tailwind` directives | One `@import "tailwindcss";` |
| Finding class names | `content` array in the config file | Automatic detection, extended with `@source` |
| Theme customization | `theme.extend` in JavaScript | `@theme` block in CSS |
The CSS entry file
In v3, your stylesheet started with three directives:
@tailwind base;
@tailwind components;
@tailwind utilities;In v4, a single import replaces all three:
@import "tailwindcss";The old directives no longer work in v4. If you copy an older stylesheet into a new project, you will get no generated styles.
The build integration
A v3 project routes CSS through PostCSS. A v4 project on Vite registers the plugin directly:
import { defineConfig } from 'vite'
import tailwindcss from '@tailwindcss/vite'
export default defineConfig({
plugins: [
tailwindcss(),
],
})You do not need autoprefixer or a separate import handler. Tailwind v4 handles vendor prefixes and @import itself. A postcss.config.js file is only needed if you choose the PostCSS route described in the previous chapter.
Configuration moves into CSS
v3 stored design tokens in tailwind.config.js. v4 stores them in your stylesheet, next to the rules that use them:
@import "tailwindcss";
@theme {
--color-brand: #3b82f6;
--font-display: "Georgia", serif;
}Each variable name follows a namespace convention. --color-brand produces bg-brand, text-brand, and related utilities. --font-display produces font-display.
The content option has no direct counterpart. Tailwind scans your project automatically, and you add extra locations with @source.
@import "tailwindcss";
@source "../node_modules/@my-company/ui-lib";Other differences to expect
- Browser targets. v4 relies on modern CSS features, so it targets recent browsers only. Projects that must support older browsers should stay on v3.
- Renamed and removed utilities. Some v3 utility names changed in v4, and deprecated ones were removed. Check the official upgrade guide when migrating existing markup.
- A JavaScript config is optional. You can still load a legacy config from CSS with the
@configdirective, which helps during a gradual migration.
Diagram of the setup flow
Common migration mistakes
- Keeping the three
@tailwinddirectives. Replace them with@import "tailwindcss";. - Leaving
tailwindcssin the PostCSS plugin list. In v4, the PostCSS plugin is@tailwindcss/postcss. - Expecting
contentglobs to work. Remove them and rely on automatic detection, or use@source.
Exercise
You inherit a project whose CSS starts with @tailwind base;, @tailwind components; and @tailwind utilities;, and which uses content: ["./src/**/*.html"] in tailwind.config.js. After upgrading to v4 with the Vite plugin, no styles appear. Which two changes does the stylesheet and config need?
Show answer
Replace the three @tailwind directives with @import "tailwindcss";. Remove the content array, because v4 detects source files automatically. If some class names live in a directory Tailwind does not scan, add an @source line for it.