USWDS Futures LabIndependent research and comparison pilot

Documentation

Implementation: native dark-mode support

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

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

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

Back to experiments · Source lock