Relative luminance is the foundation of every WCAG color-contrast check. It converts a color into a single number that represents how much light it emits to the eye, so two colors can be compared objectively for legibility.
How it works
Each sRGB channel (0–255) is first divided by 255, then linearized with the WCAG piecewise gamma transform:
c_srgb = channel / 255
c_lin = c_srgb / 12.92 if c_srgb <= 0.03928
c_lin = ((c_srgb + 0.055) / 1.055) ^ 2.4 otherwise
The three linear channels are then combined with the Rec. 709 luminance weights:
L = 0.2126 * R_lin + 0.7152 * G_lin + 0.0722 * B_lin
The result L ranges from 0 for pure black to 1 for pure white.
Using it for contrast
Once you have the luminance of a foreground and a background color, the WCAG contrast ratio is (Llighter + 0.05) / (Ldarker + 0.05). A ratio of 4.5 or higher passes AA for normal text, and 3 is enough for large text. Note that luminance is not the same as HSL lightness: it is perceptually weighted toward green, so a saturated green will read far brighter than a saturated blue of the same nominal lightness.