Dark Mode
SPA assumption: "ThemeProvider + Context + useState"
Use the Dark / Light button in the top-right corner. The preference persists across all pages via localStorage.
How It Works
- Every color token in
@themeis alight-dark()pair, resolved bycolor-schemeon<html> - With nothing stored,
color-scheme: light darkfollowsprefers-color-scheme— no script involved, so it works with JavaScript off - Inline
<script>in<head>readslocalStoragebefore paint and pins.lightor.dark— no flash - The button sends a
--toggle-themecommand to<html>; its label switches through thedark:variant, not script
Sample Content
Surface — bg-surface + border-border
Surface Alt — bg-surface-alt
Primary — bg-primary + text-on-primary
Danger — bg-danger + text-on-danger
Success — bg-success + text-on-success
All these colors switch automatically through color-scheme. No per-component logic needed.