# Relative Luminance Calculator

URL: https://hifreetools.com/developer/relative-luminance-calculator

> Calculate the relative luminance of any color (0 = absolute black, 1 = absolute white) using the WCAG 2.x linearization formula, essential for contrast ratio and accessibility compliance checks.

## Quick answer

Relative luminance is a perceptual measure of a color's brightness, ranging from 0 (pure black) to 1 (pure white), as defined by WCAG 2.x and the IEC 61966-2-1 sRGB standard. To calculate it, each 8-bit RGB channel is divided by 255, gamma-corrected to linear light, and then combined using the weighted sum L = 0.2126R + 0.7152G + 0.0722B. The weights reflect human eye sensitivity: green contributes most to perceived brightness, red contributes moderately, and blue contributes least. Relative luminance is the foundation for computing the WCAG contrast ratio between two colors, which must be at least 4.5:1 for normal text (AA) and 7:1 for enhanced (AAA) compliance.

## Formula

- C = channel ÷ 255; C_linear = C ÷ 12.92 if C ≤ 0.04045, else ((C + 0.055) ÷ 1.055)^2.4
- L = 0.2126 × R_linear + 0.7152 × G_linear + 0.0722 × B_linear
- Contrast ratio = (L1 + 0.05) ÷ (L2 + 0.05), L1 the lighter colour

## Inputs

- Hex colour code; default #1A73E8
- R (0–255) (0 to 255); default 26
- G (0–255) (0 to 255); default 115
- B (0–255) (0 to 255); default 232

## Worked examples (computed by the page's own function)

- Hex colour code = #FF0000 → Relative luminance = 0.2126, On white = 4, On black = 5.25, R linear = 1  (L = 0.2126 × 1.00000 + 0.7152 × 0.00000 + 0.0722 × 0.00000 = 0.21260)
- Hex colour code = #808080 → Relative luminance = 0.2159, On white = 3.95, On black = 5.32, R linear = 0.21586  (L = 0.2126 × 0.21586 + 0.7152 × 0.21586 + 0.0722 × 0.21586 = 0.21586)
- R (0–255) = 119, G (0–255) = 119, B (0–255) = 119 → Relative luminance = 0.1845, On white = 4.48, On black = 4.69, R linear = 0.18447  (L = 0.2126 × 0.18447 + 0.7152 × 0.18447 + 0.0722 × 0.18447 = 0.18447)

## Verification

Checked against 15 reference cases (expected values computed independently). Reviewed 2026-10-27. Latest change 2026-10-28: Moved to the schema color renderer; uses the WCAG 2.2 linearisation threshold 0.04045 (was 0.03928 — identical for 8-bit input) and shows AA/AAA verdicts against white and black.

## FAQ

**What is relative luminance and why does it matter for accessibility?**
Relative luminance is a WCAG-defined measure of a color's perceived brightness on a scale of 0 (black) to 1 (white). It matters because WCAG contrast ratios — required for accessible text — are computed directly from the luminance values of the foreground and background colors. Without correct luminance values, you cannot verify AA (4.5:1) or AAA (7:1) compliance.

**How is relative luminance different from lightness (HSL)?**
HSL lightness is a simple average-based approximation that does not account for human eye sensitivity to different wavelengths. Relative luminance uses ITU-R BT.709 coefficients (0.2126 R, 0.7152 G, 0.0722 B) that reflect how much each color channel contributes to perceived brightness. #FF0000 (red) has an HSL lightness of 50% but a relative luminance of only 0.2126.

**What does the gamma linearization step do?**
Digital images use gamma encoding (sRGB) so that more bit values are allocated to dark shades where human perception is most sensitive. Before computing luminance, you must undo this encoding (linearize) so that the values represent actual light intensity. Values ≤ 0.04045 are in a near-linear region and use simple division; higher values use the power function with exponent 2.4.

**How do I calculate the WCAG contrast ratio using luminance?**
Once you have the relative luminance of both colors, the contrast ratio is (L1 + 0.05) / (L2 + 0.05), where L1 is the lighter luminance and L2 is the darker. Adding 0.05 accounts for ambient light in a typical screen environment. For example, white (L=1.0) against black (L=0.0) gives (1.05) / (0.05) = 21:1, the maximum possible ratio.

**Can I input a hex color code instead of separate RGB values?**
Yes. A hex code like #1A2B3C maps directly to RGB: R=0x1A=26, G=0x2B=43, B=0x3C=60. You can split any 6-digit hex into three 2-digit hex pairs and convert each to decimal. This calculator accepts a hex field and converts it automatically, or you can enter the R, G, B values directly.

**Why does green contribute so much more than blue to luminance?**
The human eye has three types of cone cells. The L-cones (long wavelength, sensitive to red) and M-cones (medium, sensitive to green) are far more numerous and sensitive than S-cones (short, sensitive to blue). The BT.709 coefficients — 0.2126 R, 0.7152 G, 0.0722 B — encode this physiological reality. Blue contributes only about 7% of perceived brightness even at full intensity.


## Sources

- [W3C — WCAG 2.2: relative luminance (0.04045 threshold) and contrast ratio](https://www.w3.org/TR/WCAG22/)
- [W3C — Understanding SC 1.4.3 Contrast (Minimum)](https://www.w3.org/WAI/WCAG22/Understanding/contrast-minimum.html)
- [W3C — Understanding SC 1.4.6 Contrast (Enhanced)](https://www.w3.org/WAI/WCAG22/Understanding/contrast-enhanced.html)
- [W3C — A Standard Default Color Space for the Internet: sRGB](https://www.w3.org/Graphics/Color/sRGB.html)
- [ITU-R BT.709 — HDTV parameter values (luminance coefficients)](https://www.itu.int/rec/R-REC-BT.709/en)

Runs in the browser; nothing is uploaded. Cite as: HIFreeTools, "Relative Luminance Calculator", https://hifreetools.com/developer/relative-luminance-calculator
