Themes
Zen supports light and dark themes out of the box. Themes are applied using CSS custom properties that automatically adjust colors, backgrounds, and borders based on the active theme.
Setup#
Wrap your application with ZenProvider to enable theme support.
Theme options#
You can configure the initial theme using the theme or colorScheme props.
ThemeButton#
Use the ThemeButton component to let users toggle between light and dark themes.
Local themes#
You can scope theme changes to a specific container using the target prop. This allows parts of your UI to have a different theme than the rest of the page.
useTheme hook#
Access and control the current theme programmatically with the useTheme hook.
CSS variables#
Themes work by redefining CSS custom properties. The following variables change based on the active theme:
| Variable | Description |
|---|---|
| --zen-surface | Primary background color |
| --zen-surface-raised | Elevated surface background |
| --zen-surface-sunken | Recessed surface background |
| --zen-surface-overlay | Overlay/modal background |
| --zen-fg | Primary text color |
| --zen-fg-muted | Muted/subtle text color |
| --zen-border | Default border color |
| --zen-border-strong | Emphasized border color |
| --zen-interactive-bg | Interactive element background |
| --zen-primary | Primary/accent color |
Theme persistence#
Theme preference is automatically saved to localStorage under the key theme. When the page loads, the stored preference is restored.
Dark mode classes#
Zen applies both data-theme="dark" attribute and the .dark class to the root element for maximum compatibility with Tailwind CSS and other frameworks.
Color palettes#
Zen supports multiple gray-scale palettes inspired by Tailwind CSS. Each palette has a different color temperature and character.
Available palettes#
| Palette | Description |
|---|---|
| neutral | Pure gray with no color tint (default) |
| slate | Cool blue-gray tones |
| gray | Slight blue tint |
| zinc | Subtle blue undertones |
| stone | Warm tan/brown tones |
Setting the palette#
You can set the palette via ZenProvider or programmatically with useTheme.
Palette persistence#
Palette preference is automatically saved to localStorage under the key zen.palette. The data-palette attribute is applied to the root element.
