StringMash.com

OKLCH to hex converter

oklch() to a hex code, with out-of-gamut colours mapped as CSS does.

Conversion
19 characters
Updates as you type
OKLCHoklch(65% 0.15 270)
GamutInside sRGB
Hex#6C88EA
RGBrgb(108, 136, 234)
HSLhsl(227, 75%, 67%)
HSV (HSB)hsv(227, 54%, 92%)
CMYKcmyk(54%, 42%, 0%, 8%)
Nearest CSS namecornflowerblue
Contrast with white3.31:1 (AA large text only)
Contrast with black6.35:1 (AA)
The swatch and working are below

Show the steps
Aa blackAa white
  1. Lightness L = 0.65, chroma C = 0.15, hue H = 270°.
  2. Turn chroma and hue into Oklab: a = C × cos H = 0, b = C × sin H = −0.15.
  3. Ottosson's inverse matrix and cubing give l, m and s, and a third matrix turns those into linear red, green and blue: 0.1501, 0.245, 0.8228.
  4. Put the sRGB gamma back (12.92 × c for small values, 1.055 × c^(1/2.4) − 0.055 above 0.0031308): 0.4237, 0.5321, 0.9177.
  5. All three are between 0 and 1, so the colour fits in sRGB and needs no mapping.
  6. Multiply by 255 and round: rgb(108, 136, 234), which is #6C88EA.

Using the converter

Paste an oklch() value, such as oklch(65% 0.15 270), or type the three numbers with the lightness first. Lightness can be a percentage or 0 to 1, chroma a number or a percentage of 0.4, and the hue can use deg, turn, rad or grad. An alpha after a slash adds a fourth pair to the hex code.

The Gamut row says whether the colour fits in sRGB, the colours a hex code can hold. If it doesn't, the hex code is the nearest one CSS would choose, and the clipped version is shown for comparison.

From OKLCH to hex

Turn chroma and hue back into Oklab: a = C × cos h and b = C × sin h. Ottosson's inverse matrix gives l, m and s, which are cubed, and a third matrix turns them into linear red, green and blue.

Put the gamma back: a value up to 0.0031308 becomes 12.92 × c, and a larger one 1.055 × c^(1/2.4) − 0.055. If all three are between 0 and 1, multiply by 255, round and write them in hex.

A worked example

For oklch(65% 0.15 270), L = 0.65, a = 0.15 × cos 270° = 0 and b = 0.15 × sin 270° = −0.15. The matrices give linear values of 0.1501, 0.245 and 0.8228, and with the gamma back that's 0.4237, 0.5321 and 0.9177.

All three fit, so times 255 and rounded they are 108, 136 and 234, which is #6C88EA.

Colours outside sRGB

OKLCH can describe colours no hex code can hold. oklch(65% 0.25 270) is the same blue with more chroma, and it comes out as red 0.3475, green 0.4707 and blue 1.146. Blue is over 1, so it is outside sRGB.

Clipping each channel to 0 to 1 gives #5978FF, but clipping can shift the hue and lightness a lot. CSS Color 4 instead keeps the lightness and hue and lowers the chroma, halving the gap each time, until clipping moves the colour by less than 0.02 in Oklab, a just-noticeable difference. Here the chroma ends near 0.209 and the hex code is #6080FF.

A hue wheel at oklch(70% 0.15 …)

Same lightness and chroma at every hue. A few hues don't quite fit in sRGB at this chroma.
HueHexGamut
0#E7729BInside sRGB
30#ED7665Inside sRGB
60#E18528Inside sRGB
90#C39900Just outside sRGB, clipped
120#93AB2CInside sRGB
150#4CB86AInside sRGB
180#00BBA2Outside sRGB, chroma 0.15 mapped to 0.1474
210#00B5CEOutside sRGB, chroma 0.15 mapped to 0.1406
240#26A9F1Inside sRGB
270#7A97FBInside sRGB
300#AD87EDInside sRGB
330#D179CAInside sRGB

A blue lightness ladder at oklch(… 0.1 250)

Very dark and very light colours can't hold much chroma, so the ends of the ladder are mapped.
LightnessHexGamut
20%#00143EOutside sRGB, chroma 0.1 mapped to 0.0949
30%#002E5DJust outside sRGB, clipped
40%#124A7BInside sRGB
50%#32669AInside sRGB
60%#4F84BAInside sRGB
70%#6DA3DAInside sRGB
80%#8CC3FCInside sRGB
90%#BAE3FFOutside sRGB, chroma 0.1 mapped to 0.0725

Why OKLCH

OKLCH is built on Oklab, which Björn Ottosson published in December 2020 to predict how light, how colourful and what hue a colour looks. Equal steps in its lightness look like equal steps to the eye, which HSL does not manage.

In HSL, pure yellow #FFFF00 and pure blue #0000FF both have 50% lightness, though the yellow looks far brighter. In OKLCH the yellow is 96.8% and the blue 45.2%. That is why design systems use oklch() to build palettes where every colour at the same lightness has the same contrast with text.

Questions

Why does my browser show a different colour from this hex code?

On a wide-gamut screen a browser can show some oklch() colours outside sRGB directly. The hex code is the closest sRGB colour, the one to use as a fallback.

What happens at lightness 0% or 100%?

CSS Color 4 makes 100% white and 0% black whatever the chroma and hue, and this page does the same.

Is out-of-gamut mapping the same in every tool?

No. Some tools only clip, and some use other methods, so their hex codes can differ by a few steps for colours outside sRGB. This page follows the CSS Color 4 method.

Sources

Added and reviewed . What's new