Converting OKLCH to HEX
To convert an OKLCH color to a HEX code, simply enter your OKLCH value into the converter above. The tool will instantly parse the cylindrical coordinates and output the standard 6-character (or 8-character) base-16 string.
If you are writing this conversion in code, the process requires translating a modern, wide-gamut color space into the standard, sRGB-bound format used by legacy web browsers.
The Gamut Clipping Problem
OKLCH is capable of describing any color the human eye can see, including the ultra-vibrant colors found on modern Display P3 monitors. HEX codes, however, are strictly tied to the older, smaller sRGB color space.
If you try to convert a highly vibrant OKLCH color (one with a high Chroma value) into HEX, it physically cannot be represented. During the conversion process, the algorithm must "clamp" or map the color to the closest available sRGB value. As a result, the final HEX code will look slightly duller than the original OKLCH color.
The Conversion Pipeline
To get from OKLCH to HEX programmatically, the color must pass through several intermediate spaces:
- OKLCH to OKLab: Trigonometry converts the Chroma and Hue angle into Cartesian
aandbcoordinates. - OKLab to Linear RGB: The values are multiplied by an inverse matrix to convert them from LMS cone space back into linear red, green, and blue light.
- Gamma Correction: The linear RGB values are passed through the sRGB gamma curve to match how monitors display light.
- RGB to HEX: The final RGB decimals (0-255) are converted into base-16 hexadecimal strings and combined.