StringMash.com

Hex to OKLCH converter

Hex codes to oklch() lightness, chroma and hue, with the working.

Conversion
7 characters
Updates as you type
OKLCHoklch(74.42% 0.18117 56.46)
Oklaboklab(74.42% 0.1001 0.151)
Hex#FF8800
RGBrgb(255, 136, 0)
HSLhsl(32, 100%, 50%)
HSV (HSB)hsv(32, 100%, 100%)
CMYKcmyk(0%, 47%, 100%, 0%)
Nearest CSS namedarkorange
Contrast with white2.39:1 (fails)
Contrast with black8.77:1 (AAA)
The swatch and working are below

Show the steps
Aa blackAa white
  1. #FF8800 is rgb(255, 136, 0). Divide by 255: 1, 0.5333, 0.
  2. Undo the sRGB gamma to get linear light. Values up to 0.04045 are divided by 12.92, larger ones become ((c + 0.055) ÷ 1.055)^2.4: 1, 0.2462, 0.
  3. Mix them into the cone-like responses l, m and s with Ottosson's first matrix, for example l = 0.4122 × R + 0.5363 × G + 0.0514 × B: l = 0.5443, m = 0.3795, s = 0.1577.
  4. Take the cube root of each: 0.8165, 0.724, 0.5402.
  5. The second matrix gives Oklab: L = 0.7442, a = 0.1001, b = 0.151. L is lightness, a runs green to red and b runs blue to yellow.
  6. Chroma is the distance from grey, C = √(a² + b²) = 0.1812. Hue is the angle, atan2(b, a) = 56.46°.
  7. Together, with lightness as a percentage: oklch(74.42% 0.18117 56.46).

Using the converter

Paste a hex code such as #FF8800. The answer is an oklch() value you can paste into CSS, with the lightness as a percentage, then the chroma, then the hue in degrees.

rgb(), hsl() and colour names work too. The chroma has five decimal places so that converting back gives exactly the same hex code, which this page checks for every one of the 16,777,216 six-digit codes.

From hex to OKLCH

Split the hex code into red, green and blue and divide each by 255. Undo the sRGB gamma: a value c up to 0.04045 becomes c ÷ 12.92, and a larger one becomes ((c + 0.055) ÷ 1.055)^2.4. This gives linear light.

Ottosson's first matrix mixes the three into l, m and s, roughly the responses of the eye's three kinds of cone. Take the cube root of each, then a second matrix gives Oklab: L for lightness, a from green to red, b from blue to yellow. OKLCH is the same thing in polar form. Chroma C = √(a² + b²), and hue h = atan2(b, a) in degrees.

A worked example

#FF8800 is rgb(255, 136, 0), or 1, 0.5333 and 0. Undoing the gamma gives 1, 0.2462 and 0. The first matrix gives l = 0.5443, m = 0.3795 and s = 0.1577, and their cube roots are 0.8165, 0.724 and 0.5402.

The second matrix turns those into L = 0.7442, a = 0.1001 and b = 0.151. Chroma is √(0.1001² + 0.151²) = 0.1812, and the hue is atan2(0.151, 0.1001) = 56.46°. The result is oklch(74.42% 0.18117 56.46).

Common colours in OKLCH

Greys have no chroma, so their hue is written as 0.
ColourHexOKLCH
Red#FF0000oklch(62.8% 0.25768 29.23)
Orange#FFA500oklch(79.27% 0.17103 70.67)
Yellow#FFFF00oklch(96.8% 0.21101 109.77)
Lime#00FF00oklch(86.64% 0.29483 142.5)
Green#008000oklch(51.98% 0.17686 142.5)
Cyan#00FFFFoklch(90.54% 0.15455 194.77)
Blue#0000FFoklch(45.2% 0.31321 264.05)
Navy#000080oklch(27.11% 0.18789 264.05)
Purple#800080oklch(42.09% 0.19345 328.36)
Magenta#FF00FFoklch(70.17% 0.32249 328.36)
Pink#FFC0CBoklch(86.77% 0.07354 7.09)
Brown#A52A2Aoklch(48.06% 0.15966 25.56)
White#FFFFFFoklch(100% 0 0)
Silver#C0C0C0oklch(80.78% 0 0)
Grey#808080oklch(59.99% 0 0)
Black#000000oklch(0% 0 0)

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.

Reading the three numbers

Lightness runs from 0% for black to 100% for white. Chroma starts at 0 for a grey and has no fixed top. In sRGB it reaches about 0.32, for magenta, and CSS treats 0.4 as 100%. Hue is an angle, with pinks near 0°, reds near 30°, yellows near 110°, greens near 140°, cyans near 195° and blues near 265°.

The hue angles are not the same as in HSL. Red is 0° in HSL but 29° in OKLCH, and blue is 240° in HSL but 264° in OKLCH.

Questions

Do all browsers support oklch()?

oklch() is part of CSS Color Level 4, and current versions of the main browsers support it. Keep a hex fallback before it for older ones.

Why five decimal places for chroma?

With four, a few hundred bright colours with one channel near 0 come back one step off. With five, every hex code converts back exactly.

What is the difference between Oklab and OKLCH?

They are the same colours. Oklab uses a and b on two axes, and OKLCH turns them into a distance (chroma) and an angle (hue), as HSL does for RGB.

Sources

Added and reviewed . What's new