Skip to content

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

StylesheetSelectorToken countBinding contract
color.css:root8 scales × 12 steps + foregroundsDark mode (dark) primitive HSL values
color.css.light8 scales × 12 steps + foregroundsLight mode primitive HSL overrides with identical variable names
semantic.css:root53 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 slotsOverrides --primary, --primary-hover, --primary-active, --primary-foreground, --ring, --code-keyword, --code-string, --code-number, --code-function
ThemeRoot selectorPrimitive scaleHueMaterial
mono:root (no data-theme)obsidian220°Obsidian to Alabaster neutral plinth (Mono default)
verdigris[data-theme="verdigris"]verdigris175°Oxidized copper brand theme
brass[data-theme="brass"]brass42°Aged gold brand theme
porphyry[data-theme="porphyry"]porphyry320°Imperial purple stone brand theme

Runtime appearance contract (from apps/docs/lib/appearance.ts)

  • Default mode: dark on :root; light mode adds .light to <html>.
  • Default brand theme: mono (no data-theme attribute); non-default themes set data-theme="verdigris|brass|porphyry".
  • Storage keys: monoplinth-mode and monoplinth-theme in localStorage.
  • 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 tokenTailwind classMono (default)VerdigrisBrassPorphyry
--primarybg-primary--obsidian-9--verdigris-9--brass-9--porphyry-9
--primary-hoverbg-primary-hover--obsidian-10--verdigris-10--brass-10--porphyry-10
--primary-activebg-primary-active--obsidian-9--verdigris-9--brass-9--porphyry-9
--primary-foregroundtext-primary-foreground--obsidian-foreground--verdigris-foreground--brass-foreground--porphyry-foreground
--ringring-ring--obsidian-8--verdigris-8--brass-8--porphyry-8
--code-keywordtext-code-keyword--obsidian-12--verdigris-12--brass-12--porphyry-12
--code-stringtext-code-string--obsidian-11--verdigris-11--brass-11--porphyry-11
--code-numbertext-code-number--obsidian-11--verdigris-11--brass-11--porphyry-11
--code-functiontext-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

Do: Resolve appearance in <head> and use semantic classes
Run APPEARANCE_INIT_SCRIPT synchronously in <head> and style components with bg-background, text-foreground, bg-primary, and ring-ring so mode and theme switches require zero component re-renders.
Don't: Follow OS prefers-color-scheme or branch in JSX
Do not query window.matchMedia('(prefers-color-scheme: light)') or conditionally swap Tailwind classes in React state for dark and light modes.

Accessibility

Surface or controlDimensions and matrixWCAG and keyboard contract
Appearance matrix2 modes (dark, light) × 4 themes (mono, verdigris, brass, porphyry)>= 4.5:1 text/syntax contrast and >= 3.0:1 control/focus contrast
ModeToggle buttonTarget height 40px (2.5rem)Announces Switch to light mode or Switch to dark mode
ThemePicker radiogroupTarget size 32px (2rem); 2px active borderRoving 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.