Skip to main content
Home / Luminance Mathematics
← Back to Contrast Checker
📖 Accessibility Formulas & Mathematics

Luminance & Contrast Mathematics

The Web Content Accessibility Guidelines (WCAG) define a precise mathematical algorithm to audit visual contrast. Below is a breakdown of sRGB linearization, relative luminance weights, and how the final contrast ratio is derived.

1. Relative Luminance Formula

Relative luminance ($L$) measures the perceived brightness of a color. It is calculated by applying weighting coefficients to the linearized red ($R_s$), green ($G_s$), and blue ($B_s$) channels to match human eye sensitivity:

Note: Green is weighted highest (71.52%) as the human eye is most sensitive to green wavelengths.

2. Channel sRGB Linearization

Web colors are compressed in sRGB space. To perform linear physical operations, each color channel $C_{\text{rgb}} \in [0, 1]$ (derived from dividing the 0–255 value by 255) must be converted to linear light values $C_s$:

3. Final Contrast Ratio

The contrast ratio is calculated by comparing the relative luminance values of the lighter color ($L_{\text{light}}$) and the darker color ($L_{\text{dark}}$), adding a constant offset ($0.05$) to account for ambient light striking the display screen:

This results in ratios ranging from 1.0:1 (identical colors, zero contrast) to 21.0:1 (pure black vs pure white).

Selected Color Pairing Trace

Dynamic
#FFFFFF vs #000000 Ratio: 21.00:1
AAA Pass

The active color parameters are parsed from the URL query strings. Below is the step-by-step substitution trace using linear luminance values:

Want to test a different pairing? Go back to the interactive checker, tweak the colors, and click the formula details link to recalculate this trace.