Skip to main content
The @theme directive is used to define custom CSS variables (custom properties) that make up your design system. These variables can be referenced throughout your CSS and are automatically available to Tailwind utilities.

Syntax

Basic Usage

Defining Theme Variables

Use @theme blocks to define custom properties that will be available as theme values:
These variables are automatically added to the :root selector and can be used by utilities like bg-primary, text-secondary, or referenced with the theme() function.

Multiple @theme Blocks

You can have multiple @theme blocks throughout your CSS. All theme variables are merged together:

Options

The @theme directive accepts several options that control how theme variables are processed:
boolean
Mark theme variables as reference-only. These variables won’t be included in the final CSS output but can still be used by utilities.
boolean
Inline the variable values directly instead of using CSS custom properties. This is useful for values that need to be computed at build time.
boolean
Mark theme variables as default values that can be overridden by user-defined theme values.
boolean
Mark theme variables as static values that won’t change based on context.
string
Add a prefix to theme variables and utilities. The prefix must be lowercase ASCII letters (a-z) only.

Combining Options

You can combine multiple options:

Including @keyframes

The @theme block can also contain @keyframes definitions:
The @keyframes are automatically hoisted out of the :root selector and placed at the root level of your CSS.

Theme Namespaces

Theme variables follow a namespace convention using double-dash prefixes:

Restrictions

@theme blocks must only contain custom properties (variables starting with --) or @keyframes rules. Any other CSS will result in an error.

Output

Theme variables are output in the :root, :host selector:
Variables marked as reference are excluded from the output:

Escaping Special Characters

When using special characters in variable names, they are automatically escaped: