How Browser Relative Luminance & WCAG Contrast Work
Accessible color architecture ensures interfaces remain legible for users with low vision, color vision deficiencies, or screens viewed in bright daylight. Rather than relying on naive RGB averages, the W3C Web Content Accessibility Guidelines compute contrast from linearized relative luminance (L), weighting green light highest (71.52%) to match human cone sensitivity.
Exact W3C Contrast Formula
function srgbToLinear(channel8Bit) {
const v = channel8Bit / 255;
return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
}
function relativeLuminance(r, g, b) {
return 0.2126 * srgbToLinear(r) + 0.7152 * srgbToLinear(g) + 0.0722 * srgbToLinear(b);
}
// Contrast Ratio ranges from 1:1 (identical) to 21:1 (black on white)
const ratio = (Math.max(L1, L2) + 0.05) / (Math.min(L1, L2) + 0.05);
Designing Accessible Light-Theme Token Scales
- 50–100 Tints: Subtle callout backgrounds and pill fills paired with 700–900 foreground text.
- 200–300 Borders: Hairline card dividers and resting input borders (verify 3:1 when border alone indicates control bounds).
- 600–700 Actions: Primary interactive buttons and inline links that reliably pass 4.5:1 against white surfaces.
- 800–950 Ink: High-contrast headings and body copy delivering effortless reading comfort.
Explore perceptual color modeling in our OKLCH Color Palettes & Accessible Contrast Guide.
Frequently Asked Questions
What contrast ratio is required for standard body copy?
WCAG 2.1 Success Criterion 1.4.3 (Level AA) requires at least 4.5:1 for normal text under 18pt (24px) or 14pt bold (18.66px). Level AAA enhanced readability requires at least 7.0:1.
What are the contrast rules for form borders, buttons, and icons?
Under WCAG 2.1 Criterion 1.4.11 (Non-text Contrast), interactive UI boundaries (such as input borders, focus indicators, and standalone action icons) must achieve at least 3.0:1 against adjacent surfaces.
How is WCAG relative luminance computed from sRGB hex codes?
Each 8-bit RGB channel is normalized to 0–1, linearized using the sRGB transfer function (dividing by 12.92 below 0.03928, or applying ((V + 0.055) / 1.055)^2.4 above), and weighted as L = 0.2126*R + 0.7152*G + 0.0722*B.
Why test middle shades (400–600) carefully on white buttons?
Many saturated brand blues, teals, and emeralds pass 4.5:1 only at shade 600 or 700 when paired with white button labels. Auditing the full 50–950 ramp prevents low-contrast primary CTAs.