Convert a screen sRGB color into CIE L*a*b*, a perceptually uniform color space where equal numeric distances correspond to roughly equal perceived color differences. Useful for color-difference (Delta E) work, gradients, and matching.
How it works
RGB cannot be turned into Lab directly — it must pass through linear light and CIE XYZ:
- Gamma expand each sRGB channel to linear RGB:
c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ^ 2.4
- Linear RGB to XYZ using the sRGB / D65 matrix:
X = 0.4124*r + 0.3576*g + 0.1805*b
Y = 0.2126*r + 0.7152*g + 0.0722*b
Z = 0.0193*r + 0.1192*g + 0.9505*b
- XYZ to Lab — normalise by the D65 white (Xn 95.047, Yn 100, Zn 108.883), apply the CIELAB nonlinearity
f(t), then:
L* = 116*f(Y/Yn) - 16
a* = 500*(f(X/Xn) - f(Y/Yn))
b* = 200*(f(Y/Yn) - f(Z/Zn))
where f(t) = t^(1/3) for t > (6/29)^3, otherwise a linear segment.
Example
Convert rgb(59, 130, 246) (a blue): L* ≈ 55.6, a* ≈ 17.6, b* ≈ −64.4 — high lightness, slightly toward red on a*, strongly toward blue on b*.
Notes
Values use the D65 white point to match CSS lab() and common design tools. The whole pipeline runs in your browser — nothing is uploaded.