Dark mode
Apply Zenos' semantic theme in class-based or data-attribute applications.
Zenos dark mode is a semantic theme, not an inverted color filter. Surfaces, text, borders, elevation, feedback colors, and interaction states receive deliberate values for each mode.
Zenos recognizes either a .dark ancestor or data-theme="dark" on the document root.
12 assets require review.
12 assets require review.
Apply a theme
Section titled “Apply a theme”Keep the class and data attribute synchronized when the application supports both conventions:
document.documentElement.classList.toggle("dark", theme === "dark");document.documentElement.dataset.theme = theme;Components respond through semantic variables. Application code should not branch between light and dark hex values when one semantic role can describe the intent.
Global theme hook
Section titled “Global theme hook”The public useTheme hook reads the preference in this order:
- A valid persisted value
- The document’s
data-themevalue - The document’s
.darkclass - The operating-system preference
- The configured fallback
import { useTheme } from "@zentara-co/zenos-ui"; function ThemeControl() { const { theme, setTheme, toggleTheme } = useTheme(); return ( <Button onClick={toggleTheme} aria-label={`Use ${theme === "dark" ? "light" : "dark"} theme`}> {theme === "dark" ? "Light" : "Dark"} </Button> );}By default, the hook stores the value under theme, updates both root selectors, reacts to changes from another browser tab, and follows system changes until a preference is stored.
See the useTheme hook reference for every option, return value, synchronization rule, and SSR consideration.
Use a product-specific storageKey when multiple applications share a domain. Set it to null when persistence is managed elsewhere.
Theme toggle button
Section titled “Theme toggle button”ThemeToggleButton composes the global hook with an accessible button and an optional View Transition reveal.
<ThemeToggleButton icon={({ theme }) => (theme === "dark" ? <MoonIcon /> : <SunIcon />)} shape="circle"/>The button sets aria-pressed, supplies a default accessible name, forwards native button props, and skips the visual transition when the user prefers reduced motion or the browser does not support View Transitions.
Use the controlled theme and onThemeChange props when another state manager owns the preference.
Prevent a theme flash
Section titled “Prevent a theme flash”Apply a stored or system theme before the first paint when server-rendering or generating a static application. Place a small inline script in the document head before styles render:
<script is:inline> const stored = localStorage.getItem("theme"); const theme = stored === "light" || stored === "dark" ? stored : matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"; document.documentElement.dataset.theme = theme; document.documentElement.classList.toggle("dark", theme === "dark");</script>If storage access can be restricted, wrap it in try/catch and fall back to the system preference.
Customize both modes
Section titled “Customize both modes”Override roles rather than component selectors:
:root { --background-default: #ffffff; --text-default: #0f0f0f; --border-default: rgb(15 15 15 / 8%);} [data-theme="dark"] { --background-default: #0f0f0f; --text-default: #f8f9fa; --border-default: rgb(255 255 255 / 12%);}Check every interactive state in both modes: default, hover, pressed, selected, focused, disabled, invalid, and loading.
Surfaces and elevation
Section titled “Surfaces and elevation”Dark interfaces need visible surface hierarchy without bright borders around every region. Use semantic elevation surfaces and shadows so cards, raised controls, and overlays remain distinct from the canvas.
Avoid pure black for every layer. Small differences between canvas, card, raised, and overlay surfaces make dense interfaces easier to scan.
Images, charts, and code
Section titled “Images, charts, and code”- Verify logos and illustrations remain legible on both surfaces.
- Use semantic chart tokens rather than light-only series colors.
- Keep grid lines and axes quieter than the plotted data.
- Test code blocks, selection, syntax colors, and scrollbars independently.
- Do not reduce image opacity globally as a substitute for a dark-mode treatment.
Testing
Section titled “Testing”Test the complete interface in light, dark, and system-selected modes. Verify persistence across reloads, synchronization across tabs, initial render without a flash, forced-colors behavior, reduced motion, and readable focus indicators.
The documentation theme control follows the same browser preference and lets Starlight manage persistence, avoiding a second competing theme state.