# Tailwind v4 @theme Config

> Configure custom design tokens, color palettes, and fonts directly in CSS using the Tailwind v4 @theme directive and standard CSS custom properties.

Subject: Tailwind CSS | Lesson 12 of 16 | 6 min read
Interactive lesson: https://codewithanimation.in/tailwind/tailwind-v4-theme
Previous: [Arbitrary Values](https://codewithanimation.in/tailwind/arbitrary-values.md) | Next: [Data Attributes](https://codewithanimation.in/tailwind/data-attributes.md)

## What the @theme Directive Is in Tailwind CSS v4

In Tailwind CSS v4, project configuration moves from legacy JavaScript files (`tailwind.config.js`) into standard CSS stylesheets using the `@theme` directive.

Inside a `@theme` block, developers declare custom design tokens as CSS variables (such as `--color-brand-primary: #0ea5e9;` or `--font-display: 'Inter', sans-serif;`).

Tailwind v4 automatically scans these CSS custom properties and generates corresponding utility class modifiers (`bg-brand-primary`, `font-display`, `p-18`) without requiring build-time JS configuration wrappers.

## Why CSS-First Configuration Simplifies Build Tooling and Developer Experience

Replacing `tailwind.config.js` with pure CSS `@theme` declarations yields substantial architecture benefits:

1. **Zero JS Config Overhead**: Eliminate complex Node.js build configuration imports, CJS vs ESM module mismatches, and heavy JS bundler plugins.

2. **Native CSS Interoperability**: Theme variables defined in `@theme` exist as real runtime CSS custom properties, allowing non-Tailwind CSS rules or web components to reference `var(--color-brand-primary)` directly.

3. **Instant Hot Reloading**: CSS changes update instantly in modern build tools like Vite without restarting JavaScript bundler instances.

## How to Declare Theme Tokens, Namespace Variables, and Custom Breakpoints in v4

Configure your Tailwind v4 stylesheet using these core namespace rules:

1. **Color Tokens (`--color-*`)**: Declare `--color-brand: #0ea5e9;` inside `@theme`. Tailwind generates `bg-brand`, `text-brand`, `border-brand`, and `ring-brand` utilities automatically.

2. **Spacing and Radius Tokens (`--spacing-*`, `--radius-*`)**: Declare `--spacing-18: 4.5rem;` or `--radius-xl: 1rem;` to extend spacing scales with `p-18` or `rounded-xl`.

3. **Custom Breakpoints (`--breakpoint-*`)**: Declare `--breakpoint-3xl: 120rem;` inside `@theme`. Tailwind builds corresponding `3xl:` and `max-3xl:` responsive media query prefixes.

4. **Resetting Default Themes**: To erase default Tailwind color palettes and enforce a strict design system, use wildcard reset syntax `--color-*: initial;` before defining your custom tokens.

## Common mistake: The Legacy JS Config and Syntax Confusion

Developers transitioning from Tailwind v3 often attempt to create a `tailwind.config.js` file with `theme.extend.colors` when starting new v4 projects.

In Tailwind CSS v4, JavaScript configuration files are deprecated in favor of CSS `@theme` directives.

Attempting to write JS config files in v4 projects can lead to silent configuration ignores or build errors. Always place theme customizations inside your primary CSS file.

## Tip: Inline Theme Overrides with @theme inline

Use `@theme inline` when declaring theme variables that rely on dynamic CSS values computed at runtime.

Standard `@theme` blocks generate static utility CSS rules at compile time. `@theme inline` injects CSS variable declarations directly into utility outputs, preserving dynamic browser calculation features.

## Try it: Tailwind v4 Theme Engine Demo

Explore how Tailwind v4 uses standard CSS @theme declarations and custom CSS variables to define brand tokens natively in stylesheet files.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/tailwind/tailwind-v4-theme

## Check yourself

### Question 1

Where are custom design tokens configured in Tailwind CSS v4?

- A. Directly in your main CSS stylesheet using the `@theme` directive
- B. In `tailwind.config.js` under the `module.exports` object
- C. Inside `package.json` under a new `tailwind` key

Correct answer: A

Tailwind v4 uses CSS-first configuration. Custom tokens are declared inside @theme blocks in your stylesheet.

- Why not B: Tailwind v4 replaces legacy JavaScript config files with pure CSS @theme blocks.
- Why not C: package.json is for package metadata, not CSS theme declarations.

### Question 2

Declaring `--color-brand: #0ea5e9;` inside a `@theme` block automatically generates which utility classes?

- A. bg-brand, text-brand, border-brand, and ring-brand
- B. Only bg-color-brand and text-color-brand
- C. Custom classes require manual declaration via @utility

Correct answer: A

Theme variable namespaces (--color-*) generate matching utilities (bg-brand, text-brand, border-brand) automatically.

- Why not B: Tailwind strips the namespace prefix (--color-) to produce clean utility classes like bg-brand.
- Why not C: Tailwind v4 theme engine automatically maps --color-* variables to standard color utility prefixes.

### Question 3

How do you strip all default Tailwind colors to enforce a custom color palette in v4?

- A. Add `--color-*: initial;` inside your `@theme` block
- B. Set `theme.colors = {}` in `tailwind.config.js`
- C. Delete the `@import "tailwindcss";` line from your CSS file

Correct answer: A

In Tailwind v4, wildcard reset syntax like --color-*: initial; clears default palette tokens so only your custom colors exist.

- Why not B: Tailwind v4 uses CSS wildcard reset syntax inside @theme blocks instead of JS object resets.
- Why not C: Deleting @import removes the entire Tailwind framework, not just default color tokens.

## Remember this

- Tailwind v4 replaces tailwind.config.js with pure CSS @theme blocks.
- Namespace CSS variables like --color-brand generate bg-brand and text-brand utilities automatically.
- Tokens declared in @theme exist as native CSS custom properties accessible anywhere in your CSS.
- Use --color-*: initial; to wipe default colors when building custom design systems.
