Skip to content
Hex Calculator

OKLab to Hex Converter

Convert an OKLab lightness and a/b coordinate pair back into a 6-digit hex color code, with exact round-trip accuracy for design tokens.

Hex result
#2563EB
Swapnil Sanghvi

Built by

Swapnil Sanghvi

Full-Stack Web Developer & WordPress Developer

Swapnil Sanghvi is a full-stack web and WordPress developer, UI designer, and full-time freelancer who builds and maintains Hex Calculator.

OKLab to Hex Converter tool preview card from Hex Calculator
Share preview: this is the card that appears when you share the OKLab to Hex Converter page on social media.

Further reading: CSS Colors — W3Schools

How OKLab to Hex Conversion Works

The lightness and a/b coordinates run through the inverse of the Oklab matrix transform to produce linear-light RGB. That linear RGB is then gamma-encoded into standard sRGB and rounded to 0-255 integer channels, which convert to hex the same way any RGB to hex conversion works.

OKLab to Hex Example, Step by Step

oklab(54.6% -0.0267 -0.2135) = #2563EB

oklab(54.6% -0.0267 -0.2135) = #2563EB

Oklab(0.546, -0.0267, -0.2135)
-> inverse Oklab matrix -> LMS
-> inverse LMS matrix -> linear RGB
-> sRGB gamma encoding

Round to bytes: R=37, G=99, B=235 -> #2563EB
StepDescriptionResult
Apply the inverse Oklab matrixmap L, a, b back to LMSL, M, S values
Apply the inverse LMS matrixmap LMS back to linear RGBlinear R, G, B
Apply sRGB gamma encodingconvert linear values to standard sRGBR=37, G=99, B=235
Convert to hexround and pair each channel#2563EB

This exactly reverses the hex-to-OKLab example — the two conversions are precise inverses of each other for in-gamut colors.

Where OKLab to Hex Actually Comes Up

Producing a Hex Fallback for color-mix()

Browsers or tools that don't support modern CSS color functions still need a static hex value — converting a computed OKLab blend here gives you that fallback.

OKLab blend -> hex fallback

Generating Gradient Stops From a Color Scale

A perceptually even color scale computed in OKLab needs its stops converted to hex before it can be used as a standard CSS gradient or in tools without OKLab support.

OKLab scale points -> gradient hex stops

Exporting a Design Tool's OKLab Palette

Design tools that generate palettes internally in OKLab for perceptual consistency need this conversion to hand off exact hex values to developers.

OKLab palette -> hex for handoff

Common Mistakes With OKLab to Hex

  • Entering a or b as percentages — they're signed decimals, typically roughly -0.4 to 0.4, not 0-100% values.
  • Expecting every L/a/b combination to map to a valid hex — some fall outside what sRGB can display and get clamped.
  • Mixing up a and b — a is the green-red axis, b is the blue-yellow axis; swapping them produces a completely different hue.

Why Use This Calculator Instead of Doing the Math Yourself

  • Handles the full inverse matrix transform and gamma encoding for you
  • Runs entirely in your browser — nothing you type gets sent anywhere
  • Clamps out-of-gamut colors to valid RGB instead of producing garbage
  • Round-trips exactly with the Hex to OKLab converter

Limitations

  • Converts back to sRGB — out-of-gamut OKLab values get clamped to the nearest displayable sRGB color rather than rejected.

Frequently Asked Questions

How do you convert OKLab to hex?

Run the Oklab matrix transform in reverse to get linear-light RGB from the L, a, and b values, then apply sRGB gamma encoding and round each channel to a 0-255 integer before converting to hex.

What format does this tool accept for OKLab input?

Either plain space-separated values (54.6% -0.0267 -0.2135) or a full oklab() function string (oklab(54.6% -0.0267 -0.2135)) — both work the same.

Does OKLab to hex round-trip exactly?

Yes — oklab(54.6% -0.0267 -0.2135) converts back to exactly #2563EB, matching the original hex value it came from with no drift.

What happens with an OKLab color outside the sRGB gamut?

Some L/a/b combinations represent colors no sRGB screen can display. This tool clamps the output to the nearest valid 0-255 RGB channel values rather than producing an invalid hex code.

Can a and b be positive or negative?

Yes — both axes are signed. Positive a leans red, negative a leans green; positive b leans yellow, negative b leans blue.

How do I get a hex fallback for a CSS color-mix() result?

Compute the blended OKLab value (either by hand or from a tool that does linear interpolation in OKLab), then convert it here to get a static hex fallback for browsers or contexts that need one.

I generated a color scale in OKLab — how do I get the hex stops?

Convert each L/a/b point along your scale here to build the corresponding hex stops for a CSS gradient or design token list, preserving the perceptually even spacing OKLab gives you.