Why v4?
Since 2019, Tailwind CSS has become one of the most popular utility-first CSS frameworks. But the JIT engine introduced in v3, the growing complexity of tailwind.config.js , and the PostCSS dependency gave the team plenty of reasons to build something new from the ground up.
The main goal of v4 is simple: more speed, less configuration, and greater use of CSS standards. And spoiler: it largely delivers.
Oxide Engine
At the heart of v4 is Oxide, a new build engine written in Rust. This change brings a dramatic improvement in compilation times:
Initial build
~1,500ms
~35ms
Incremental build
~150ms
~4ms
How was this measured?
These figures come from Tailwind’s own benchmark tests. The ratios can vary with the size of a real project, but the overall trend is consistent.
The CSS-First Approach
In v3, configuration lived in JavaScript. v4 changes that approach: configuration now lives directly in your CSS file, starting with @import "tailwindcss".
/* postcss.config.js */
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
/* tailwind.config.js */
module.exports = {
content: ['./src/**/*.{js,ts,jsx,tsx}'],
theme: {
extend: {
colors: { brand: '#0ea5e9' }
}
}
}/* globals.css — everything in one file */
@import "tailwindcss";
@theme {
--color-brand: #0ea5e9;
--font-display: 'Geist', sans-serif;
--radius-card: 0.75rem;
}With Vite, you can use the @tailwindcss/vite plugin instead of a PostCSS setup.
The @theme Directive
@theme makes each variable available as both a CSS custom property and a Tailwind utility class.
@theme {
/* This definition generates:
- CSS var: --color-electric
- Utility: bg-electric, text-electric, border-electric
*/
--color-electric: oklch(65% 0.25 250);
/* Spacing */
--spacing-18: 4.5rem; /* → p-18, m-18, gap-18 */
/* Animations */
--animate-slide-in: slide-in 0.3s ease-out;
}The OKLCH color space
v4 encourages OKLCH color definitions. Modern browsers with support for the wide P3 color gamut can display much more vivid colors.
New Features
v4 is more than a refactor: it introduces new utilities and variants:
field-sizing-contentNew utilityTextareas can grow to fit their content with a single utility class.
@starting-style supportNew variantAnimate elements appearing from display: none using native CSS.
not-* variantNew variantNegation variants such as not-hover:opacity-50 are now built in.
inert variantNew variantApply styles to elements with the inert attribute.
Migrating to v4
An official migration tool is available for upgrading from v3 to v4. It handles most breaking changes automatically:
# Automatic migration
npx @tailwindcss/upgrade@next
# Manual setup (new project)
npm install tailwindcss@next @tailwindcss/viteA summary of the main differences between v3 and v4:
| Feature | v3 | v4 |
|---|---|---|
| Configuration | tailwind.config.js | CSS @theme directive |
| Build tooling | PostCSS | Vite plugin / CLI / PostCSS |
| Initial build | ~1.5s | ~35ms |
| Incremental build | ~150ms | ~4ms |
| CSS variables | Manual | Automatically generated |
| dark: variant | class / media | + @custom-variant |
Breaking changes
bg-opacity-*, text-opacity-* and similar utilities have been removed. Instead, use the bg-black/50 syntax. The migration tool converts most of these automatically.
Conclusion
Tailwind CSS v4 is both a technical rewrite and a shift in approach. CSS-first configuration relies more closely on modern web standards such as cascade layers, custom properties, and OKLCH.
The difference in build speed is noticeable during everyday development. On larger projects, nearly instant incremental builds make the workflow much smoother.
Starting a new project? Use v4 directly. For an existing project, try the migration tool and review any changes it makes.
Arda Abacı
Jr. Full-Stack Web Developer