Convert a CIE L*a*b* color back into a displayable sRGB value, with the matching hex code and a live swatch. This reverses the RGB-to-Lab pipeline, so you can take perceptually-defined colors and turn them into something a screen can show.
How it works
The conversion runs the RGB-to-Lab steps in reverse:
- Lab to XYZ — recover the intermediate
fvalues, then invert the nonlinearity (cube where above the threshold, linear segment below) and multiply by the D65 white:
fy = (L* + 16) / 116
fx = fy + a*/500
fz = fy - b*/200
X = Xn * finv(fx) Y = Yn * finv(fy) Z = Zn * finv(fz)
- XYZ to linear sRGB with the inverse matrix:
r = 3.2406*X - 1.5372*Y - 0.4986*Z
g = -0.9689*X + 1.8758*Y + 0.0415*Z
b = 0.0557*X - 0.2040*Y + 1.0570*Z
- Gamma encode each linear channel and scale to 0–255:
c <= 0.0031308 ? 12.92*c : 1.055*c^(1/2.4) - 0.055
If any channel lands outside 0–255 the color is out of sRGB gamut; it is clamped and flagged.
Example
lab(55.6% 17.6 -64.4) converts back to approximately rgb(59, 130, 246) → #3B82F6.
Notes
The D65 white point is assumed, matching sRGB and CSS lab(). Out-of-gamut colors are clamped into range and marked, since a monitor cannot display them exactly. All math runs in your browser — nothing is uploaded.