Moving to Tailwind CSS 4: config moves into CSS
Tailwind CSS 4 came out in January, and the headline is speed: a new engine that builds in milliseconds. But the change you'll notice first is that tailwind. config.
Tailwind CSS 4 came out in January, and the headline is speed: a new engine that builds in milliseconds. But the change you’ll notice first is that tailwind.config.js is gone by default. Your theme now lives in your CSS file, as CSS variables. A few utilities also quietly changed size, which is the part worth slowing down for.
Setup is one line of CSS
/* app.css */
@import "tailwindcss";
That replaces the three @tailwind directives from v3. The build tools moved into separate packages: @tailwindcss/vite for Vite, @tailwindcss/postcss for PostCSS, and @tailwindcss/cli for the command line. For Vite:
// vite.config.js
import { defineConfig } from 'vite';
import tailwindcss from '@tailwindcss/vite';
export default defineConfig({
plugins: [tailwindcss()],
});
There’s no content array either. Tailwind finds your templates by itself. More on that below, because it has a catch.
The theme is CSS now
Extending the theme happens in an @theme block, using a naming convention that maps variables to utilities:
@import "tailwindcss";
@theme {
--color-brand-500: oklch(0.62 0.19 259);
--font-display: "Inter", sans-serif;
--breakpoint-3xl: 120rem;
}
From those three lines you get bg-brand-500, text-brand-500 and the rest of the colour utilities, font-display, and a 3xl: breakpoint variant. I built it to check: bg-brand-500 compiles to background-color: var(—color-brand-500).
That var() is the real improvement. Theme values are now actual CSS custom properties on the page, so everything else can use them too: a third-party component, an inline style, a chart’s colours, a
Custom utilities have their own directive now, instead of @layer utilities:
@utility content-auto {
content-visibility: auto;
}
That works with variants (hover:content-auto, lg:content-auto) automatically.
If you’re not ready to move a big config file, you can still load it:
@import "tailwindcss";
@config "../tailwind.config.js";
Automatic detection, and where it goes wrong
Without a content array, Tailwind scans your project for class names. It skips files listed in .gitignore, binary files and CSS files.
Notice what’s not on that list: node_modules. In a normal project, node_modules is in .gitignore, so it’s skipped. But in a folder that isn’t a git repository, or one without a .gitignore, Tailwind scans your dependencies too, and generates every class-like string it finds in them. In my test project, the same input CSS built to 23 KB with a .gitignore and 66 KB without one, with utilities like bg-red-500 that I never used.
If your build output is suspiciously large, or you have a monorepo where the root isn’t what you want scanned, set the base path explicitly:
@import "tailwindcss" source("../src");
or turn detection off and list sources yourself:
@import "tailwindcss" source(none);
@source "../src";
@source "../../packages/ui/src";
The utilities that changed size
This is the part that doesn’t break your build, it just changes how things look. Several scales shifted down a step, so the old name now means something bigger:
| You wrote in v3 | v4 equivalent |
|---|---|
| shadow-sm | shadow-xs |
| shadow | shadow-sm |
| rounded-sm | rounded-xs |
| rounded | rounded-sm |
| blur-sm | blur-xs |
| outline-none | outline-hidden |
So after upgrading, every shadow-sm in your code is a slightly bigger shadow than it was. Nothing errors.
Two defaults changed too:
- ring is 1px and uses the current text colour. In v3 it was 3px and blue. Write ring-3 ring-blue-500 to keep the old look.
- Borders default to the current text colour, not gray-200. A bare border on a dark-text element is now a dark border. Add a colour, like border-gray-200, wherever you relied on the default.
Opacity utilities like bg-opacity-50 are gone, replaced by the slash syntax you may already use: bg-black/50. In v4 it compiles to color-mix().
Use the upgrade tool
Renames like these are exactly what tools are for:
npx @tailwindcss/upgrade
It moves your config into CSS, swaps the directives, and renames utilities across your templates, including the size shifts above. Run it on a clean branch, read the diff, and click through the app afterwards. It handles class names it can find. Classes built from strings at runtime, like shadow-${size}, it can’t see.
Check your browser support first
v4 leans on modern CSS: cascade layers, @property and color-mix(). It targets Safari 16.4, Chrome 111 and Firefox 128 or newer. If you have to support older browsers, stay on v3.4 for now. That’s a real reason not to upgrade, not just caution.
Is it worth it?
For new projects, yes. Setup is simpler, builds are fast, and having the theme as CSS variables removes a whole class of “how do I get my Tailwind colours into this other thing” problems. For an existing project, the upgrade tool does most of the work. Budget your time for the visual review afterwards, because the changes that matter here are the ones that don’t throw errors.