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:
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
DynamicThe active color parameters are parsed from the URL query strings. Below is the step-by-step substitution trace using linear luminance values: