← All posts
Design··2 min read

Tailwind CSS v4: A Faster, CSS-First Approach

A closer look at CSS-first configuration, the Oxide engine, and the new @theme directive in Tailwind CSS v4.

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

43× faster

Incremental build

~150ms

~4ms

37× faster
ℹ

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".

css — v3 (old)
/* postcss.config.js */
module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
}

/* tailwind.config.js */
module.exports = {
  content: ['./src/**/*.{js,ts,jsx,tsx}'],
  theme: {
    extend: {
      colors: { brand: '#0ea5e9' }
    }
  }
}
css — v4 (new)
/* 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.

css
@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 utility

Textareas can grow to fit their content with a single utility class.

@starting-style supportNew variant

Animate elements appearing from display: none using native CSS.

not-* variantNew variant

Negation variants such as not-hover:opacity-50 are now built in.

inert variantNew variant

Apply 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:

bash
# Automatic migration
npx @tailwindcss/upgrade@next

# Manual setup (new project)
npm install tailwindcss@next @tailwindcss/vite

A summary of the main differences between v3 and v4:

Featurev3v4
Configurationtailwind.config.jsCSS @theme directive
Build toolingPostCSSVite plugin / CLI / PostCSS
Initial build~1.5s~35ms
Incremental build~150ms~4ms
CSS variablesManualAutomatically generated
dark: variantclass / 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.

#tailwindcss#css#frontend#performance
Arda Abacı

Arda Abacı

Jr. Full-Stack Web Developer

← All posts