Sub topic 11
Why Equal Numeric Value Does Not Look Equally Light
This chapter assumes you know what hue, saturation, and value mean, and that you have seen the HSV and HSL models. You should also be able to read short Python and CSS snippets. By the end, you will be able to explain why two colors with the same "value" number can differ a lot in brightness. You will also be able to measure perceived lightness and correct for the difference.
The problem: the number is not the brightness
In HSV, value is the largest of the red, green, and blue channels. In HSL, lightness is the average of the largest and smallest channels. Both are simple arithmetic on the channel numbers. Neither asks how bright the color looks to a person.
Compare pure yellow and pure blue:
| Color | RGB | HSV value | HSL lightness |
|---|---|---|---|
| Yellow | 255, 255, 0 | 100% | 50% |
| Blue | 0, 0, 255 | 100% | 50% |
By both models these two colors are tied. Yellow still looks far lighter than blue. Put blue text on a yellow background and it is easy to read. Swap the two hues and the text on screen is much harder to read. The sliders in your design tool say "equal", but your eyes disagree.
Why the eye disagrees with the model
Three effects combine.
- The eye is not equally sensitive to red, green, and blue light. Human vision responds most strongly to green, moderately to red, and weakly to blue. A fully lit green channel contributes much more perceived brightness than a fully lit blue channel.
- sRGB values are gamma encoded. Screen values are not proportional to emitted light. A channel value of 0.5 produces only about 21% of the light of a value of 1.0. To reason about light, you must first convert to linear light.
- Perception is not linear in light. Doubling the light does not double the apparent lightness. The eye responds roughly to the cube root of luminance, which is the reason perceptual lightness scales such as CIELAB's L* exist.
A fourth effect is smaller. Highly saturated colors can look brighter than a gray of the same luminance (the Helmholtz–Kohlrausch effect). It is usually a second-order concern, but it explains why a vivid red can look "louder" than its measured lightness suggests.
Measuring perceived lightness
The standard pipeline has three steps.
- Decode gamma. Convert each sRGB channel
c(0 to 1) to linear light: ifc <= 0.04045, usec / 12.92. Otherwise use((c + 0.055) / 1.055) ** 2.4. - Weight the channels. Relative luminance is
Y = 0.2126 R + 0.7152 G + 0.0722 B, using linear values. These weights are the Rec. 709 primaries that sRGB uses. They encode the eye's sensitivity: green dominates and blue barely counts. - Apply the perceptual curve. CIELAB lightness is
L* = 116 * Y^(1/3) - 16for most values of Y, and903.3 * Yfor very dark ones. L* runs from 0 (black) to 100 (white) and is designed so equal steps look roughly equal.
Seeing it in code
The script below takes the six fully saturated hues, all at HSL lightness 50%, and prints their perceptual lightness.
import colorsys
def srgb_to_linear(c):
if c <= 0.04045:
return c / 12.92
return ((c + 0.055) / 1.055) ** 2.4
def relative_luminance(r, g, b):
return (0.2126 * srgb_to_linear(r)
+ 0.7152 * srgb_to_linear(g)
+ 0.0722 * srgb_to_linear(b))
def lstar(r, g, b):
y = relative_luminance(r, g, b)
if y <= 216 / 24389:
return y * 24389 / 27
return 116 * y ** (1 / 3) - 16
hues = {"red": 0, "yellow": 60, "green": 120,
"cyan": 180, "blue": 240, "magenta": 300}
for name, hue in hues.items():
r, g, b = colorsys.hls_to_rgb(hue / 360, 0.5, 1.0)
print(f"{name:8s} HSL L=50% L*={lstar(r, g, b):5.1f}")Running it prints:
red HSL L=50% L*= 53.2
yellow HSL L=50% L*= 97.1
green HSL L=50% L*= 87.7
cyan HSL L=50% L*= 91.1
blue HSL L=50% L*= 32.3
magenta HSL L=50% L*= 60.3Every row has the same HSL lightness, yet perceived lightness spans from about 32 to about 97. The chart shows the same numbers in order.
The pattern follows the channel weights. Colors with a lot of green (yellow, cyan, green) sit at the top. Colors that rely on blue sit at the bottom.
Equalizing lightness across hues
If you want several hues to look equally light, you must solve for the model lightness that gives each one the same L*. Luminance rises steadily as HSL lightness rises, so a bisection search finds the answer.
import colorsys
def srgb_to_linear(c):
if c <= 0.04045:
return c / 12.92
return ((c + 0.055) / 1.055) ** 2.4
def lstar(r, g, b):
y = (0.2126 * srgb_to_linear(r)
+ 0.7152 * srgb_to_linear(g)
+ 0.0722 * srgb_to_linear(b))
if y <= 216 / 24389:
return y * 24389 / 27
return 116 * y ** (1 / 3) - 16
def match_lightness(hue_deg, sat, target):
"""Find the HSL lightness (0 to 1) whose L* equals target."""
lo, hi = 0.0, 1.0
for _ in range(40):
mid = (lo + hi) / 2
r, g, b = colorsys.hls_to_rgb(hue_deg / 360, mid, sat)
if lstar(r, g, b) < target:
lo = mid
else:
hi = mid
return (lo + hi) / 2
for name, hue in {"red": 0, "yellow": 60, "green": 120, "blue": 240}.items():
l = match_lightness(hue, 1.0, 60)
print(f"{name:7s} needs HSL lightness {l:.2f} for L*=60")The result differs per hue. Blue needs HSL lightness well above 50%, and yellow and green need it well below. This is why a "same lightness, different hue" set of buttons built by copying one HSL lightness number looks uneven.
Practical consequences
- Grayscale check. Convert a design to grayscale (using luminance, not an average of channels). If two elements merge into the same gray, they have the same perceived lightness and will fail for people who cannot tell their hues apart.
- Chart and category colors. If categories are meant to be equal in weight, use equal L*. Otherwise yellow will dominate and blue will recede, and viewers may read that as a difference in importance.
- Text and backgrounds. Contrast depends on the luminance difference, not on the hue or the HSV value. The contrast ratio in the accessibility chapter is built on the same relative luminance
Yyou computed here. - Light and dark variants. When generating tints and shades by changing HSL lightness, the steps look even for some hues and lumpy for others. A blue scale can look nearly flat in its dark half while a yellow scale jumps.
Better color spaces for this job
HSL and HSV are fast and easy to explain, but they are not perceptually uniform. Modern CSS includes spaces that are closer to it:
.swatch-a { background: oklch(70% 0.15 30); } /* warm red */
.swatch-b { background: oklch(70% 0.15 150); } /* green */
.swatch-c { background: oklch(70% 0.15 260); } /* blue */In OKLCH, the first number is lightness, the second is chroma (a saturation-like quantity), and the third is hue in degrees. Colors that share a lightness number look much closer in lightness than they do in HSL. The trade-off is that some combinations fall outside the range a screen can display, and the browser has to map them back. Older browsers may not support oklch(), so provide a fallback if you need broad support.
HSL and HSV remain good for quick adjustments and for reasoning about the three properties. Switch to a perceptual space, or compute L* as above, when evenness of lightness matters.
Common errors
- Assuming
hsl(h 100% 50%)gives the same brightness for every hue. - Using the simple average
(R + G + B) / 3as brightness. It ignores the eye's channel weights. - Applying the luminance weights directly to gamma-encoded values. Decode to linear light first, except when you deliberately want the older "luma" approximation.
- Reading L as a percentage of light output. It is a perceptual scale, and L 50 is not half as much light as L* 100.
Exercise
A designer sets a blue button to hsl(240 100% 50%) and a yellow button to hsl(60 100% 50%) so that they "have the same lightness". Using the L* values from this chapter, which button looks lighter, by roughly how much, and what is one way to fix the mismatch?
Show answer
The yellow button looks much lighter. Its L is about 97 and blue's is about 32, a gap of about 65 points. To fix it, choose each color's HSL lightness by solving for the same target L, for example with the match_lightness function, which will raise blue's lightness and lower yellow's. A second option is to use oklch() with the same lightness value for both. Either way, you may need to reduce saturation if a target is out of range.
Exercise
Why does the relative luminance formula give green a weight of 0.7152 and blue only 0.0722, and why must you decode sRGB values to linear light before applying those weights?
Show answer
The weights reflect how sensitive human vision is to each primary: the eye responds strongly to green and weakly to blue, so a full green channel adds far more perceived brightness. The weights apply to physical light intensity, but sRGB channel values are gamma encoded and are not proportional to light. A value of 0.5 emits only about 21% of the light of 1.0. Applying the weights to encoded values mixes two different scales and gives a wrong luminance.