Tailwind CSS v4 introduces a powerful new way to customize your theme using theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/tailwindlabs/tailwindcss/llms.txt
Use this file to discover all available pages before exploring further.
@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
Theme Namespaces
Theme values are organized into namespaces using CSS custom properties:Common Theme Namespaces
Color values for background, text, border utilities
Spacing scale for padding, margin, gap utilities
Font sizes with optional line-height sub-properties
Responsive breakpoints for media queries
Container query breakpoints
Sub-properties
Some theme values support sub-properties using the-- separator:
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:@theme reference, values are inlined:
Clearing Theme Values
Set values toinitial to remove them:
JavaScript Configuration
You can also define theme values in yourtailwind.config.js:
tailwind.config.ts
Theme Function
Access theme values from within configuration:Merging Strategies
When usingextend, theme values are deeply merged:
Best Practices
- Use @theme for CSS-based values - Colors, spacing, and sizes defined close to usage
- Use config for complex logic - Dynamic values, calculations, or conditional themes
- Prefer reference mode for large values - Keep generated CSS size down
- Use sub-properties - Group related values like font-size and line-height