Xerobit

Hex to OKLCH Converter

Enter a hex color code to get the equivalent OKLCH value formatted as a CSS oklch() function, along with OKLab and sRGB coordinates. The conversion follows the exact sRGB to linear to OKLab pipeline defined by Bjorn Ottosson. This hex to oklch converter runs entirely in your browser, so no data is uploaded anywhere.

Result

  • OKLCH (CSS)
    oklch(62.3% 0.188 259.8)
  • OKLab
    oklab(62.3% -0.0332 -0.1851)
  • sRGB
    rgb(59, 130, 246)
  • Alpha
    100%

    opaque (no alpha digits)

By · Published · How we build and test tools

How to use the hex to oklch converter

  1. Type or paste a hex color code into the input field. You can include the # prefix or leave it out.
  2. The converter immediately calculates the sRGB to OKLCH transformation using the standard matrices.
  3. Copy the oklch() CSS string directly into your stylesheet. A 4 or 8 digit hex adds the alpha as / 50.2% style syntax.
  4. Review the OKLab and sRGB rows for the full set of color coordinates.

How the sRGB to OKLCH conversion works

The hex to oklch conversion follows three mathematical stages defined by Bjorn Ottosson. First, the 8-bit sRGB channels are normalized to the 0-1 range and linearized by removing the gamma curve. Each channel uses the formula: if the value is at most 0.04045, divide by 12.92; otherwise compute ((value + 0.055) / 1.055) raised to the power of 2.4.

Second, the linear RGB values are multiplied by a 3x3 matrix to produce LMS cone responses, then each response is cube-rooted, and a second matrix yields the OKLab L, a and b coordinates. Finally, chroma is calculated as the square root of a squared plus b squared, and hue is the arctangent of b over a converted to degrees.

For example, converting #3b82f6: the sRGB values 59, 130, 246 become linear 0.0437, 0.2232, 0.9216. After both matrix multiplications and the cube root step, the OKLab result is approximately L = 0.623, a = -0.033, b = -0.185. Chroma becomes 0.188 and hue computes to about 259.8 degrees, so the tool prints oklch(62.3% 0.188 259.8).

Using OKLCH in CSS

Modern browsers support the oklch() color function natively. The syntax is oklch(L% C H) where L is lightness from 0 to 100 percent, C is chroma (typically 0 to 0.4 for sRGB colors), and H is hue in degrees from 0 to 360. For achromatic colors like pure white or black, chroma is zero and the hue angle has no visual effect, but this converter outputs 0 for consistency.

This hex to oklch css output can be pasted directly into any property that accepts a color value, such as color, background-color or border-color. Because OKLCH is perceptually uniform, adjusting the lightness percentage produces visually even steps, which is harder to achieve in sRGB or HSL.

If you enter a 4 or 8 digit hex code, the alpha channel is carried over with the CSS slash syntax. For example, #ff000080 gives oklch(62.8% 0.258 29.2 / 50.2%), because hex 80 is 128 out of 255.

Common hex to OKLCH reference values

The table below shows pre-computed conversions for frequently used colors. Values are rounded to match the output format of this tool.

HexOKLCHsRGB
#ffffffoklch(100.0% 0.000 0)rgb(255, 255, 255)
#000000oklch(0.0% 0.000 0)rgb(0, 0, 0)
#ff0000oklch(62.8% 0.258 29.2)rgb(255, 0, 0)
#00ff00oklch(86.6% 0.295 142.5)rgb(0, 255, 0)
#0000ffoklch(45.2% 0.313 264.1)rgb(0, 0, 255)
#808080oklch(60.0% 0.000 0)rgb(128, 128, 128)

Why use OKLCH instead of other color spaces

OKLCH was designed to be perceptually uniform, meaning that a numerical change of the same size produces a similar visual difference regardless of where you are in the color space. This makes it far more predictable than HSL when building design systems or generating color palettes programmatically.

If you need to convert between other formats, tools like hex to rgb or rgb to hex handle the legacy sRGB space. For print workflows, hex to cmyk provides the subtractive equivalents. But for on-screen work in modern CSS, the sRGB to OKLCH path gives you the widest gamut representation that browsers currently support.

Handling edge cases and gamut limits

Not every OKLCH value maps back to a valid sRGB color. When converting hex to oklch, the source color is always within the sRGB gamut, so the resulting OKLCH coordinates are safe. However, if you manually edit the chroma or hue in CSS, you may exceed what sRGB displays can reproduce. Browsers will typically gamut-map the color, but the visual result may differ from your expectation.

Achromatic colors (grays, pure white, pure black) have a chroma of exactly zero. In these cases the hue angle is mathematically undefined because the arctangent of 0 divided by 0 has no unique solution. This converter sets the hue to 0 degrees for all achromatic results to keep the CSS string valid and deterministic.

Worked examples

ExampleInputResult
BlueHex color: #3b82f6OKLCH (CSS): oklch(62.3% 0.188 259.8); OKLab: oklab(62.3% -0.0332 -0.1851); sRGB: rgb(59, 130, 246); Alpha: 100%
WhiteHex color: #ffffffOKLCH (CSS): oklch(100.0% 0.000 0); OKLab: oklab(100.0% 0.0000 0.0000); sRGB: rgb(255, 255, 255); Alpha: 100%
BlackHex color: 000000OKLCH (CSS): oklch(0.0% 0.000 0); OKLab: oklab(0.0% 0.0000 0.0000); sRGB: rgb(0, 0, 0); Alpha: 100%
Short redHex color: f00OKLCH (CSS): oklch(62.8% 0.258 29.2); OKLab: oklab(62.8% 0.2249 0.1258); sRGB: rgb(255, 0, 0); Alpha: 100%
With alphaHex color: #ff000080OKLCH (CSS): oklch(62.8% 0.258 29.2 / 50.2%); OKLab: oklab(62.8% 0.2249 0.1258 / 50.2%); sRGB: rgb(255 0 0 / 50.2%); Alpha: 50.2%

FAQ

What is the oklch() CSS function?

The oklch() function defines a color using lightness (as a percentage), chroma (a decimal number) and hue (an angle in degrees). It is supported in all major browsers and provides perceptually uniform color manipulation.

Can I use a short hex code like #abc?

Yes. The converter accepts 3-digit, 4-digit, 6-digit and 8-digit hex codes, with or without the leading hash symbol. Short codes are expanded automatically, so #abc becomes #aabbcc. The 4 and 8 digit forms carry an alpha value, which appears after a slash in the oklch() output.

Why is the hue 0 for white and black?

When chroma is zero the color is achromatic and the hue angle is mathematically undefined. This tool outputs 0 degrees to produce a valid CSS oklch() string.

Is OKLCH better than HSL for web design?

OKLCH is perceptually uniform, so equal numeric changes produce equal visual changes. HSL does not have this property, which makes OKLCH more reliable for building consistent color scales.

Does this tool upload my color values?

No. The entire hex to oklch conversion runs locally in your browser using JavaScript. Nothing is sent to any server.

What matrices are used for the conversion?

The conversion uses the two 3x3 matrices published by Bjorn Ottosson: one to transform linear sRGB to LMS cone responses, and another to transform cube-rooted LMS values to OKLab coordinates.