Skip to main content

theme()

Access theme configuration values from both CSS @theme declarations and JavaScript config.
string
required
Dot-notation path to the theme value (e.g., 'colors.blue.500', 'spacing.4')
any
Fallback value if the path doesn’t exist

Basic Usage

With Default Value

Nested Properties

Using in matchUtilities

Extending Theme Colors

Opacity Modifiers

Theme colors support opacity modifiers using the / syntax:
Compiles to:

Theme Value Resolution

The theme() function merges values from multiple sources:
  1. CSS theme values from @theme declarations (highest priority)
  2. Plugin config from the config parameter
  3. Global config from configuration files
  4. Default theme values

Referencing Other Theme Values

Theme functions can reference other theme keys:

Common Theme Paths

config()

Access raw configuration values outside of the theme.
string
Dot-notation path to the config value (e.g., 'prefix', 'important'). Omit to get the entire config.
any
Fallback value if the path doesn’t exist

Get Entire Config

Access Specific Values

Custom Config Options

Usage:

prefix()

Apply the configured prefix to a class name.
string
required
The class name to prefix

Example

With prefix: 'tw-' configuration:
In v4, the prefix() function is primarily for compatibility. The design system automatically handles prefixing for utilities registered through the Plugin API.

Bare Value Support

Many theme keys support bare values (numeric values without explicit units):

DEFAULT Key

The DEFAULT key in theme objects maps to utilities without a suffix:

CSS Variable Access

Access CSS custom properties directly:
The theme() function intelligently merges CSS @theme values with JavaScript config, prioritizing CSS values for better performance and CSS-first workflows in v4.