A production-ready theming guide

Design the system.
Do not invert the page.

Light and dark are complete semantic palettes. Auto is the preference resolver that chooses between them. This guide explains how to build accessible color, typography, scrolling, and browser integration around that model.

01 · Architecture

Two palettes. Three preference states.

Model what the user selected separately from what the interface currently renders. This keeps Auto responsive to operating-system changes without losing the explicit preference.

Preference Auto Stored choice
Resolved mode Light Current rendering
1

Explicit choice wins

Light or dark overrides the operating-system preference.

2

Auto follows the system

The effective theme updates as the system appearance changes.

3

Persist the preference

Store auto, light, or dark. Do not store Auto’s current result as the source of truth.

Core principle

Do not invert raw colors. Remap semantic roles such as canvas, surface, text, border, action, focus, warning, and elevation.

02 · Semantic tokens

Name colors by responsibility.

Components should consume meaning. Foundation colors can change without forcing each component to understand theme mechanics.

Canvas

Application background and largest visual field.

--color-canvas
Surface

Cards, forms, drawers, and elevated regions.

--color-surface
Action

Primary interactive emphasis with a paired foreground.

--color-action

Recommended token layers

Foundation

Raw ramps such as gray-50, blue-500, red-700.

Semantic

Intent such as text-primary, border-control, action, danger.

Component

Local bindings such as button-primary-bg and input-focus-ring.

Avoid misleading names

×
--white or --light-gray

These names become false as soon as the theme changes.

--surface-raised or --text-secondary

The role remains stable even when the value changes.

03 · Palette construction

Build tonal hierarchy in both directions.

Light mode should not default to pure white and black everywhere. Dark mode should not collapse every surface into black.

Light appearance

Raised surface

Use white or a near-white above a slightly tinted canvas.

Nested surface

Use tonal steps and explicit control boundaries.

Near-black text Tinted canvas Distinct control borders

Dark appearance

Near-black canvas

Leave room for surfaces to become visibly lighter.

Tonal elevation

Use layers, borders, and restrained shadows together.

Off-white text Reduced accent glare Multiple surface steps
Dark-mode color tuning

Highly saturated accents can appear unusually luminous on dark backgrounds. Increase lightness when needed, reduce chroma for large fills, and revalidate every foreground/background pair.

04 · Contrast

Use WCAG 2.2 as the release gate.

Contrast is a property of a rendered pair, not a color token in isolation. Validate every state against its actual adjacent background.

Content WCAG AA Preferred internal target
Normal text 4.5:1 7:1 when practical
Large text 3:1 4.5:1
Controls and meaningful graphics 3:1 3.5–4.5:1
Secondary meaningful text 4.5:1 5–7:1

Muted still matters

Metadata, dates, help text, and supporting descriptions are still meaningful text.

Focus crosses surfaces

Use a two-layer focus treatment so it remains visible against the control and the surrounding canvas.

Color is not the only signal

Pair status color with labels, icons, border treatment, shape, or placement.

05 · Color profiles

Author perceptually. Ship interoperably.

Use sRGB as the required baseline. Use OKLCH to construct palettes. Use Display P3 only as an enhancement after the fallback already works.

Three complementary roles

sRGB
P3
OKLCH

sRGB: compatibility baseline for UI, screenshots, remote desktops, and mixed displays.

Display P3: progressive enhancement for richer supported displays.

OKLCH: perceptual palette authoring, interpolation, and tonal ramp construction.

OKLCH tonal ramp

Perceptual lightness makes ramps easier to reason about than HSL. It does not replace contrast measurement.

Gamut rule

Every sRGB fallback and P3 override must independently pass contrast and preserve state meaning.

06 · Typography

Let the platform rasterize text.

Global font-smoothing overrides are non-standard and can make text appear thinner, especially bright text against dark backgrounds.

Recommended

Platform-default smoothing

Do not force antialiasing globally.

font-optical-sizing: auto

Use variable-font optical sizing where available.

Body weight 400+

Review dense dark-mode text on ordinary-density displays.

Avoid

×
Global WebKit smoothing hacks

They are platform-specific and often thin the text.

×
Global optimizeLegibility

Behavior varies and can alter ligatures and kerning.

×
Disabling mobile text adjustment

Preserve user-agent readability behavior.

07 · Scrolling

Preserve native interaction physics.

Native scrolling retains platform behavior, keyboard access, touch momentum, history restoration, find-in-page, and assistive-technology compatibility.

A

Smooth anchors only

