Tailwind CSS v4: Theme and Configuration
Understand CSS-first theme customization, custom design tokens, source discovery, and how v3 differs from v4.
CSS-first theme customization
Tailwind CSS v4 emphasizes CSS-first configuration for many common theme customizations. The @theme directive lets you define design tokens that participate in Tailwind's utility and variant system. This is different from many v3 tutorials that put most theme customization in tailwind.config.js.
Use the current official documentation for exact syntax and supported namespaces. Theme tokens should express stable design decisions such as brand colors, font families, spacing, and breakpoints—not every individual component's one-off state.
@import "tailwindcss";
@theme {
--color-brand-500: #0ea5e9;
--color-brand-700: #0369a1;
--font-display: "Inter", ui-sans-serif, system-ui, sans-serif;
--radius-panel: 1.25rem;
}- Tailwind v4 supports CSS-first theme customization.
- Define tokens for repeated design decisions.
- Confirm token syntax and generated utility names for the installed version.
Tailwind v3 vs. v4 and migration awareness
Tailwind v3 and v4 differ in setup, configuration conventions, CSS entry points, browser requirements, and some migration details. A code sample containing utility classes may look familiar across versions, while installation or theme instructions may not be portable.
When upgrading, read the official upgrade guide, confirm framework and browser support, review custom plugins and configuration, and compare generated CSS. Avoid making several unrelated changes during the migration; isolate setup changes from visual refactoring so regressions are easier to locate.
Use the matching integrationReview tokens and configCheck file discoveryTest key screensA v3 configuration example may not be the right starting point for a v4 project. Identify the installed version before changing setup.
Source paths and third-party components
Tailwind must discover class candidates in the source files where they appear. Monorepos, shared component packages, generated files, and third-party UI libraries can complicate source detection. If a class is missing only in production or only in a package, inspect the source configuration and build pipeline before adding arbitrary CSS overrides.
For a shared component package, document which source files the consuming app must scan or use the supported source registration mechanism for the installed version. Prefer a reproducible build fix over manually copying generated CSS.
- Inspect source discovery when utilities are missing from production.
- Monorepos and shared packages need deliberate source configuration.
- Use the official migration guide for major-version changes.