Dark mode is no longer an optional theme—it is a core part of brand perception and accessibility. The key is to lead with semantics: define tokens, respect user preferences, and avoid one-off overrides when something feels misaligned.
- Start with design tokens mapped to CSS custom properties
- Honor
prefers-color-schemefor first render - Use a toggle that persists intent with localStorage
- Audit contrast for both themes before shipping
:root {
color-scheme: light dark;
--surface: #ffffff;
--surface-inset: #f4f6fb;
--text: #1f2933;
--accent: #274690;
}
@media (prefers-color-scheme: dark) {
:root {
--surface: #101623;
--surface-inset: #151d2d;
--text: #f5f7fa;
--accent: #5c8bff;
}
}
body.theme--dark {
--surface: #101623;
--surface-inset: #151d2d;
--text: #f5f7fa;
--accent: #5c8bff;
}
By layering the system preference with a user-controlled toggle, you offer a flawless experience whether someone opens the page at noon or midnight.