Apply smooth scrolling to programmatic navigation, then disable it for reduced motion.

B

Offset sticky headers

Use scroll-padding-top and scroll-margin-top.

C

Stabilize layout

Use scrollbar-gutter: stable where classic scrollbars affect width.

D

Contain locally

Use overscroll-behavior on nested panes, not indiscriminately on the page.

08 · Accessibility preferences

Theme is only one adaptation dimension.

High contrast, forced colors, reduced motion, and reduced transparency are distinct user needs. Do not collapse them into dark mode.

Forced colors

Allow the browser to replace author colors. Use system color keywords for the few properties that remain controlled.

ButtonText ButtonFace Highlight CanvasText

Increased contrast

Strengthen text hierarchy, control boundaries, and focus indicators. Do not simply push every value toward black or white.

Stronger borders Less-muted text Explicit states
Transparency rule

Treat opaque, deterministic surfaces as the baseline. Blur and translucent materials should be progressive decoration, never the only support for readable text.

09 · Production baseline

A compact implementation pattern.

The CSS below gives Auto to the browser and constrains the scheme only when the user explicitly chooses light or dark.

:root {
  color-scheme: light dark;

  --canvas: light-dark(#f7f8fa, #0f1115);
  --surface: light-dark(#ffffff, #171a21);
  --text-primary: light-dark(#171a1f, #f2f4f7);
  --text-secondary: light-dark(#545b66, #b5bcc7);
  --border-control: light-dark(#7c8592, #697386);
  --action: light-dark(#155eef, #8ab4ff);
  --focus: light-dark(#005fcc, #9cc2ff);
}

:root[data-theme="light"] {
  color-scheme: only light;
}

:root[data-theme="dark"] {
  color-scheme: only dark;
}

html {
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
  scrollbar-gutter: stable;
  scroll-padding-top: var(--header-offset, 4.5rem);
  scroll-behavior: smooth;
}

body {
  background: var(--canvas);
  color: var(--text-primary);
  font-optical-sizing: auto;
  text-rendering: auto;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

@media (prefers-contrast: more) {
  :root {
    --text-secondary: var(--text-primary);
  }
}

@media (forced-colors: active) {
  :focus-visible {
    outline-color: Highlight;
  }
}
10 · Validation

Test a matrix, not a screenshot.

A theme is a state system. Validate transitions, preferences, display characteristics, scaling, loading behavior, and content variation.

Appearance and preference

Auto, light, and dark.
System theme changes while Auto is active.
Normal and increased contrast.
Forced colors and reduced motion.
Reduced transparency where supported.

Rendering and content

sRGB and Display P3 output.
100%, 200%, and 400% zoom.
Ordinary- and high-density displays.
Long, localized, empty, error, and loading states.
First paint, hydration, cached load, and offline/PWA launch.
11 · Standard

The durable operating model.

Semantic first

Theme systems should map stable roles to adaptive values.

Accessible by construction

WCAG 2.2, forced colors, and real-device tests are release gates.

Progressively enhanced

OKLCH, P3, blur, and rich materials improve capable devices without weakening the baseline.

The central lesson

The hardest failures are structural: missing semantic roles, treating Auto as a palette, using opacity as hierarchy, overriding font rasterization globally, and validating only one appearance.

12 · Provenance

Evidence is part of the document.

The explainer includes visible references, structured TechArticle metadata, and section-level data-source-refs mappings. This keeps the research lineage available to readers, parsers, and future maintainers.

Research synthesis
July 18, 2026
Evidence hierarchy
Specifications and WCAG first; platform and implementation guidance second.
Normative release gate
WCAG 2.2 and applicable CSS specifications.
Advisory guidance
MDN, Apple HIG, Material Design 3, web.dev, and browser tooling documentation.
Claim-to-source map
  • Theme architecture: src-css-color-adjust, src-mdn-color-scheme, src-mdn-light-dark.
  • Semantic roles and palette construction: src-material-roles, src-apple-dark, src-css-color-4.
  • Contrast and focus: src-wcag-quick, src-wcag-nontext, src-wcag-focus, src-wcag-use-color.
  • Typography and scrolling: src-mdn-font-smooth, src-mdn-text-rendering, src-css-overflow, src-css-overscroll.
  • Accessibility preferences: src-mdn-forced-colors, src-mdn-contrast, src-mdn-reduced-transparency.
Maintenance note

Browser-support claims should be revalidated before adopting new features as mandatory dependencies. The linked standards remain the source of truth when advisory guidance differs.