How the contrast ratio is calculated
The WCAG contrast ratio compares the relative luminance of two colors using the formula (L1 + 0.05) / (L2 + 0.05), where L1 is the lighter luminance and L2 is the darker. Relative luminance is computed from sRGB values using a gamma correction formula that models how human vision perceives light — it's not the same as HSL lightness. Two colors at similar HSL lightness can have very different relative luminance. The formula produces ratios from 1:1 (identical colors) to 21:1 (pure black against pure white). The +0.05 constants prevent division-by-zero at pure black and provide a slight adjustment for the non-linearity of human visual response near absolute black.
