Fetching latest headlines…
The WCAG Contrast Ratio, Explained (With a Live Checker)
NORTH AMERICA
πŸ‡ΊπŸ‡Έ United Statesβ€’June 27, 2026

The WCAG Contrast Ratio, Explained (With a Live Checker)

0 views0 likes0 comments
Originally published byDev.to

Is your text readable on that background? There's a precise, math-backed answer β€” the WCAG contrast ratio β€” and you can compute it in ~10 lines. Here's a live checker, no library.

πŸŒ— Try it (pick fg + bg colors): https://dev48v.infy.uk/solve/day18-contrast-checker.html

The math (it's exact)

  1. Hex β†’ RGB (0–255 β†’ 0–1).
  2. Linearize each channel (undo sRGB gamma): if c ≀ 0.03928, c/12.92, else ((c+0.055)/1.055)^2.4.
  3. Relative luminance = 0.2126Β·R + 0.7152Β·G + 0.0722Β·B (green is weighted heaviest β€” your eyes are most sensitive to it).
  4. Ratio = (L_lighter + 0.05) / (L_darker + 0.05) β€” ranges 1:1 (identical) to 21:1 (black on white).

The thresholds

  • AA normal text β‰₯ 4.5:1, large text β‰₯ 3:1
  • AAA normal β‰₯ 7:1, large β‰₯ 4.5:1
  • "Large" = β‰₯18pt (or 14pt bold)

Sanity check: #000 on #fff = 21:1 (max); #777 on #fff β‰ˆ 4.48:1 (fails AA-normal, passes AA-large).

Why bother

~1 in 12 people have some color-vision deficiency; low contrast hurts everyone in sunlight. And never rely on color alone to convey meaning.

πŸ”¨ Full build (hexβ†’rgb β†’ linearize β†’ luminance β†’ ratio β†’ thresholds) on the page: https://dev48v.infy.uk/solve/day18-contrast-checker.html

Part of SolveFromZero. 🌐 https://dev48v.infy.uk

Comments (0)

Sign in to join the discussion

Be the first to comment!