Modes and themes
Dark mode (dark) and the monochrome brand theme (mono) are the default appearance on :root. Adding .light to <html> switches the color mode, and setting data-theme on <html> switches the 10% brand hue.
Selector architecture and no-flash script
| Stylesheet | Selector | Token count | Binding contract |
|---|---|---|---|
| color.css | :root | 8 scales × 12 steps + foregrounds | Dark mode (dark) primitive HSL values |
| color.css | .light | 8 scales × 12 steps + foregrounds | Light mode primitive HSL overrides with identical variable names |
| semantic.css | :root | 53 total (45 neutral/Mono + 8 feedback) | Binds neutral/Mono slots to --obsidian-* and feedback slots to --red-*, --blue-*, --orange-*, --green-* |
| semantic.css | [data-theme="verdigris"], [data-theme="brass"], [data-theme="porphyry"] | 9 brand-driven slots | Overrides --primary, --primary-hover, --primary-active, --primary-foreground, --ring, --code-keyword, --code-string, --code-number, --code-function |
| Theme | Root selector | Primitive scale | Hue | Material |
|---|---|---|---|---|
| mono | :root (no data-theme) | obsidian | 220° | Obsidian to Alabaster neutral plinth (Mono default) |
| verdigris | [data-theme="verdigris"] | verdigris | 175° | Oxidized copper brand theme |
| brass | [data-theme="brass"] | brass | 42° | Aged gold brand theme |
| porphyry | [data-theme="porphyry"] | porphyry | 320° | Imperial purple stone brand theme |
Runtime appearance contract (from apps/docs/lib/appearance.ts)
- Default mode:
darkon:root; light mode adds.lightto<html>. - Default brand theme:
mono(nodata-themeattribute); non-default themes setdata-theme="verdigris|brass|porphyry". - Storage keys:
monoplinth-modeandmonoplinth-themeinlocalStorage. - Brand-driven semantic tokens (9):
--primary, --primary-hover, --primary-active, --primary-foreground, --ring, --code-keyword, --code-string, --code-number, --code-function.
(function(){var d=document.documentElement,m="dark",t="mono";try{var sm=localStorage.getItem("monoplinth-mode"),st=localStorage.getItem("monoplinth-theme");if(sm==="light")m="light";if(st==="verdigris"||st==="brass"||st==="porphyry")t=st;}catch(e){}if(m==="light")d.classList.add("light");else d.classList.remove("light");if(t==="mono")d.removeAttribute("data-theme");else d.setAttribute("data-theme",t);})();Primitive color tokens use identical variable names across :root and .light, while semantic tokens bind once on :root and override only the brand-driven slots under [data-theme]. A blocking inline script runs in <head> before first paint to read localStorage, fall back to dark and mono, and ignore prefers-color-scheme.
Brand-driven semantic token map
| Semantic token | Tailwind class | Mono (default) | Verdigris | Brass | Porphyry |
|---|---|---|---|---|---|
| --primary | bg-primary | --obsidian-9 | --verdigris-9 | --brass-9 | --porphyry-9 |
| --primary-hover | bg-primary-hover | --obsidian-10 | --verdigris-10 | --brass-10 | --porphyry-10 |
| --primary-active | bg-primary-active | --obsidian-9 | --verdigris-9 | --brass-9 | --porphyry-9 |
| --primary-foreground | text-primary-foreground | --obsidian-foreground | --verdigris-foreground | --brass-foreground | --porphyry-foreground |
| --ring | ring-ring | --obsidian-8 | --verdigris-8 | --brass-8 | --porphyry-8 |
| --code-keyword | text-code-keyword | --obsidian-12 | --verdigris-12 | --brass-12 | --porphyry-12 |
| --code-string | text-code-string | --obsidian-11 | --verdigris-11 | --brass-11 | --porphyry-11 |
| --code-number | text-code-number | --obsidian-11 | --verdigris-11 | --brass-11 | --porphyry-11 |
| --code-function | text-code-function | --obsidian-12 | --verdigris-12 | --brass-12 | --porphyry-12 |
Only the brand-driven semantic tokens change when data-theme switches. Neutral surfaces and functional feedback tokens remain constant across every brand theme.
Usage
Apply mode and theme state on the root <html> element and consume semantic tokens in components:
// Root layout (<head> blocking script; APPEARANCE_INIT_SCRIPT is a static build-time constant)
<html lang="en" suppressHydrationWarning>
<head>
<script dangerouslySetInnerHTML={{ __html: APPEARANCE_INIT_SCRIPT }} />
</head>
<body className="min-h-screen bg-background font-sans text-foreground">
{children}
</body>
</html>/* Default: dark mode + Mono theme on :root */
/* Light mode + Verdigris theme on <html class="light" data-theme="verdigris"> */
.brand-callout {
background-color: var(--card);
color: var(--card-foreground);
border-left: var(--border-width-4) solid var(--primary);
}
.brand-callout:focus-visible {
outline: var(--focus-ring-width) solid var(--ring);
outline-offset: var(--focus-ring-offset);
}Do and don't
Accessibility
| Surface or control | Dimensions and matrix | WCAG and keyboard contract |
|---|---|---|
| Appearance matrix | 2 modes (dark, light) × 4 themes (mono, verdigris, brass, porphyry) | >= 4.5:1 text/syntax contrast and >= 3.0:1 control/focus contrast |
| ModeToggle button | Target height 40px (2.5rem) | Announces Switch to light mode or Switch to dark mode |
| ThemePicker radiogroup | Target size 32px (2rem); 2px active border | Roving tabIndex with ArrowRight, ArrowDown, ArrowLeft, ArrowUp, Home, End |
Every mode and brand theme combination passes automated contrast verification for text, syntax, controls, and focus rings. The mode toggle and theme radiogroup expose explicit accessible labels, keyboard navigation, and non-color selection borders.
Rationale
Dark mode is the architectural default of Monoplinth, so ignoring OS prefers-color-scheme guarantees a predictable first visit unless the user explicitly selects .light. Reusing identical custom property names across :root, .light, and [data-theme] keeps CSS specificity flat and eliminates duplicate dark: utility classes in component templates.