Scoring two colours against WCAG
Set a foreground and a background, either with the colour pickers or by typing six-digit hex values, and the fields stay in sync both ways. The page computes the relative luminance of each colour by linearising its sRGB channels and weighting them at 0.2126, 0.7152 and 0.0722, then divides the lighter value plus 0.05 by the darker value plus 0.05. That ratio drives a live preview panel, a numeric readout and four pass or fail rows.
A worked example
The defaults, #111827 text on #ffffff, score 17.74:1 and the badge reads AAA. Change the text to #767676 and the ratio falls to 4.54:1, which is still enough for Normal text at AA (needs 4.5:1) and for both large-text rows, but fails Normal AAA (needs 7:1). The badge itself flips through AAA at 7:1, AA at 4.5:1, AA Large at 3:1, then Fail below that.
How the four rows are decided
Each row applies one minimum: normal text is tested against 4.5:1 for AA and 7:1 for AAA, while large text is tested against 3:1 and 4.5:1. The label states the threshold, so a Fail row always tells you the number you need to reach. Values are shown to two decimals. Sample a colour off your own layout with the color picker, then check the same pair in the color blindness simulator.
Where it stops
- Input is validated as six hex digits, so three-digit shorthand, named colours and alpha channels are rejected.
- The 18px and bold 14px cutoffs are the WCAG convention, not a measurement of the font on your page.
- Only flat pairs are compared; gradients, images and semi-transparent overlays need manual sampling.
- No ratio is stored, so results vanish when you reload.
Questions people ask
What ratio is safe for body copy?
4.5:1 meets AA for normal text; 7:1 clears AAA if you need the stricter level.
Does this cover icons and buttons?
Contrast for non-text graphics has its own 3:1 rule, and this page reports text thresholds rather than judging components.
Is darker always better?
No. Both very dark and very light foregrounds can pass, because the calculation depends on the gap between the two luminances.