Tailwind CSS v4.0 2026: Pure CSS Revolution π
Tailwind CSS v4.0 (released Jan 22, 2025) rewrites the utility framework as pure CSS with Oxide engine, CSS-first config (@theme/@tokens), native cascade layers, container queries, LightningCSS, P3 color space, and registered custom properties. 8x faster builds, 35% smaller bundles, zero JavaScript config.
[image:310]
π― Tailwind v4 vs v3 Breaking Changes
| Feature | Tailwind v3 | Tailwind v4 |
|---|---|---|
| Config | tailwind.config.js | CSS @theme |
| Directives | @tailwind base; | Removed |
| Engine | PostCSS | Oxide + LightningCSS |
| Build Speed | Baseline | 8x faster |
| Bundle Size | 100% | 65% smaller |
| CSS Vars | Limited | Native registered |
π v4 Installation (Zero Config)
Vite (Recommended)
npm i tailwindcss@4.0.0-alpha.20 postcss autoprefixer
npx tailwindcss init
Next.js 15
npm i tailwindcss@4.0.0-alpha.20
/* styles/globals.css - NO @tailwind directives! */
@import "tailwindcss";
@theme {
--color-primary: oklch(70% 0.2 240);
--spacing-12: 3rem;
--font-family-sans: "Inter", ui-sans-serif;
--breakpoint-xs: 475px;
--breakpoint-sm: 640px;
}
π₯ CSS-First Configuration (@theme/@tokens)
/* @theme = Design tokens */
@theme {
/* Colors (P3 + OKLCH) */
--color-white: 0 0% 100%;
--color-slate-50: 0.95 4% 95%;
--color-primary: 0.68 0.2 240; /* OKLCH */
--color-gradient: linear-gradient(135deg, var(--color-primary), hsl(200 100% 50%));
/* Spacing */
--spacing-0: 0px;
--spacing-1: 0.25rem;
--spacing-12: 3rem;
--spacing-full: 100%;
/* Typography */
--font-size-xs: 0.75rem;
--font-weight-bold: 700;
/* Breakpoints */
--breakpoint-sm: 640px;
--breakpoint-md: 768px;
}
/* @tokens = Low-level values */
@tokens {
--radius-sm: 0.25rem;
--shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}
ποΈ New Syntax (Pure CSS)
/* Layers (native cascade layers) */
@layer base, components, utilities;
@layer base {
:root { @theme; }
body { font-family: var(--font-family-sans); }
}
@layer components {
.btn {
@apply px-6 py-3 rounded-lg font-medium transition-all inline-flex items-center gap-2;
}
}
@layer utilities {
.container {
@container;
max-width: 1200px;
margin: 0 auto;
}
}
πͺ Container Queries (Game-Changer)
/* Parent container */
@container class="card" style="--max-w: 32rem;";
.card {
@apply container;
display: grid;
gap: 1rem;
}
/* Child responds to parent size */
@container (min-width: 20rem) {
.card-title { @apply text-xl; }
.card-image { @apply w-48 h-48; }
}
@container (max-width: 20rem) {
.card { @apply flex-col; }
.card-title { @apply text-sm; }
}
π¨ Dynamic Utilities (CSS Vars)
/* Arbitrary values with CSS vars */
.dynamic-height {
height: var(--height, 100vh);
}
.animate-gradient {
background: var(--color-gradient);
background-size: 400% 400%;
animation: gradient-shift 15s ease infinite;
}
<!-- Usage -->
<div class="dynamic-height" style="--height: 500px;">...</div>
<div class="animate-gradient">...</div>
β‘ Production Build (LightningCSS)
// vite.config.ts
import { defineConfig } from 'vite';
import tailwindcss from 'tailwindcss';
export default defineConfig({
css: {
postcss: {
plugins: [tailwindcss()]
}
}
});
// tailwind.config.ts (Optional - CSS preferred)
export default {
content: ['./src/**/*.{html,js,ts,jsx,tsx}'],
theme: {
extend: {
colors: {
primary: 'oklch(70% 0.2 240)'
}
}
}
};
π οΈ Component Layer (shadcn/ui v4)
@layer components {
.btn {
@apply relative inline-flex items-center justify-center whitespace-nowrap
font-medium ring-offset-background transition-colors
focus-visible:outline-none focus-visible:ring-2
focus-visible:ring-ring focus-visible:ring-offset-2
disabled:pointer-events-none disabled:opacity-50;
--radius: 0.5rem;
padding: 0.5rem 1rem;
border-radius: var(--radius);
&[data-variant="outline"] {
@apply border border-input bg-background hover:bg-accent hover:text-accent-foreground;
}
}
.card {
@apply bg-card text-card-foreground rounded-lg border shadow-sm;
}
}
π P3 Colors + OKLCH (Modern Color)
@theme {
/* OKLCH (perceptually uniform) */
--color-primary: oklch(70% 0.2 240);
--color-primary/50: oklch(95% 0.1 240);
--color-primary/90: oklch(45% 0.25 240);
/* CSS color-mix() */
--color-overlay: color-mix(in srgb, var(--color-primary) 12%, transparent 88%);
}
<!-- Alpha variants work everywhere -->
<div class="bg-primary/90 text-primary/10 border-primary/20">...</div>
<div class="backdrop-blur-sm bg-background/80">...</div>
π± RTL + Logical Properties
@layer utilities {
.ltr\:rotate-0 { rotate: 0deg; }
.rtl\:rotate-180 { rotate: 180deg; }
/* Logical properties */
.ps-4 { padding-inline-start: 1rem; }
.pe-6 { padding-inline-end: 1.5rem; }
}
π― Complete Dashboard Example
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdn.tailwindcss.com/4.0.0-alpha.20"></script>
<style>
@layer base {
:root { @theme; }
}
@theme {
--color-primary: oklch(70% 0.2 240);
--spacing-18: 4.5rem;
}
@layer components {
.dashboard { @apply min-h-screen bg-linear-to-br from-slate-50 to-blue-50; }
.card { @apply bg-white/80 backdrop-blur-sm shadow-xl rounded-2xl border border-white/20; }
.btn-primary {
@apply btn bg-primary/90 hover:bg-primary text-white shadow-lg hover:shadow-xl
hover:-translate-y-0.5 transition-all;
}
}
</style>
</head>
<body>
<div class="dashboard">
<div class="container mx-auto p-8 max-w-7xl">
<div class="@container/card max-w-4xl mx-auto">
<div class="card p-8 @container/content">
<h1 class="text-4xl font-bold bg-linear-to-r from-primary to-purple-500 bg-clip-text text-transparent mb-8">
Tailwind v4 Dashboard
</h1>
<div class="grid @lg:grid-cols-3 gap-6">
<div class="card p-6 @container/card-item">
<div class="text-3xl font-bold text-primary mb-2">$12,345</div>
<div class="text-sm text-muted-foreground">Revenue</div>
</div>
</div>
<div class="mt-8 flex gap-4">
<button class="btn-primary px-8 py-3 text-lg">New Action</button>
<button class="btn btn-outline px-8 py-3">Export</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
π Performance Benchmarks
| Metric | Tailwind v3 | Tailwind v4 |
|---|---|---|
| Full Build | 100% | 285% faster |
| Incremental | 100% | 800% faster |
| Package Size | 100% | 65% smaller |
| CSS Output | 100% | 30% smaller |
π― Migration Guide (v3 β v4)
1. Install v4
npm i tailwindcss@next
2. Replace @tailwind directives
β v3
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
β
v4
@import "tailwindcss";
3. Move config to CSS
@theme {
--color-primary: #3b82f6;
}
π― Production Checklist
β [] @import βtailwindcssβ (no directives) β [] CSS @theme configuration β [] Container queries (@container) β [] Cascade layers (@layer) β [] OKLCH/P3 colors β [] LightningCSS (Vite) β [] Zero JS config β [] Dynamic utilities (CSS vars) β [] shadcn/ui v4 components
π― Final Thoughts
Tailwind v4 = CSS framework. Pure CSS config, native cascade layers, container queries, Oxide engine = zero JavaScript, 8x faster builds, modern CSS features. shadcn/ui v4 + CSS vars = enterprise design systems.
2026 Strategy: Tailwind v4 β Production apps (80%) CSS + SCSS β Custom design systems (15%) Vanilla CSS β Micro-interactions (5%)
Build lightning-fast UIs with Tailwind v4βs CSS-native power π.
Tailwind v4: tailwindcss.com/blog/v4 | Docs: v4.tailwindcss.com