API reference
defineTheme
API reference for the `defineTheme` method
The defineTheme
function allows you to define semantic design tokens that respond to themes such as "light"
or "dark"
, and can optionally fall back to a default
value.
These tokens are automatically turned into CSS custom properties
(i.e. --variables
) and placed into:
:root
for defaults:root[data-theme="themeName"]
for per-theme overrides- or
@media
,@container
selectors if used viacss.media
orcss.container
🎯 Basic usage
Define tokens with theme-aware values.
- If
default
is defined, it's written to:root
- Each theme name becomes
:root[data-theme="name"]
- Keys are converted to kebab-case
🎨 Consuming themes in components
Use theme tokens in your components just like any other CSS variable.
📦 Output summary
Plumeria will generate:
var(--token-name)
references in CSS- Theme-specific overrides in data attributes
- (Optional) integration with
css.media
orcss.container
This allows for light/dark mode switching, theming via props, and custom container queries.
💡 Tips
- Use together with defineVars() to separate tokens from themes
- Themes are resolved at runtime via the data-theme attribute
- You can dynamically switch themes by toggling document.documentElement.dataset.theme = 'dark'
📚 Related APIs
- defineVars() — define base variables to reuse in themes
- create() — style components using theme tokens