Skip to content
Hex Calculator

Hex to OKLab Converter

Convert a hex color into OKLab's lightness and a/b axes — the Cartesian, perceptually uniform space used for linear color blending.

OKLab result
oklab(54.6% -0.0267 -0.2135)
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.

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

Further reading: CSS Colors — W3Schools

How Hex to OKLab Conversion Works

Hex converts to OKLab by first decoding to linear-light RGB (undoing the sRGB gamma curve), then applying the Oklab matrix transform, which produces a lightness value plus two opponent-color axes: a (green-red) and b (blue-yellow). Unlike OKLCH's polar chroma and hue, OKLab's a/b coordinates are Cartesian, which makes it the preferred space for linear operations like blending or interpolating between two colors.

Hex to OKLab Example, Step by Step

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

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

#2563EB -> rgb(37, 99, 235) -> linear RGB

Apply Oklab matrix transform:
L = 0.546
a = -0.0267
b = -0.2135
StepDescriptionResult
Convert hex to linear RGBundo sRGB gamma encodinglinear R, G, B
Apply the LMS cone-response matrixmap linear RGB to the LMS spaceL, M, S values
Apply the Oklab matrixmap LMS to lightness and a/b axesL=54.6%, a=-0.0267, b=-0.2135

A negative b value here means this color leans toward blue on the blue-yellow axis, matching the visibly blue hue of #2563EB.

Where Hex to OKLab Actually Comes Up

Building a Perceptually Smooth Gradient

Converting two brand hex colors to OKLab before interpolating between them produces a gradient that looks smooth and natural, avoiding the dull midpoint RGB gradients often produce.

hex A + hex B -> OKLab blend path

Generating an Accessible Tint/Shade Scale

Design systems that programmatically generate lighter and darker variants of a base color use OKLab's lightness axis to keep perceived brightness steps consistent.

base hex -> OKLab tint/shade scale

Implementing Modern CSS color-mix()

CSS's color-mix() function can blend in OKLab space directly — converting your existing hex palette to OKLab helps you understand and predict how those blends will look.

hex palette -> OKLab for color-mix()

Common Mistakes With Hex to OKLab

  • Confusing OKLab's a/b axes with OKLCH's chroma/hue — they describe the same point in space but aren't interchangeable numbers.
  • Assuming a and b are bounded to a fixed range — like chroma in OKLCH, they're open-ended and typically stay within roughly -0.4 to 0.4 for sRGB colors.
  • Using OKLab values directly as CSS — browsers expect the oklab() function syntax, not raw comma-separated numbers.

Why Use This Calculator Instead of Doing the Math Yourself

  • Handles the full matrix transform and gamma decoding for you
  • Runs entirely in your browser — nothing you type gets sent anywhere
  • Round-trips exactly with the OKLab to Hex converter
  • Saves you from implementing the LMS cone-response math by hand

Limitations

  • Computed from sRGB — the conversion assumes standard sRGB input and doesn't account for a wide-gamut source profile.

Frequently Asked Questions

What is OKLab?

OKLab is a perceptually uniform color space with three axes: L (lightness), a (green-red axis), and b (blue-yellow axis). It's the Cartesian form that OKLCH's chroma and hue are derived from.

What's the OKLab value of #2563EB?

oklab(54.6% -0.0267 -0.2135) — a negative b value places it toward blue, and a slightly negative a value leans just past neutral toward green.

How is OKLab different from OKLCH?

They describe the same space with different coordinates — OKLCH uses polar chroma and hue (easier to reason about as 'how saturated' and 'what hue'), while OKLab uses Cartesian a and b axes (easier to use in math like linear interpolation between two colors).

Why is OKLab better for blending colors than RGB or HSL?

Linearly interpolating between two RGB or HSL colors often passes through a dull, muddy midpoint. Because OKLab's axes are perceptually uniform, a straight-line blend between two OKLab colors looks like a smooth, natural transition instead.

Is this conversion exact?

Yes — converting the resulting OKLab value back to hex reproduces the original color exactly, aside from floating-point rounding.

How do I build a perceptually smooth gradient between two brand colors?

Convert both endpoint hex colors to OKLab, interpolate the L, a, and b values linearly at each step, then convert each interpolated point back to hex — this avoids the muddy midpoint that RGB or HSL interpolation often produces.

Why would a design system store colors in OKLab instead of just hex?

OKLab makes it possible to generate accessible, evenly-spaced tint and shade scales programmatically, since equal steps in L correspond to roughly equal perceived brightness changes — something hex/RGB can't guarantee.