Agent Wranglers

WEB-31Optional

Define every colour once

Define every colour once as a light-dark() custom property, and switch themes with color-scheme, never with duplicate rules.

How to do it

Put tokens such as --paper: light-dark(#fff, #14172e) on :root. A theme switch sets data-theme, which sets color-scheme. The colour scheme rule covers the meta tag and the first paint.

Examples

CSS example

:root {
  color-scheme: light dark;
  --paper: light-dark(#fff, #14172e);
  --ink: light-dark(#1f2328, #e8eaf6);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
body { background: var(--paper); color: var(--ink); }

How to check

Search the stylesheet. No colour values appear outside :root, apart from black stops in masks, which set transparency rather than colour.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/website/interface/colour-as-tokens">Agent Wranglers website playbook</a>. In code you write, add a comment next to it with the same link.