Hex to OKLCH converter: lightness, chroma and hue from a hex code

By TechCompare · Updated · How we check

#8B5CF6 is oklch(60.56% 0.2189 292.72) in CSS, and you can paste that text into a stylesheet unchanged. It names the same color as the hex code, to within the rounding in the text.

  • OKLCHoklch(60.56% 0.2189 292.72)
  • RGBrgb(139, 92, 246)
  • HSLhsl(258, 90%, 66%)
  • CMYKcmyk(43%, 63%, 0%, 4%)

OKLCH splits a color into three parts: lightness, chroma and hue. Lightness is how light the color looks to a person, chroma is how strong the color is, and hue is its position on the color wheel. Hex and RGB describe the same color without those parts, so the converter above works the three numbers out from the sRGB values in your hex code.

Conversion
HEX to OKLCH
Example: #8B5CF6
Category
Modern Formats
Color knowledge base

How this is calculated

The hex code gives sRGB values, and the converter turns each channel into linear light. A matrix then gives approximate cone responses, each response goes through a cube root, and a second matrix turns the result into L, a and b. Chroma is the length of the (a, b) pair and hue is its angle, so OKLCH is the same space in polar form. Björn Ottosson designed Oklab to be simple to use while still predicting perceived lightness, chroma and hue well. You don't need the matrix numbers, since the converter does that work.

Lightness is where OKLCH and HSL disagree. HSL gives pure yellow 50% lightness and pure blue 50%, but OKLCH gives 96.8% and 45.2%. Yellow is the lighter of the two in OKLCH. MDN calls the L in oklch() the perceived lightness, which is different from the L in hsl(), where it represents lightness as compared to other colors.

A gray has chroma 0, and the converter writes its hue as 0 too, since a gray has no real hue. Mid gray is oklch(59.99% 0 0) and white is oklch(100% 0 0). In CSS, chroma can be a number or a percent, and 100% equals 0.4. MDN says chroma has no fixed top, but in practice it doesn't exceed 0.5. The converter rounds lightness and hue to two decimals and chroma to four. That's just enough for the oklch() text to give back every hex code within one step per channel, but the hex code stays the exact source.

Verdict

To make a lighter or darker variant, change the lightness and keep chroma and hue the same, then check the result in a browser. This converter reads hex, RGB, HSL and CMYK but not OKLCH. To get a hex code back from an OKLCH value, type it into the OKLCH fields of the Color Picker. A variant can also land outside sRGB, so read OKLCH in CSS before you ship a wide-gamut palette.

More Color scenarios

Hex to RGB
A hex color code is three RGB numbers written in base 16.
View details
RGB vs CMYK
Screens add light and print adds ink. See one color in both, and why a plain CMYK formula can't promise a print match.
View details
HSL color model
Hue, saturation and lightness, with three live sliders and a table of common colors in hex, RGB and HSL.
View details

Frequently asked questions

Is oklch() supported in browsers?
Yes. MDN says oklch() has been available across browsers since May 2023, and it lists the feature as widely available.
What are the OKLCH ranges?
Lightness runs from 0 to 1, or 0% to 100%. Chroma starts at 0 and has no fixed top, though MDN says it doesn't exceed 0.5 in practice. A chroma of 100% equals 0.4. Hue is a number or an angle, usually from 0 to 360 degrees.
Why is chroma 0 for gray, and what hue does gray have?
Chroma is the length of the a and b pair. A gray comes out with a and b at zero, so its chroma is 0. The converter writes hue as 0, but a gray has no real hue. At zero chroma every hue gives the same gray, so that 0 is only a placeholder.
Is OKLCH the same as LCH?
No. OKLCH is the polar form of Oklab, and LCH is the polar form of CIELAB, so they're different color spaces. MDN's oklch() page notes that hue angles differ between sRGB, CIELAB and Oklab, so the same hue number can point to different colors in each.