Bea’s catalogue now has two themes, an always-dark “Returns week” banner, and a switch for visitors. Every pairing looks fine on your screen, but nobody has checked that everyone can read the text in both themes. Bea also wants each seed card’s type to match the colored band on her printed packets.
In this lesson, you’ll measure text colors on solid backgrounds with DevTools, decide which minimum each must meet, and fix the ones that fall short in either theme. Start with a pair that’s been in the catalogue since the first lesson.
Measure a Pair in the Color Picker
How readable a color looks to you isn’t a reliable test, because you know what the text says. Someone with low vision, or reading a phone in sunlight, sees much less difference. Light gray on white often looks fine to whoever picked it and still fails.
So the Web Content Accessibility Guidelines, or WCAG, set a number. A contrast ratio compares the relative luminance of two colors, or how much light they give off. It ranges from 1:1 for identical colors to 21:1 for black on white. The criterion for text is 1.4.3 Contrast (Minimum), at Level AA:
- Text needs at least 4.5:1 against its background.
- Large text, at least 24px or about 18.66px bold, needs at least 3:1. In the catalogue, only the headings are large text. If you want a refresher on how font size and weight are set, it’s in Boxes, Type, and Visual Design With CSS.
DevTools measures the ratio for you. The catalogue follows the system setting by default, so first check Light in its theme switch to measure the light theme. Then open DevTools, select the <body> element, and in the Styles pane click the color square next to color: var(--color-text).
The picker’s Contrast ratio line shows 17.06 with a check mark. Click the line to expand it. It lists the AA minimum, 4.5, and the AAA one, 7, and marks whether the pair passes each. The AAA row is 1.4.6 Contrast (Enhanced), a stricter level this course doesn’t target.
Now measure the label on the “Borrow seeds” buttons. Select the first button’s <a> element and open the picker from color: var(--color-on-accent). It’s 4.32, below 4.5, marked as failing.
Force :hover from the :hov menu and open the picker again. On the darker hover background, the ratio drops to 2.82. Then uncheck :hover to return the button to its normal state.
That label has looked fine through every lesson, yet it fails in both states. No single color passes on both terracottas, either. Pale text does better on hover, but it measures 3.95 on the lighter one.
So give the label two roles, one for each state. In the semantic tokens, replace --color-on-accent with these two lines:
--color-on-accent: var(--green-15);
--color-on-accent-hover: light-dark(var(--green-98), var(--green-15));
The hover label is pale in the light theme and dark in the dark one. Use the new token in the hover rule:
.borrow-button:hover {
background-color: var(--color-accent-hover);
color: var(--color-on-accent-hover);
}