Design

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.

This container has its own theme

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:

VariableDescription
--zen-surfacePrimary background color
--zen-surface-raisedElevated surface background
--zen-surface-sunkenRecessed surface background
--zen-surface-overlayOverlay/modal background
--zen-fgPrimary text color
--zen-fg-mutedMuted/subtle text color
--zen-borderDefault border color
--zen-border-strongEmphasized border color
--zen-interactive-bgInteractive element background
--zen-primaryPrimary/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.

50
100
200
300
400
500
600
700
800
900
950

Available palettes#

PaletteDescription
neutralPure gray with no color tint (default)
slateCool blue-gray tones
graySlight blue tint
zincSubtle blue undertones
stoneWarm 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.