Skip to main content
Tailwind CSS v4 introduces a powerful new way to customize your theme using the @theme directive directly in your CSS, alongside the traditional JavaScript configuration approach.

Using @theme

The @theme directive allows you to define theme values directly in your CSS files:
app.css
These values are automatically available as utilities:

Theme Namespaces

Theme values are organized into namespaces using CSS custom properties:

Common Theme Namespaces

color
Color values for background, text, border utilities
length
Spacing scale for padding, margin, gap utilities
length
Font sizes with optional line-height sub-properties
length
Responsive breakpoints for media queries
length
Container query breakpoints

Sub-properties

Some theme values support sub-properties using the -- separator:
The text-xs utility will apply all sub-properties:

Reference Mode

Use @theme reference when you want to define theme values that should be available to the configuration but not emitted as CSS variables:
Reference theme values are useful for:
  • Plugin development where values are transformed
  • Keeping the generated CSS smaller
  • Defining values used only in JavaScript calculations

Inline vs Variable Resolution

By default, theme values are referenced as CSS variables:
With @theme reference, values are inlined:

Clearing Theme Values

Set values to initial to remove them:

JavaScript Configuration

You can also define theme values in your tailwind.config.js:
tailwind.config.ts

Theme Function

Access theme values from within configuration:

Merging Strategies

When using extend, theme values are deeply merged:

Best Practices

  1. Use @theme for CSS-based values - Colors, spacing, and sizes defined close to usage
  2. Use config for complex logic - Dynamic values, calculations, or conditional themes
  3. Prefer reference mode for large values - Keep generated CSS size down
  4. Use sub-properties - Group related values like font-size and line-height
Be cautious when clearing theme values with --*: initial - this removes ALL theme values and should only be used when you want complete control over the entire design system.