The number was 4.37:1. It was the contrast between the text and the background of a small red "danger" badge on my demo site, demo.miguelcarino.com, the working Angular app behind the posts on this blog. I hadn't measured it. The site's new accessibility check had, on its very first run, and it failed the build over it.
Contrast ratio is how WCAG, the W3C's accessibility guidelines, measures whether text stands out from what's behind it. It runs from 1:1, the same color on itself, to 21:1, black on white. At level AA, the usual target, text at normal size needs at least 4.5:1. The badge was 0.13 short.
The check was a sweep I'd just added. Playwright, Microsoft's browser automation tool, opens every page in a real browser, and axe-core, Deque's open-source accessibility rules engine, scans what it renders. Any violation fails the build.
A shade that looked fine
The badge set its text in the danger hue, a terracotta red, #b44835, on a pale tint made from 12% of that same red. At a glance it reads perfectly well. That's what makes 4.37:1 such a sneaky number. It's close enough to pass any glance and far enough to fail the measurement, and WCAG says outright that ratios aren't rounded, so 4.499:1 fails too. The line works like the sizer box for carry-on bags at the gate. A bag that's a little too big doesn't get partial credit.
The red made a strong border and a clear fill. The mistake was using one design token, a named color value the components share, for two jobs, and readable words on a pale background ask more of a color than a border does.
I fixed the badge by moving its text to a deeper shade of the same red. That afternoon the same pair turned up on another page, as the error text in a CSS :has() demo, also at 4.37:1, and got the same fix. A few days later I caught a third in Chrome's DevTools: brand-colored text, used for links and the active menu item, on a pale surface at 4.41:1, in a theme the demo had then. The sweep had missed that one for a plain reason: it scanned every page in one theme only.
All three had the same cause.
Text gets its own token
The real fix was a rule in the tokens themselves. Each status color now has a -text shade for words, and the saturated hue stays for fills, borders and icons. When I raised the site's bar from AA to AAA, which asks 7:1 of body text, those text shades went darker again until they cleared 7:1 on plain surfaces and on their own tints. The sweep got a loop over every theme, so a color can't pass in light and fail in dark.
The badge as it ships, trimmed to the danger variant:
&--danger {
background-color: var(--foo-color-danger-bg);
// Text uses the AAA-darkened -text shade; the fill/border keep the saturated danger hue.
color: var(--foo-color-danger-text);
border: 1px solid var(--foo-color-danger);
}
The demo's contrast catch section puts the old pair and the shipping badge side by side and measures both in your browser. The math is WCAG's own, from a small file in the demo, trimmed to the two functions that do the work:
export function relativeLuminance([r, g, b]: Rgb): number {
const lin = (channel: number) => {
const c = channel / 255;
return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
};
return 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);
}
export function contrastRatio(a: Rgb, b: Rgb): number {
const [hi, lo] = [relativeLuminance(a), relativeLuminance(b)].sort((x, y) => y - x);
return (hi + 0.05) / (lo + 0.05);
}
Relative luminance is how bright a color is to the eye, from 0 for black to 1 for white, with green counting for most of it. The ratio adds 0.05 to both sides, so even black on black comes out at a defined 1:1. The unit test pins the history to that arithmetic:
it('reproduces the 4.37:1 the sweep caught: #b44835 on its 12% tint of #fffaf3', () => {
const accent = parseColor('#b44835');
const tint = mixSrgb(accent, parseColor('#fffaf3'), 0.12);
expect(formatRatio(contrastRatio(accent, tint))).toBe('4.37:1');
expect(meets(contrastRatio(accent, tint), 4.5)).toBe(false);
});
On the page, the component reads the colors the browser actually painted with getComputedStyle, so the numbers follow the theme. In light, the old pair reads 4.37:1 and fails AA, and the shipping badge reads 7.96:1. In dark, the old pair reads 4.99:1, which passes AA and still fails AAA, and the shipping badge reads 7.00:1, judged on the unrounded value. Switch the theme in the header and both readouts change.
One detail I like: the "before" sample is drawn as colored bars with no words in them. That page goes through the same sweep with nothing excluded, so it couldn't ship the very failure it describes.
What a design tool can't measure
Checking by eye is what let the badge through, and that's no knock on anyone's eyes. A 0.13 miss is invisible on a good monitor in a bright room, and plenty of the people the rule protects aren't reading on one.
Contrast plugins for design tools catch a lot early, and I'd want one in any design team's kit. They measure the colors in the design file. This badge's tint was mixed in CSS at runtime with color-mix(), from tokens that differ by theme, so the only reliable measurement was of the rendered page.
Chrome's DevTools show a contrast ratio in the color picker for any text you inspect. That's how I found the third miss. It's precise and it's manual, one element at a time, which is why the fix that stuck was making the sweep run every theme.
APCA, the Accessible Perceptual Contrast Algorithm, models how people actually perceive contrast, including font size, weight and whether text is dark on light or light on dark. It was in early drafts of WCAG 3 and was later taken out, and the WCAG 3 contrast method is still undecided. Conformance today is judged on the WCAG 2 ratio, so that's what the sweep enforces.
Words Get Their Own Shade
The badge taught the design system a rule it now enforces on every color: the shade for words is chosen for words, and the bright hue keeps the borders, fills and icons. Contrast is checked on the page the browser painted, in every theme, on every pull request. The demo still shows the old pair failing beside the badge that replaced it, measured live in whichever theme you're reading in.



