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:
Theme Value Resolution
Thetheme() function merges values from multiple sources:
- CSS theme values from
@themedeclarations (highest priority) - Plugin config from the
configparameter - Global config from configuration files
- 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
prefix()
Apply the configured prefix to a class name.string
required
The class name to prefix
Example
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
TheDEFAULT 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.