Skip to main content
The theme() CSS function allows you to reference values from your Tailwind theme (defined via @theme) directly in your CSS.

Syntax

Basic Usage

Referencing Theme Variables

Use theme() to reference CSS custom properties defined in @theme:
Output:

Direct Value Resolution

By default, theme() returns a var() reference. The actual value is resolved at runtime by the browser.

Inline Resolution

Use the inline modifier to resolve theme values at build time:
Output:
The theme variable itself is not included in the output when using inline.

When to Use Inline

Fallback Values

Provide a fallback value if the theme variable doesn’t exist:
If --color-accent is not defined:

Multiple Fallbacks

You can chain multiple fallbacks:

Fallback with var()

When the theme value is a var() reference, the fallback is injected into it:
Output:
The initial placeholder in the theme is replaced with the provided fallback.

Special Theme Functions

Tailwind provides additional CSS functions for working with theme values:

—theme()

An alternative syntax that’s identical to theme():

—spacing()

Multiply the spacing scale by a value:
The --spacing theme variable must be defined for --spacing() to work.

—alpha()

Apply opacity to a color:
With theme variables:

Using in At-Rules

Theme functions are automatically inlined when used in at-rule conditions:

Media Queries

Supports Queries

Container Queries

CSS custom properties cannot be used in at-rule conditions, so theme() automatically inlines values in these contexts.

Legacy dot-notation Syntax

The legacy theme() syntax using dot-notation is still supported:
The legacy syntax:
  • Requires quotes around the path
  • Uses dots to separate path segments
  • Maps to the same theme variables
The modern --variable syntax is recommended for new projects.

Unquoting Quoted Values

The legacy syntax automatically unquotes quoted theme values:
From the source code (css-functions.ts:206-224):

Error Handling

Missing Theme Variable

If a theme variable doesn’t exist and no fallback is provided:
Error:

Provide Fallback to Avoid Errors

Invalid Variable Name

Modern syntax requires CSS custom property names (starting with --):

Function Processing

From the source code (css-functions.ts:68-127), the theme() function:
  1. Validates the variable name starts with --
  2. Checks for the inline modifier
  3. Auto-inlines if used in an at-rule
  4. Resolves the value from the design system
  5. Handles fallback values
  6. Injects fallbacks into nested var() or theme() calls

--spacing()

Multiply the spacing scale

--alpha()

Apply opacity to colors