USWDS Futures LabIndependent research and comparison pilot

Cross-component capability · Prototype available

Native dark-mode support

A semantic token layer that lets USWDS components respond to system appearance and an explicit user override without replacing upstream components.

Review status: accepted. Reviewer: Mike Gifford on 2026-11-20. Accepted as a lab experiment; upstream not authorized. Evidence: 9 of 9 routes collected. Human review: accepted.

Working demonstration

Evaluate this experiment Open the registered demonstration

The evaluation workspace does not mirror keyboard input. Open either implementation independently for keyboard and assistive-technology testing.

Proposal and context

Status: Prototype. Automated evidence may exist; human review is pending.

Category: Cross-component capability
Baseline: USWDS v3.14.0 (npm distribution)
Proposal: A semantic token layer over the official component assets.

Why this exists

USWDS issue #5069 asked for personalization, including light/dark preferences, and was closed as not planned amid limited maintainer capacity. Issue #4644 explored CSS custom properties and moved into a broader discussion. Issue #4577 is a component-specific example: an accordion icon treatment that must be evaluated on the whole component, not a single screenshot. Issue #4407 is a reminder that dark mode is not the same as a contrast preference.

The lab does not claim these issues were rejected on technical grounds. It tests one small, reversible approach.

What stable USWDS provides

USWDS 3.14.0 ships a mature light theme and compile-time Sass settings. It does not ship a runtime dark theme, an explicit user override, or a documented set of semantic runtime tokens that cover the components in this lab. Many teams add their own overrides; those overrides are rarely tested across states, forced colors, and no-JavaScript conditions.

What is proposed

site/assets/experiment.css adds a small semantic token layer (--fx-*) and selector overrides. It:

  • follows prefers-color-scheme: dark when no explicit choice is stored;
  • accepts an explicit data-mode="light" or data-mode="dark" override;
  • themes the accordion, alert, banner, and form fixtures;
  • keeps the official USWDS CSS and JavaScript in place;
  • does not load any third-party dark-mode package.

The explicit preference is exposed through the user preferences panel, not through a second control inside every component.

What changed in the lab

Only the experimental pane changes. The baseline pane keeps the official assets and does not load experiment.css. The fixture markup is shared by both panes. The baseline still includes a small fixture stylesheet for page framing, which is labelled in the evidence.

Evidence status

Automated evidence is collected by npm run evidence and published on the lab evidence page after a build. A successful collection is not a review. The decision is recorded in the central decision log: accepted as a lab experiment on 2026-11-20, with the stated limitations.

Known limitations

  • Four components are covered, not all of USWDS. Header, footer, navigation, tables, cards, and complex form controls are not yet themed.
  • The upstream alert icon is not recolored; the alert heading carries the meaning.
  • The experiment relies on !important overrides for some states. That is a maintenance cost and a sign that the semantic token layer does not yet exist upstream.
  • No real high-contrast OS session, screen reader, or government-service integration has been tested.
  • Dark mode is not a claim of energy savings.

Implementation guidance

Approach

The experiment keeps the official USWDS CSS and JS. It adds one stylesheet with semantic custom properties and a small set of component overrides.

:root {
  --fx-canvas: #fff;
  --fx-surface: #f1f3f5;
  --fx-text: #1b1b1b;
  --fx-border: #77808b;
  --fx-link: #005ea2;
  --fx-focus: #005ea2; /* 6.2:1 on the light surface */
}
:root[data-mode="dark"] {
  --fx-canvas: #151c28;
  --fx-surface: #273448;
  --fx-text: #f5f6f9;
  --fx-border: #aab7c8;
  --fx-link: #86c9fa;
  --fx-focus: #ffbe2e; /* 10.7:1 on the dark canvas */
}
@media (prefers-color-scheme: dark) {
  :root[data-mode="system"] { /* the same dark values */ }
}

data-mode is set by site/assets/fixture.js from the ?theme= query parameter or the saved preference. The default is system, which is resolved entirely by the media query; no JavaScript is required for the system preference.

Component rules

  • Accordion and banner buttons use --fx-surface for the control and --fx-canvas for the panel.
  • Alerts use semantic warning/error/info backgrounds and keep a heading; color is not the only cue.
  • The form input uses --fx-canvas and --fx-text.
  • Radio and checkbox containers need explicit treatment. Upstream sets .usa-radio{background:#fff} and .usa-checkbox{background:#fff}. The lab sets both the container and the label color in dark mode; otherwise the page shows a white slab or dark-on-dark text.
  • The banner's small “About this banner” text is visually hidden from assistive technology upstream but is still visible text on narrow screens. It uses --fx-link in dark mode.
  • Focus is a 3px outline with a 3px offset. The light token is #005ea2 (6.2:1 on the light surface and 4.7:1 on the page); the dark token is #ffbe2e (10.7:1 on the dark canvas). The outline sits on the page surface because of the offset, so the contrast is measured against the surface behind it.

RTL and logical properties

The alert uses border-inline-start and removes the physical left border, so the accent moves to the start side in RTL. Accordion and banner buttons use text-align:start. This is a small demonstration, not a complete multilingual layout.

Forced colors and reduced motion

@media(forced-colors: active) restores a system Highlight focus outline and ButtonText borders. The theme does not set forced-color-adjust:none on components. @media(prefers-reduced-motion: reduce) removes non-essential transitions. Dark mode is not a substitute for either preference.

How to use it

  • fixture/accordion-experiment.html?theme=dark
  • fixture/accordion-experiment.html?theme=system
  • compare.html?component=accordion&theme=dark
  • The preferences panel stores an explicit override in localStorage; reset removes it.

What upstream would need

A real contribution would need to map Sass tokens to runtime custom properties, document the supported component matrix, and resolve hard-coded colors in upstream CSS. This experiment does not claim that a short --fx-* list is complete USWDS support.

Known gaps

  • No high-contrast OS session or real screen-reader session.
  • No header/footer/navigation/table/card coverage.
  • Some states use !important because upstream selectors have higher specificity.
  • No measured performance claim; the extra CSS is small, but it has not been benchmarked.

Evidence and limitations

9 of 9 routes collected. Human review: accepted.

Open the evidence index for transcripts, screenshots, axe observations, and coverage gaps.

Automated evidence is not human approval. The decision record remains authoritative.

Related USWDS history

Experiment files

AI assistance disclosed by the contributor: issue research, initial implementation, test scaffolding, documentation drafting. A human reviewer must assess the evidence before any upstream proposal.