
The Math Behind Converting OKLCH to RGB
A deep dive into the mathematics behind converting the OKLCH color model to RGB, featuring an interactive conversion tool.
Introduction
As support for the OKLCH color model grows, so does the need to understand how it relates to the ubiquitous RGB model. While OKLCH offers superior perceptual uniformity and access to wide-gamut colors, our screens (mostly) still work with RGB subpixels.
In this article, we'll explore the mathematical journey of converting an OKLCH color into the standard sRGB space used by most web devices.
The Interactive Converter
Before we dive into the math, try out the conversion process yourself! Adjust the Lightness, Chroma, and Hue sliders below to see how they map to an RGB Hex code.
The Conversion Pipeline
Converting OKLCH to RGB isn't a single step; it involves a series of transformations across different color spaces.
Step 1: OKLCH to OKLab
First, we need to convert the cylindrical OKLCH coordinates (Lightness, Chroma, Hue) back to the Cartesian OKLab coordinates (L, a, b).
- L remains the same.
- a (green-red) is calculated using cosine:
- b (blue-yellow) is calculated using sine:
(Note: Ensure H is in radians for these calculations.)
Step 2: OKLab to Linear RGB
Next, we move from the perceptual OKLab space to a "Linear" RGB space. This transformation happens in three sub-steps:
2.1 OKLab to LMS (Cone Response)
We first transform L, a, b coordinates into an intermediate LMS domain using a specific matrix:
2.2 LMS Non-Linearity
The OKLab model uses a cube root non-linearity. To get back to linear light intensity, we must cube the resulting LMS values:
2.3 LMS to Linear RGB
Finally, we convert these linear LMS values to Linear RGB using another matrix transformation:
Step 3: Linear RGB to sRGB (Gamma Correction)
Finally, most screens require "Gamma Corrected" signals. This is because human eyes are more sensitive to dark shades than light ones.
Standard sRGB conversion uses a transfer function:
- If the value is very small (), multiply by 12.92.
- Otherwise, raise it to the power of and apply scaling offsets.
This final step gives us the familiar 0-255 values (after scaling) for Red, Green, and Blue.
Example Calculation
Let's trace oklch(60% 0.15 250) through this pipeline:
-
To OKLab:
-
To Linear RGB (after matrix transform):
-
To sRGB (after Gamma correction):
- Hex:
#2784D5
Conclusion
Understanding these conversions highlights the complexity hidden behind a simple CSS color declaration. While modern browsers handle this automatically, knowing the math gives us a deeper appreciation for the precision of digital color science.
More Posts

Mastering Color with the HSV Model
Understand Hue, Saturation, and Value for more intuitive color selection.

Unlocking Vibrant Colors with OKLCH
Discover how the OKLCH color model provides a modern, perceptually uniform color space that unlocks the full potential of your display.

Understanding the RGB Color Model
A deep dive into how Red, Green, and Blue combine to create colors on your screen.

