Every developer has shipped text that looked fine on their monitor and was unreadable for someone else. WCAG contrast ratios exist to take the guesswork out of that — but most checkers online are either buried in ads or ask you to install something.

So I built one that runs 100% in the browser: pick a text color and a background color, and it instantly shows the contrast ratio, AA/AAA pass-fail badges for normal and large text, and a live preview. No server, no uploads, nothing leaves the page.

Here is what I learned building it.

The formula is simpler than it looks

A contrast ratio is just a comparison of relative luminance — how bright a color actually appears, weighted the way human vision works (we are far more sensitive to green than to blue).

For each sRGB channel, you first linearize it:

function linearize(channel) { const c = channel / 255; return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4); } function luminance(r, g, b) { return 0.2126 * linearize(r) + 0.7152 * linearize(g) + 0.0722 * linearize(b); } function contrastRatio(rgb1, rgb2) { const l1 = luminance(...rgb1); const l2 = luminance(...rgb2); const lighter = Math.max(l1, l2); const darker = Math.min(l1, l2); return (lighter + 0.05) / (darker + 0.05); } 

That is the entire engine. The + 0.05 accounts for ambient light/screen flare, and it is why the maximum possible ratio is exactly 21:1 (pure black on pure white) rather than infinity.

The thresholds you actually need to memorize

Level Normal text Large text
AA 4.5 : 1 3 : 1
AAA 7 : 1 4.5 : 1

"Large" means at least 24px, or at least ~18.7px if bold. AA is the level most regulations and audits target; AAA is the stricter, enhanced level.

Why #767676 is famous

Run the numbers and you find that #767676 on white is 4.54:1 — it is the lightest gray that still passes AA for normal text. One step lighter and you fail. Designers have passed this hex around for years, and now you know it is not folklore, it is just arithmetic.

A few more pairs I verified with the checker while building it:

Text Background Ratio Verdict
#000000 #FFFFFF 21.00 : 1 Passes everything
#0A4450 #FFFFFF 10.74 : 1 AAA
#FFFFFF #0E5A68 7.83 : 1 AAA
#767676 #FFFFFF 4.54 : 1 AA (barely)
#FFFFFF #A9D94B 1.65 : 1 Fails everything

That last one is the trap: a bright lime green feels vibrant and modern, but white text on it is essentially unreadable in bright light — 1.65:1 fails even the large-text threshold by half. Flip it around (dark text #0D1F24 on the same lime) and you get 10.26:1, a AAA pass. Same brand color, opposite result — direction matters.

Two implementation details worth stealing

1. Test both directions. A pair is not "accessible" or "inaccessible" — a direction is. My UI always evaluates the exact foreground/background assignment the user picked, and swapping the colors is one click, because that is the most common fix.

2. Preview with real text sizes. A ratio number is abstract; a preview paragraph at 16px and a heading at 24px make the pass/fail badges obvious. The badges map to the preview, not just to the number, so users see why large text gets a pass at 3:1 while body text does not.

Try it / break it

The tool is here: Color Contrast Checker — everything runs client-side, so view-source is the full documentation.

If you test it against a pair you know from another checker and get a different second decimal, I want to hear about it — rounding in the linearization step is exactly the kind of bug that hides in these tools.

This is part of a series on building small, single-purpose web tools that run entirely in the browser. Next up: compressing an image to an exact file size (50 KB, not "about 50 KB") with a binary search over JPEG quality.