This is the top of the landing page of Stashling, the course’s sample site, as Module 5 left it, at 1280 pixels wide.

Figure 1: the page’s one primary action. Its white label is hard to read on the brand blue, #3ea6ff.
A reader would say the white words on the button are hard to read. The button also looks faded next to the black title, although it’s the one action the page wants.
This module measures that problem the way WCAG 2.2 does, then builds a palette for the whole site: grays, one blue and one red, each named for its job. It ends with a dark theme that has its own lightness steps and follows the reader’s system setting.
After this module, you can:
- measure the contrast between two colors the way WCAG 2.2 does, say which minimum applies to a piece of text, and say where a newer measure disagrees
- build a set of lightness steps for one hue and pick the step that holds white text
- name colors by their job, so one change of value reaches every page, and make hover shades in CSS
- check that a page still works for readers who see fewer hues
- add a dark theme with its own colors, and a fallback for browsers that can’t show it
To follow along, start from the module-05 folder of the course repository, github.com/vespaiach/web-design-course, and open index.html and settings.html in a browser.
A blue button with white words
Here are the button rules from base.css:
/* excerpt */
.button {
display: inline-block;
background: #3ea6ff;
color: #fff;
border: none;
padding: 10px 20px;
font-size: var(--step-0);
cursor: pointer;
}
.button:hover {
background: #0000ff;
text-decoration: none;
}
.button-danger {
background: #ff0000;
}
The label is 18 px at normal weight on a 1280-pixel screen, so WCAG 2.2 asks for a contrast of at least 4.5:1.
Pause and predict: does the white label reach 4.5:1 on this blue? Write down a guess for its number before you measure it.
Open index.html and paste this into the DevTools console:
// for colors that the browser reports as rgb(r, g, b)
const lum = (rgb) => {
const [r, g, b] = rgb.match(/\d+/g).map((n) => {
const c = n / 255;
return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
});
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
};
const ratio = (a, b) => {
const [hi, lo] = [lum(a), lum(b)].sort((x, y) => y - x);
return (hi + 0.05) / (lo + 0.05);
};
const s = getComputedStyle(document.querySelector(".button"));
console.log(s.color, "on", s.backgroundColor, ratio(s.color, s.backgroundColor).toFixed(2));
console.log(s.fontSize, s.fontWeight);
Answer
In one run in Chrome 157 on macOS, it printed this:
rgb(255, 255, 255) on rgb(62, 166, 255) 2.59
17.999px 400
The label reaches 2.59:1, far under 4.5:1. It even fails 3:1, the lowest minimum that WCAG sets for any text. On the settings page, the red “Delete repository” button has white text at 4.00:1, also under 4.5:1. And on hover, every button turns pure blue, #0000ff, the red one included.
lum is Module 5’s luminance formula, rewritten for rgb() strings. The last line of ratio is the WCAG 2.2 formula, which the next section explains.
How WCAG 2.2 turns two colors into one number
A contrast ratio compares the luminance of two colors as (L1 + 0.05) / (L2 + 0.05), where L1 belongs to the lighter color. It runs from 1:1 for two equal colors to 21:1 for black on white (WCAG 2.2, a W3C Recommendation in its 12 December 2024 edition).
The 0.05 on both sides stands for flare, the light that a room reflects off the screen. Understanding 1.4.3 says the value is based on typical viewing flare. When both colors are dark, both luminances are small, so the 0.05 decides most of the result and the ratio stays low. The dark theme section comes back to this.
Which minimum applies to which text
Success criterion 1.4.3, Contrast (Minimum), sets the level AA minimums:
- Text: at least 4.5:1.
- Large-scale text: at least 3:1.
- No minimum, among others: text in a disabled control, pure decoration, text nobody can see, and logos.
Large-scale text is text of at least 18 point, or at least 14 point in bold. One point is 4/3 of a CSS pixel, so that means 24 px, or 18.67 px in bold. WCAG adds that this is about 1.2 and 1.5 em in many body fonts, and that you should check it for your own font.
Stashling’s label is 18 px at weight 400, so it needs 4.5:1. A separate criterion, 1.4.11 Non-text Contrast, asks for 3:1 for the parts of a control that show what it is and what state it’s in (Understanding 1.4.11). A button with a text label needs no visible edge, but its focus indicator does; Module 9 handles focus.
The numbers come from vision research, as Understanding 1.4.3 explains. 3:1 is the minimum that ISO 9241-3 and ANSI/HFES 100-1988 recommend for standard vision. Vision of 20/40, which the document calls typical at about age 80, comes with a loss of contrast sensitivity of about 1.5, so 3 × 1.5 gives 4.5. Level AAA’s 7:1 matches about 20/80 vision.
Three details change results in practice:
- No rounding. 4.499:1 fails 4.5:1.
#767676on white is 4.54:1 and passes;#777777is 4.48:1 and fails (color-calc/calc.mjs, section 11). - Hue doesn’t count. The formula uses luminance only. Understanding 1.4.3 names one exception, red on a dark background for readers with one kind of red-green deficiency; the section on color vision returns to it.
- Set both colors. A text color without a background color, or the reverse, is failure F24 in WCAG, because the reader’s default colors are unknown.
base.csssets both onbody.
The formula gives the same number when you swap text and background. CSS Color 5 advises browsers not to use it to choose between light and dark text, because it has several known issues (CSS Color 5, §8). A later section shows one.
Two fixes for the button, one change each
You can keep the blue and darken the text, or keep the white text and darken the blue. To darken the blue, use Module 5’s method: lower the OKLCH lightness and keep the chroma and the hue.
The brand blue is oklch(0.707 0.161 248.4). As its lightness falls, white text reaches 3:1 at 0.66 (#2b97ef, 3.10:1) and 4.5:1 at 0.56 (#0078cd, 4.60:1). At 0.56 the color is outside sRGB, so the script maps it in (calc.mjs, section 3). Figure 2 puts both fixes beside the original.

Figure 2: the button (left), with dark text (middle) and with a darker fill (right). Each fix changes one color.
The dark text, #222222, gives 6.14:1 and keeps the brand’s exact blue. The cost is a light button with dark text, which a second measure, explained later in this module, rates weak for small text. The darker fill gives 4.60:1, barely above the minimum, and the blue is no longer the brand’s exact blue.
This module uses the darker fill in the light theme. The dark theme uses the other idea: a light fill with dark text.
Rule: Measure every text color against the color behind it. Use 4.5:1 unless the text is 24 px, or 18.67 px in bold, and never round up.
A palette: grays, one accent and a red
Before this module, the CSS files hold seven raw colors, each picked when its rule was written, plus Module 5’s three status colors. A palette is the set of colors a site uses, each with a job.
A neutral is a color with little or no chroma: a gray, a near-white or a near-black. An accent is the one color with chroma that marks what is interactive or important.
A common pattern is neutrals for nearly everything and one accent. Material Design 2’s dark theme guidance, for example, puts limited color accents on large dark surfaces. It’s a convention, and we found no study that tests it.
But we can give a reason from Modules 1 and 5: if only one kind of element has chroma, chroma becomes a signal. On Stashling, that signal is the buttons, so the eye finds the primary action first.
Colors with fixed meanings form a second family, not more accents. Stashling needs a red for the danger button and keeps Module 5’s three status colors. So its palette is a gray scale, a blue scale for the accent, a red scale for danger, and the status colors.
Some palettes tint their grays with a trace of the accent’s hue, such as #0b1220, which is oklch(0.183 0.031 263.4). We found no source that tests the practice. The lab keeps pure grays, so their numbers stay easy to read.
A tonal scale: one hue from light to dark
A tonal scale is one hue in a series of steps from light to dark, so each step can do one job: a background, a border, a fill or text. This course numbers the steps from 50 to 950; Material and Radix number theirs differently.
The course’s script color-calc/m6/palette.mjs builds three scales with one rule: every step has one OKLCH lightness, the same for every hue.
// excerpt from color-calc/m6/palette.mjs
const hex = c => new Color(c).toGamut({ space: "srgb", method: "css" }).to("srgb").toString({ format: "hex", collapse: false });
const L = { 50: 0.97, 100: 0.93, 200: 0.87, 300: 0.80, 400: 0.72, 500: 0.64,
600: 0.56, 700: 0.48, 800: 0.40, 900: 0.32, 950: 0.25 };
const [, brandC, brandH] = new Color("#3ea6ff").to("oklch").coords;
const scale = (C, H) => Object.fromEntries(Object.entries(L).map(([k, l]) => [k, hex(new Color("oklch", [l, C, H]))]));
const S = { blue: scale(brandC, brandH), red: scale(0.2, 27), neutral: { 0: "#ffffff", ...scale(0, 0) } };
The blue takes the brand’s hue, 248.4, and asks for its chroma, 0.161. The red takes hue 27, near sRGB red’s 29.2, and asks for 0.2. The grays have chroma 0, plus white as step 0.
Then hex maps each color into sRGB the way CSS Color 4 describes: it lowers chroma and keeps lightness and hue. Figure 3 shows the result.
Figure 3: three tonal scales with one OKLCH lightness per step. White text first reaches 4.5:1 at step 600 in all three.
Three things in Figure 3 follow from Module 5:
- Chroma falls at both ends. Step 50 of the blue asks for 0.161 and gets 0.024, because sRGB holds little chroma near white.
- The hue drifts. The blue’s hue is 219.7 at step 50 and 257.4 at step 950. Mapping allows a small change per color, and the changes add up near the edge of sRGB. If the drift shows, ask for less chroma at the ends.
- One lightness gives three ratios. At step 600, white text is 4.60:1 on blue, 5.15:1 on red and 4.67:1 on gray. OKLCH lightness and WCAG luminance are different models, so the step number predicts the ratio only roughly.
tokens.css stores the mapped hex, not the oklch() value, because Chrome 157 clips colors outside sRGB instead of mapping them (Module 5). In one test, it drew oklch(0.8 0.161 248.4) as #5fc4ff, the clipped color. Mapping gives #77c4ff, the blue-300 in Figure 3 (palette-output.txt, section K).
Equal lightness steps do not give equal contrast
Pause and predict: four pairs of grays, each 0.2 apart in OKLCH lightness. Do they all have about the same contrast ratio?
Figure 4 draws the four pairs with their ratios.
Figure 4: four gray pairs, each 0.2 apart in OKLCH lightness. Near black, the same gap gives the least contrast.
The pair near black gets 1.52:1, against 2.12:1 in the middle. That’s the effect of the 0.05 for flare: when both luminances are tiny, the 0.05 decides most of the ratio. So you can’t mirror the step numbers that work in a light theme into a dark one, and the dark theme section measures its own pairs.
Other ways to build a scale
- By hand. A designer picks every step by eye. This suits a brand whose exact colors must not move.
- By target contrast. You name the ratio each step needs and a tool finds the color. Leonardo works this way (see “Online tools for this step”). This suits a design where contrast rules come first.
- By Material’s tones. Material Design 3 builds tonal palettes from 0 to 100 on CIELAB lightness, which it calls tone (How the system works). It says tones 50 and 98 give 3:1, and 30 and 98 give 7:1. Over all gray pairs, a gap of 50 tones gives at least 4.48:1, slightly under 4.5 (
palette-output.txt, section L). - By HSL lightness. Module 5 showed that HSL lightness isn’t what the eye sees, so its steps are uneven.
Radix Colors gives each of its 12 steps a job (Understanding the scale). Steps 1 and 2 are app backgrounds, 3 to 5 component backgrounds, and 6 to 8 borders. Steps 9 and 10 are solid fills, and 11 and 12 are text.
Every step is a token to maintain and to check in two themes. So tokens.css keeps only the 11 steps the site uses, out of the 34 in Figure 3.
Rule: Build a scale by lightness, then measure every pair you use. The step number alone doesn’t give you the ratio.
Semantic color tokens name the job, not the color
Module 2 named spaces by their job: --space-inside points to --space-4. Colors get the same two layers. Scale tokens hold values, such as --blue-600. Semantic color tokens name jobs, such as --color-accent, and point to a step.
CSS rules for the page use only the semantic ones. Figure 5 shows the chain for five of them.
CSS rule semantic token scale token
body { background } -> --color-surface -> --neutral-0
body { color } -> --color-text -> --neutral-950
.button { background } -> --color-accent -> --blue-600
.button { color } -> --color-on-accent -> --neutral-0
.button-danger { ... } -> --color-danger -> --red-600
Figure 5: two layers of names. A theme changes only the right-hand arrows.
Each fill gets a partner token for the text on it: --color-accent and --color-on-accent. Material 3 does the same with its color roles, such as “primary” and “on primary”, and has 26 roles in each theme. So the pair is what you check: one ratio per pair, once per theme.
These are the twelve semantic tokens of the lab, with their light values and the pairs from palette-output.txt, section C:
| Token | Job | Light value | Ratio |
|---|---|---|---|
--color-surface |
page background | --neutral-0, #ffffff |
|
--color-surface-alt |
code blocks | --neutral-100, #e8e8e8 |
text on it 12.98:1 |
--color-text |
text | --neutral-950, #222222 |
on surface 15.91:1 |
--color-muted |
secondary text | --neutral-700, #5d5d5d |
on surface 6.58:1 |
--color-border |
card, table and form edges | --neutral-300, #bebebe |
on surface 1.86:1 |
--color-bar |
header and footer | --neutral-950, #222222 |
|
--color-on-bar |
text on the bar | --neutral-0, #ffffff |
on bar 15.91:1 |
--color-accent |
button fill | --blue-600, #0078cd |
|
--color-on-accent |
text on the accent | --neutral-0, #ffffff |
4.60:1; on hover 6.60:1 |
--color-danger |
destructive button fill | --red-600, #d02c2a |
|
--color-on-danger |
text on danger | --neutral-0, #ffffff |
5.15:1; on hover 7.29:1 |
--color-on-status |
text on status labels | --neutral-950, #222222 |
7.53, 7.09 and 6.75:1 |
The borders are 1.86:1 because they’re decoration. They don’t identify a control, so 1.4.11 doesn’t apply; the form fields keep the browser’s own borders.
Semantic tokens are a convention, not a finding. Their cost is two layers of names, which is more than a four-page site needs for one theme. But the payoff comes in the dark theme, which changes only the semantic layer.
Rule: CSS rules use semantic tokens only, and each fill has an
on-token. Check the ratio of each pair, not of each color.
Hover shades and text colors from CSS functions
The old hover jumped to #0000ff. A hover shade should be the same color, a little darker, for whichever button it’s on. color-mix() mixes two colors in a color space you name:
/* excerpt from base.css after the lab */
.button {
--fill: var(--color-accent); /* each kind of button sets its own fill */
background: var(--fill);
}
.button:hover {
background: color-mix(in oklab, var(--fill), black 15%);
}
.button-danger {
--fill: var(--color-danger);
}
The local --fill property is what makes the danger button darken its own red. Before, .button:hover set one blue for every button, and it beat .button-danger because it’s more specific.
The mixes give #005fa5 for the blue, with white text at 6.60:1, and #a72120 for the red, at 7.29:1. In one test in Chrome 157, the pixels matched both. If you mix in sRGB instead, the blue gives #0066ae at 5.98:1, a lighter shade, because sRGB mixes gamma-encoded codes (color-calc/m6.mjs, section D).
color-mix() is Baseline widely available since 2025-11-09: Chrome 111, Firefox 113 and Safari 16.2. The latest CSS Color 5 draft lets you leave out in oklab, and Chrome 157 then mixes in Oklab. But the browser data doesn’t track that shorter form separately, so the lab writes the space.
Relative colors change one number
Module 5 used relative color syntax to read lightness. It can also change one channel: oklch(from #3ea6ff calc(l - 0.15) c h) lowers the lightness by 0.15. Chrome 157 draws it as #0077cc, with white text at 4.66:1 (m6.mjs, section A).
Relative colors are Baseline newly available since 2024-09-16: Chrome 125, Firefox 128 and Safari 18. An older browser drops the declaration, so write a plain hex line before it as a fallback. CSS Color 5 also warns that turning the hue this way can leave sRGB. So the lab uses color-mix(), which needs no fallback.
contrast-color() picks black or white
contrast-color(<color>) returns white or black, whichever contrasts more with the color as a background. The specification leaves the method to the browser and asks only that results meet AA for large text, 3:1. Figure 6 shows Chrome 157’s choices.

Figure 6: contrast-color() in Chrome 157 on three blues. On the right, black wins by 4.65:1 to 4.52:1.
All three choices match the color with the higher WCAG 2 ratio. That fits six tests in the research for this module, so Chrome appears to use the WCAG 2 formula that CSS Color 5 advises against. MDN warns that mid-tones such as #2277d3 suit neither black nor white for small text (MDN).
So contrast-color() would fix Stashling’s button the first way, with black text at 8.10:1. But it can’t choose a darker fill, and it promises only 3:1. It’s Baseline newly available since 2026-04-10: Chrome 147, Firefox 146 and Safari 26. If a browser doesn’t support it, the browser drops the declaration, so put a plain color line before it.
Rule: Let CSS derive shades, then measure the result like any other color.
APCA, a second measure that WCAG does not use
APCA, the Accessible Perceptual Contrast Algorithm, is a contrast method by Andrew Somers that predicts how strong contrast looks on a monitor. Its reference code, apca-w3, is a public beta, last published in July 2022 (apca-w3).
APCA gives Lc, a lightness contrast with a sign. Dark text on a light background gets 0 to about 106, and light text on a dark background 0 to about −108. So, unlike WCAG 2, it treats the two directions differently.
APCA’s own documentation suggests these levels (APCA in a Nutshell):
- Lc 90: preferred for body text.
- Lc 75: the minimum for columns of body text.
- Lc 60: the minimum for other content text.
- Lc 45: for large, heavy text such as headlines.
- Lc 30: the absolute minimum for any text, such as placeholders.
- Lc 15: the minimum for non-text, such as dividers.
These are its author’s levels, not a W3C rule.
The two measures disagree most at mid-tones (palette-output.txt, sections H and I):
| Pair | WCAG 2.2 | APCA Lc |
|---|---|---|
White on the brand blue #3ea6ff |
2.59:1, fails | −55.3 |
| Black on the brand blue | 8.10:1, passes AAA | 53.8 |
White on #0078cd |
4.60:1, passes | −76.7 |
Black on #0078cd |
4.57:1, passes | 32.9 |
#767676 on white |
4.54:1, passes | 71.6 |
#777777 on white |
4.48:1, fails | 71.1 |
WCAG 2 passes black on the brand blue at AAA, but APCA rates it under Lc 60, weak for body text. On #0078cd, WCAG 2 sees almost no difference between black and white, but APCA strongly prefers white. That’s why the lab’s light theme keeps white text on a darker fill.
Where WCAG 3 stands on 18 November 2026
WCAG 3 is a W3C Working Draft, and the W3C says a draft must not be cited as more than a work in progress. Its latest draft is dated 10 September 2026 (WCAG 3.0). Its text contrast requirement reads, in place of a method, @@[contrast measure to be determined]. An editor’s note says: “The contrast algorithm used in WCAG 3 is yet to be determined.”
The note adds that the draft assumes the method will include a factor for text size and weight. The word “APCA” doesn’t appear anywhere in that draft. The drafts of January and December 2021 used an APCA lookup table for text contrast. But the drafts of July 2023, December 2024, March 2026 and September 2026 don’t mention it (publication history).
APCA’s documentation calls it the candidate method for the future WCAG 3. But the W3C drafts don’t support that claim. APCA isn’t part of WCAG 2.2 or of the current WCAG 3 draft, and WCAG 2.2 is the standard to meet.
You’ll still meet APCA. The Chrome DevTools documentation says its color picker suggests APCA-compliant values by default, with WebAIM’s guidelines as an option (Color picker); we didn’t confirm the current default in DevTools. Radix Colors states its text steps in Lc.
Rule: Meet WCAG 2.2. Use APCA as a second opinion on mid-tones, and never report an Lc value as a WCAG result.
Color vision deficiency: never rely on hue alone
A color vision deficiency is a reduced ability to tell some hues apart, usually inherited. In everyday words, people call it color blindness.
Large surveys find red-green deficiency in about 8% of men and 0.4% of women of European descent (Birch, 2012; we read the abstract). In men of Chinese and Japanese descent, they find 4% to 6.5%. The US National Eye Institute names deuteranomaly, a mild red-green type, as the most common (Types of color blindness).
Chrome can simulate the strongest forms. In DevTools, open the Rendering tab and use “Emulate vision deficiencies” (Chrome DevTools). Deuteranopia and protanopia are the full red-green forms, with no red-green distinction at all, and the simulations show those. But most people with a deficiency have a milder form, so a simulation shows the extreme case.
Pause and predict: on the settings page, which status labels will look alike to a reader with deuteranopia?
Figure 7 shows the labels with normal color vision, and Figure 8 shows them with deuteranopia emulated.

Figure 7: the status labels after the lab, with normal color vision.

Figure 8: the same crop with deuteranopia emulated in Chrome 157. Done and Failed have the same color.
With culori’s model of deuteranopia, Done and Failed move from a color difference of 0.237 to 0.006 in Oklab units. CSS treats 0.02 as one just-noticeable step, so they become one color. Their WCAG ratio to each other is only 1.12:1 to begin with (palette-output.txt, section G).
But the page still passes 1.4.1 Use of Color, which forbids color as the only way to convey information, because each label carries a word. A colored dot without a word would fail.
The blue accent survives red-green deficiencies. Under simulated deuteranopia, blue-600 becomes #395acc, still a blue. But the danger red turns into a dark olive, #695a28, so the word “Delete” carries its meaning. Protanopia also darkens reds, which is the exception Understanding 1.4.3 names for red on dark backgrounds.
Rule: Give every color that carries meaning a second signal, such as a word, an icon or a shape. Then check the page with a deuteranopia and a protanopia simulation.
A dark theme is a second palette
A theme is one complete set of values for the semantic color tokens. Stashling now has a light theme, and the dark theme is a second set of values for the same twelve names.
Suppose your first try swaps only the background and the text, and keeps every other color:
/* excerpt: a first try, not the lab's code */
:root {
color-scheme: light dark;
--color-surface: light-dark(var(--neutral-0), var(--neutral-950));
--color-text: light-dark(var(--neutral-950), var(--neutral-100));
/* every other semantic token keeps its light value */
}
light-dark() returns its first color in a light theme and its second in a dark one. Later in this section, you’ll see how the browser decides.
Pause and predict: with this first try, what goes wrong at the top of the landing page in dark mode?
Figure 9 shows the result.

Figure 9: the first try in dark mode. The header is gone, and the muted text is hard to read.
The numbers come from palette-output.txt, section E:
- The muted text, still
#5d5d5d, is 2.42:1 on the dark page. It fails 4.5:1. - The header bar is
#222222on a#222222page, 1.00:1. It disappears. - The button fill,
#0078cd, stands 3.46:1 from the dark page, against 4.60:1 from white. The primary action stands out less than in the light theme. - The borders, still
#bebebe, are 8.56:1 on the dark page, much stronger than 1.86:1 on white.
Three reasons the dark theme needs its own steps
- The dark end has less contrast. Figure 4 showed it. So choose dark values by their measured ratio. Light muted text is 6.58:1; its mirror step, neutral-300, would be 8.56:1 on the dark page, too close to the text’s 12.98:1. Neutral-400 gives 6.38:1, the nearest match.
- Fills need lighter steps. Step 600 sits close to a dark page. Step 300 with dark text, the second fix from Figure 2, gives 8.43:1 for the blue and 7.72:1 for the red. Material Design 2 also tells dark themes to use lighter tones of a color, and to avoid saturated colors on dark surfaces (Dark theme).
- Raised surfaces get lighter. On a dark page, shadows are hard to see. Material Design 2 shows a raised surface by making it lighter. Stashling’s header, footer and code blocks use neutral-900,
#333333, on the neutral-950 page.
Material Design 2 recommends #121212 as a dark surface. But the lab uses its own scale’s step 950, #222222, which gives a little less contrast. Text #e8e8e8 is 12.98:1 on it, against 15.29:1 on #121212 (palette-output.txt, section D).
Figure 10 shows the result with the lab’s tokens.

Figure 10: the dark theme after the lab, in the same crop as Figure 9. Each semantic token has its own dark value.
How light-dark() and color-scheme work
light-dark(a, b) computes to a when the element’s used color scheme is light, and to b when it is dark (CSS Color 5, §7). The used color scheme comes from the color-scheme property (CSS Color Adjust 1):
color-scheme: light darksays the page supports both. The browser uses the reader’s system setting, whichprefers-color-schemereports.- Without a
color-schemedeclaration, the page counts as light. In Chrome 157 with macOS set to dark,light-dark(#ffffff, #000000)still gave#ffffffin the research for this module. - The property is inherited, so one declaration on
:rootcovers the page. - It also switches the browser’s own parts: form fields, checkboxes and scrollbars turn dark, as in Figure 14 later.
A theme button could set color-scheme: light or dark on :root, and every light-dark() would follow. We derived that pattern from the specification; the lab has no button.
MDN also suggests <meta name="color-scheme" content="light dark"> in the HTML head, so the browser knows the scheme before the CSS arrives (MDN). The lab leaves the HTML as it is and sets the property in CSS only.
Browser support and the fallback
light-dark() is Baseline newly available since 2024-05-13: Chrome 123, Firefox 120 and Safari 17.5. Thirty months after that date, it would count as widely available; by our count that was 2026-11-13. But on 2026-11-18, the web-features data (3.46.0) and webstatus.dev still list it as newly available. color-scheme is widely available since 2024-08-03, and @supports since 2018-03-30.
If a browser doesn’t support light-dark(), a var() that holds it is invalid where it’s used. So the page would lose its colors: text in the browser’s default black, and buttons with no fill. So tokens.css ends with a fallback:
/* excerpt from tokens.css */
@supports not (color: light-dark(#000, #fff)) {
:root {
color-scheme: light;
--color-surface: var(--neutral-0);
/* …one plain light value for each semantic token */
}
}
The fallback sets color-scheme: light too. Otherwise, an older browser that knows color-scheme but not light-dark() would draw dark form fields on a light page. To test it, change not (color: light-dark(#000, #fff)) to (color: red) for a moment. Then the page stays light in dark mode.
The other way: a media query
You can redefine the tokens in @media (prefers-color-scheme: dark) { :root { … } }. The media query is Baseline widely available since 2022-07-15, so it needs no fallback. But color-scheme can’t override it for one part of a page, and a theme button then needs an extra selector. Choose the media query when you must support browsers older than Chrome 123, Firefox 120 or Safari 17.5.
What the dark theme costs
Every pair needs a second check and every page a second screenshot. The status labels keep one value in both themes. Module 5 expected them to need dark values, but their text sits on the label, at 7.53, 7.09 and 6.75:1 in both themes. On the dark page they’re the brightest things, which you may decide is too strong.
Images don’t change. The hero photo stays as bright as before, and one landing page icon keeps its pure blue stroke; both are Module 8’s. light-dark() for images is newly available only since 2026-09-14.
Rule: Give each semantic token a dark value chosen by its measured ratio. Never mirror the light steps.
Choices and costs
| Decision | Choice in the lab | Cost or limit | Choose something else when |
|---|---|---|---|
| Button fix | Darker fill, blue-600, white text (4.60:1) | The blue is no longer the brand’s exact blue | The brand color must stay exact: use dark text on it (6.14:1) |
| Scale | Generated, one OKLCH lightness per step | Hue drifts at the ends; one step gives different ratios per hue | Contrast comes first: generate by target ratio |
| Neutrals | Pure grays | Nothing ties them to the accent | You want warmer or cooler grays: tint them with the accent’s hue |
| Token layers | Scale tokens and semantic tokens | Two names for every color | A site with one theme and few colors: one layer |
| Hover | color-mix(in oklab, …, black 15%) |
In the dark theme, darker means less contrast (5.46:1) | You want lighter hovers in dark mode: mix with white there |
| Text on fills | An on- token chosen and checked by hand |
Every pair is a manual check | The fill is unknown in advance: contrast-color(), 3:1 only |
| Contrast measure | WCAG 2.2 | Odd at mid-tones; ignores polarity | A second opinion on mid-tones: APCA, not a standard |
| Dark theme | light-dark() and color-scheme |
Newly available; needs the fallback | Older browsers matter: a prefers-color-scheme media query |
| Dark surface | #222222, step 950 |
Less contrast than #121212 (12.98:1 against 15.29:1 for the text) |
You want the most contrast, or true black for OLED screens |
Material Design 2 notes that true black saves power on OLED screens, but that switching pixels on and off can cause a delay when the screen scrolls.
What changed recently in CSS and standards
All Baseline statuses are from the web-features data (version 3.46.0), read on 2026-11-18.
- WCAG 2.2 is a W3C Recommendation, in its 12 December 2024 edition.
color-mix()became Baseline widely available on 2025-11-09. CSS Color 5 drafts after the one of 18 March 2025 default to Oklab when the space is left out, and allow mixing more than two colors. Only Firefox 150 and Safari 27 mix more than two.contrast-color()became newly available on 2026-04-10.light-dark()has been newly available since 2024-05-13. Its form for images became newly available on 2026-09-14.alpha(from …), for changing only the alpha of a color, became newly available on 2026-09-14. CSS Color 5 (16 November 2026) marks it at risk, so this course doesn’t use it.- The WCAG 3 draft of 10 September 2026 has a text contrast requirement with its method still to be determined. The draft of 3 March 2026 had no text contrast requirement at all.
Online tools for this step
All three were reachable on 2026-11-18 and showed no price. None replaces measuring the pairs in your own CSS.
- WebAIM Contrast Checker. You enter a text and a background color, by hex or with a picker. It gives the WCAG ratio with AA and AAA results for text, large text and UI parts. It has a lightness slider for each color and a JSON form of each result. Limit: WCAG 2 only, one pair at a time, and the page doesn’t say how it rounds. DevTools overlap: Chrome’s color picker shows the ratio of
coloragainstbackground-colorwith AA and AAA lines (Chrome DevTools). The CSS Overview panel lists contrast problems for a whole page. - Leonardo. An open-source tool from Adobe that generates color scales and themes from target contrast ratios or target lightness. It exports SVG, CSS custom properties and W3C Design Tokens. Limit: its package documentation lists LCH, LAB, CAM02, HSL, HSLuv, HSV and RGB for interpolation, not OKLCH. It is built for design systems, which is more than a four-page site needs. DevTools overlap: none.
- Coblis Color Blindness Simulator. You drop in an image, such as a screenshot, and see red-, green- and blue-blind and fully color-blind versions. It says images are processed in the browser and not uploaded. Limit: it works on images, not live pages, and its simulation function is free for non-commercial use only. DevTools overlap: Chrome’s “Emulate vision deficiencies” does the same on the live page.
Check yourself
Critique: the link that passed in light mode
A documentation site adds a dark theme. Its cards in dark mode are #1e1e1e. Links in the cards keep the light theme’s link color, #0078cd, and are underlined. In the light theme, the same links on white measured 4.60:1, so the team didn’t check them again.
A reader writes that links in the cards are hard to read at night.
Hint 1
Compute the ratio of #0078cd on #1e1e1e. Which minimum does link text need?
Hint 2
Look at Figure 3. Which blue step did Stashling’s dark theme use for its accent, and why?
Answer
#0078cd on #1e1e1e is 3.63:1, and its APCA value is Lc −28.6 (palette-output.txt, section J). Link text is text, so it needs 4.5:1, and it fails. It would pass the 3:1 for non-text parts, but that minimum doesn’t apply to text. APCA agrees: −28.6 is under its absolute minimum of Lc 30.
The cause is a light-theme value used on a dark surface. The dark end of the contrast scale is compressed, and step 600 sits close to a dark card.
Give the link a semantic token with its own dark value: --color-link: light-dark(var(--blue-600), var(--blue-300)). Blue-300, #77c4ff, is 8.83:1 on #1e1e1e. Keep the underline, so links don’t rely on hue alone. Then check every pair again in dark mode.
Review questions
- A label is 20 px and bold. Which minimum ratio does it need under 1.4.3, and why?
- A color gives white text 4.499:1. Does it pass? And can an APCA Lc value count as a WCAG 2.2 or WCAG 3 result?
- In Figure 3, why doesn’t white text get the same ratio at step 600 of every scale?
- Why does
.buttonset a--fillproperty instead of writingvar(--color-accent)into the hover’scolor-mix()? - Under deuteranopia, Done and Failed look the same. Why does the settings page still pass 1.4.1, and what change would make it fail?
Answers
- 3:1. Bold text of at least 14 point, which is 18.67 px, counts as large-scale text.
- No. WCAG says not to round, so 4.499:1 fails 4.5:1. And no: APCA isn’t part of WCAG 2.2, and the WCAG 3 draft of 10 September 2026 says its contrast method is still to be determined.
- The steps share OKLCH lightness, but the ratio uses WCAG luminance, which weights hues differently. So at step 600, white is 4.60:1 on blue, 5.15:1 on red and 4.67:1 on gray.
- So each kind of button darkens its own fill. With the accent written into the hover, the danger button would turn blue on hover, as
#0000ffdid before. - Each label carries a word, so color is not the only signal. Replacing the words with colored dots would fail 1.4.1.
The lab: a palette, semantic tokens and a dark theme
In about 15 minutes, you add three scales and twelve semantic tokens to Stashling, fix both buttons, replace every raw color in the page CSS, and add a dark theme. Start from the module-05 folder. Keep index.html and settings.html open, and reload after each step. The finished files are in the module-06 folder of the course repository.
Step 1: measure the button
Why: you need the number before you change a color (see “How WCAG 2.2 turns two colors into one number”).
Run the console code from “A blue button with white words” on index.html. Then run it on settings.html, with ".button-danger" in place of ".button".
What you should see: 2.59 for the blue button and 4.00 for the red one. Chrome’s color picker also shows a ratio, but its documentation says it may suggest APCA values by default.
Step 2: add the scales
Why: each color the site uses becomes one step of a scale (see “A tonal scale: one hue from light to dark”).
In tokens.css, add an empty line after the --color-muted line, then these lines:
/* Color scales: one OKLCH lightness per step, the same in every hue.
Only the steps the site uses, as sRGB hex after gamut mapping. */
--neutral-0: #ffffff; /* L 1.00 */
--neutral-100: #e8e8e8; /* L 0.93 */
--neutral-300: #bebebe; /* L 0.80 */
--neutral-400: #a4a4a4; /* L 0.72 */
--neutral-700: #5d5d5d; /* L 0.48 */
--neutral-900: #333333; /* L 0.32 */
--neutral-950: #222222; /* L 0.25 */
--blue-300: #77c4ff; /* L 0.80, hue of the brand blue #3ea6ff */
--blue-600: #0078cd; /* L 0.56 */
--red-300: #ff998d; /* L 0.80, hue 27 */
--red-600: #d02c2a; /* L 0.56 */
What you should see: nothing changes yet, because no rule uses them.
Step 3: fix the buttons
Why: each fill gets a semantic pair, and each hover darkens its own fill (see “Hover shades and text colors from CSS functions”).
In tokens.css, add an empty line after the --color-status-failed line, then these lines:
/* Semantic colors */
--color-accent: var(--blue-600);
--color-on-accent: var(--neutral-0);
--color-danger: var(--red-600);
--color-on-danger: var(--neutral-0);
In base.css, replace the .button, .button:hover and .button-danger rules with these:
.button {
--fill: var(--color-accent); /* each kind of button sets its own fill */
display: inline-block;
background: var(--fill);
color: var(--color-on-accent);
border: none;
padding: 10px 20px;
font-size: var(--step-0);
cursor: pointer;
}
.button:hover {
background: color-mix(in oklab, var(--fill), black 15%);
text-decoration: none;
}
.button-danger {
--fill: var(--color-danger);
color: var(--color-on-danger);
}
What you should see: Figure 11 beside Figure 1, and Figures 12 and 13 on the settings page. Only the button fills changed. The console code now prints rgb(255, 255, 255) on rgb(0, 120, 205) 4.60. Hover over the red button: it turns a darker red, not blue.

Figure 11: the landing page after step 3, in the same crop as Figure 1. Only the button fill changed: 4.60:1.

Figure 12: the danger button before step 3, #ff0000 with white text, 4.00:1.

Figure 13: the danger button after step 3, red-600 with white text, 5.15:1.
Step 4: name every other color
Why: CSS rules use semantic tokens only, so the next step can change every color in one place.
In tokens.css, delete the line --color-muted: #555; /* secondary text: 7.46:1 on white */. Then make the semantic block read like this:
/* Semantic colors */
--color-surface: var(--neutral-0);
--color-surface-alt: var(--neutral-100);
--color-text: var(--neutral-950);
--color-muted: var(--neutral-700);
--color-border: var(--neutral-300);
--color-bar: var(--neutral-950);
--color-on-bar: var(--neutral-0);
--color-accent: var(--blue-600);
--color-on-accent: var(--neutral-0);
--color-danger: var(--red-600);
--color-on-danger: var(--neutral-0);
--color-on-status: var(--neutral-950);
In base.css, change the colors in four rules. Only the color lines change:
/* excerpt: the changed lines of four rules in base.css */
body {
color: var(--color-text);
background: var(--color-surface);
}
.site-header {
background: var(--color-bar);
color: var(--color-on-bar);
}
pre {
background: var(--color-surface-alt);
}
.site-footer {
background: var(--color-bar);
color: var(--color-on-bar);
}
In index.css (.feature), signup.css (.signup-form) and settings.css (.settings th, .settings td), change border: 1px solid #000; to this:
border: 1px solid var(--color-border);
In settings.css, change the comment and the color of .status:
/* same OKLCH lightness, so no label looks heavier; dark text on all three */
.status {
color: var(--color-on-status);
padding: 2px 6px;
font-size: var(--step--1);
}
In index.html, three feature icons have stroke="#000" or fill="#000": the lock, the stack of layers and the lightning bolt. Change each #000 to currentColor, so the icons take the text color in both themes. Leave the blue cloud icon for Module 8.
Then check that no raw color is left in the page CSS. In the lab folder, run:
grep -nE '#[0-9a-fA-F]{3,6}\b' base.css index.css settings.css signup.css
What you should see: the command prints nothing. Only black is left, inside the hover’s color-mix(), where it means “darker”, not a palette color. The page looks nearly the same: text and bars are #222222 instead of black, borders are light gray, and code blocks are #e8e8e8. Muted text is 6.58:1 instead of 7.46:1, and label text 7.53, 7.09 and 6.75:1 instead of 9.95, 9.35 and 8.91:1.
Step 5: add the dark theme
Why: each semantic token gets a dark value chosen by its ratio (see “A dark theme is a second palette”).
In tokens.css, replace the semantic block with this one:
/* Semantic colors: light-dark(light theme, dark theme) */
color-scheme: light dark;
--color-surface: light-dark(var(--neutral-0), var(--neutral-950));
--color-surface-alt: light-dark(var(--neutral-100), var(--neutral-900));
--color-text: light-dark(var(--neutral-950), var(--neutral-100));
--color-muted: light-dark(var(--neutral-700), var(--neutral-400));
--color-border: light-dark(var(--neutral-300), var(--neutral-700));
--color-bar: light-dark(var(--neutral-950), var(--neutral-900));
--color-on-bar: light-dark(var(--neutral-0), var(--neutral-100));
--color-accent: light-dark(var(--blue-600), var(--blue-300));
--color-on-accent: light-dark(var(--neutral-0), var(--neutral-950));
--color-danger: light-dark(var(--red-600), var(--red-300));
--color-on-danger: light-dark(var(--neutral-0), var(--neutral-950));
--color-on-status: var(--neutral-950);
Then add an empty line and the fallback at the end of the file, after the closing } of :root:
/* Browsers without light-dark() (before Chrome 123, Firefox 120, Safari 17.5)
get the light theme only. */
@supports not (color: light-dark(#000, #fff)) {
:root {
color-scheme: light;
--color-surface: var(--neutral-0);
--color-surface-alt: var(--neutral-100);
--color-text: var(--neutral-950);
--color-muted: var(--neutral-700);
--color-border: var(--neutral-300);
--color-bar: var(--neutral-950);
--color-on-bar: var(--neutral-0);
--color-accent: var(--blue-600);
--color-on-accent: var(--neutral-0);
--color-danger: var(--red-600);
--color-on-danger: var(--neutral-0);
}
}
The light values in the fallback are the ones you typed in step 4. To see the dark theme, open the Rendering tab in DevTools and set “Emulate CSS media feature prefers-color-scheme” to prefers-color-scheme: dark (Chrome DevTools), or switch your system to dark mode.
What you should see: Figure 10 on the landing page and Figure 14 on the settings page. The console code prints rgb(34, 34, 34) on rgb(119, 196, 255) 8.43. With the emulation set to light, the page looks as it did after step 4.

Figure 14: the settings page after the lab, in dark mode. Form controls follow color-scheme, and the fills use their 300 steps.
Step 6: check without some hues
Why: color must never be the only signal (see “Color vision deficiency: never rely on hue alone”).
In the Rendering tab, set “Emulate vision deficiencies” to Deuteranopia, then to Protanopia. Look at the status labels and the red button in both themes. Turn the emulation off afterward.
What you should see: Figure 8 in the light theme. Done and Failed share one color, but their words still tell them apart.
Optional: apply it to a page of your own
Pick a page of your own with at least one colored button.
- List every raw color in its CSS. Group them into neutrals, one accent and colors with fixed meanings.
- For each text and fill pair, measure the ratio with the console code, changing the selector. Mark every pair under 4.5:1, or under 3:1 for large text.
- Replace each fill with a step of a scale that passes, and name it with a semantic token and an
on-partner. - Add
light-dark()values for a dark theme, chosen by their measured ratio, and the@supports notfallback.
Then emulate dark mode and deuteranopia, and measure every pair again.
Module 6 cheat sheet
Ratio (L1 + 0.05) / (L2 + 0.05); 4.5:1 text, 3:1 large text and UI
Large text 24px, or 18.67px bold; never round 4.499 up to 4.5
Palette neutrals + one accent; danger and status are their own family
Scale one OKLCH lightness per step for every hue; store the mapped hex
Tokens rule -> semantic token (its job) -> scale step; fills have on-
Hover color-mix(in oklab, var(--fill), black 15%)
Dark color-scheme: light dark; light-dark(light, dark); own steps
Fallback @supports not (color: light-dark(#000, #fff)) { light values }
Checks ratios in both themes; deuteranopia; APCA is not WCAG
Module 7, Layout and Responsive Design, starts with the sign-up form that works on a laptop and breaks on a phone.
Sources
Standards:
- W3C, Web Content Accessibility Guidelines (WCAG) 2.2, Recommendation, 12 December 2024: the contrast ratio, 1.4.1, 1.4.3 and 1.4.11. With Understanding 1.4.3 Contrast (Minimum), for where 3:1, 4.5:1 and the 0.05 come from, and Understanding 1.4.11 Non-text Contrast. The place to start for going deeper.
- W3C, WCAG 3.0, Working Draft, 10 September 2026, and its publication history.
- W3C, CSS Color Module Level 5, Working Draft, 16 November 2026:
color-mix(), relative colors,light-dark()andcontrast-color(). - W3C, CSS Color Adjustment Module Level 1, Candidate Recommendation Snapshot, 16 December 2025:
color-schemeand the used color scheme.
Contrast and color vision:
- Andrew Somers, apca-w3 (version 0.1.9) and APCA in a Nutshell, the method’s own description and levels.
- J. Birch, “Worldwide prevalence of red-green color deficiency“, Journal of the Optical Society of America A 29(3), 2012.
- National Eye Institute, Types of color blindness.
Design systems, cited for what they recommend:
- Material Design 2, Dark theme, and Material Design 3, How the system works.
- Radix Colors, Understanding the scale.
Browsers:
- MDN,
light-dark(),color-scheme,contrast-color()andcolor-mix(). - Chrome for Developers, DevTools pages on the color picker, contrast, emulating CSS media features and vision deficiencies.
- The web-features data, version 3.46.0, and webstatus.dev, for every Baseline status in this module.
The numbers in this module come from scripts in the course’s color-calc/ folder, with their output saved beside them: calc.mjs, m6.mjs and m6/palette.mjs. They use colorjs.io 0.7.1, culori 4.0.2 for the color vision simulations and apca-w3 0.1.9. palette.mjs checks its own WCAG formula against colorjs.io before it prints anything. Run them with Node.js after npm install in that folder.