Hex to OKLCH Converter
Convert sRGB hex codes to CSS oklch(), generate Tailwind v4 @theme tokens
and custom-property @supports fallbacks, and check Display P3 gamut limits.
mid vivid blue
sRGB fallback #4F46E5 · Nearest CSS name slateblue · ΔE₀₀ 6.86
Fallback #4F46E5 · rgb(79, 70, 229)
Gamut & fallback status
In sRGB & Display P3Safe on all screens. Uses 82.7% of sRGB chroma headroom (max 0.2782 at L 51.06%, H 276.97; Display P3 extends up to 0.2974).
OKLCH & fallback values
Click any value to copy| Format | Value | Notes |
|---|---|---|
| OKLCH (primary) | Selected CSS Color 4 syntax ready to copy. | |
| OKLCH (alt syntax) | Equivalent CSS Color 4 notation using the other lightness unit. | |
| sRGB hex fallback | Chroma-mapped inside sRGB at constant lightness and hue. | |
| Display P3 | Clamped wide-gamut color(display-p3 r g b) representation. | |
| RGB (sRGB) | Resolved 0-255 sRGB channel values. |
Channel breakdown
82.7% of sRGB chroma ceiling| Channel | Value | Meaning |
|---|---|---|
| L (Lightness) | 51.06% (decimal 0.5106) |
Perceived brightness from 0% black to 100% white. |
| C (Chroma) | 0.23005 |
82.7% of 0.2782 sRGB ceiling (0.2974 in Display P3). |
| H (Hue) | 276.97 deg |
Perceptual angle on the OKLab wheel (0 pink/red, 145 green, 270 blue). |
Tailwind v4 & CSS @supports snippets
Token--color-brand
CSS variable + @supports fallback
Required when defining CSS variables: guards the OKLCH value so older browsers keep the hex fallback.
:root {
--color-brand: #4F46E5;
}
@supports (color: oklch(0% 0 0)) {
:root {
--color-brand: oklch(51.06% 0.23005 276.97);
}
}
Tailwind CSS v4 (@theme)
Generates bg-brand, text-brand, and border-brand utilities natively in Tailwind v4.
@import "tailwindcss";
@theme {
--color-brand: oklch(51.06% 0.23005 276.97);
}
Tailwind v3 (tailwind.config.js)
Maps Tailwind v3 utilities to the @supports CSS custom property above.
module.exports = {
theme: {
extend: {
colors: {
"brand": "var(--color-brand, #4F46E5)",
},
},
},
};
Direct CSS cascade fallback
Simple CSS properties ignore unknown color functions without needing @supports.
.swatch-brand {
background-color: #4F46E5;
background-color: oklch(51.06% 0.23005 276.97);
}
How Hex to OKLCH conversion works
Converting #RRGGBB hex to oklch(L C H) reverses the sRGB gamma
curve into linear RGB, maps linear channels through D65 cone-response matrices into
Bjorn Ottosson's OKLab space, and converts cartesian coordinates (a, b) into
perceptual Chroma C and Hue angle H.
Unlike HSL, where blue at 50% lightness looks far darker than yellow at 50% lightness,
two OKLCH tokens sharing the same Lightness L hold closely matched visual
weight across hues. That makes OKLCH ideal for automated Tailwind color scales and hover
states.
Why CSS custom properties still need @supports
On a regular property such as color: #4F46E5; color: oklch(...), any older
browser ignores the second declaration at parse time. CSS variables behave differently:
parsers accept --color-brand: oklch(...) unconditionally because custom
property syntax allows arbitrary tokens, then turn the element invalid (IACVT) when
var(--color-brand) resolves. Guarding the override inside
@supports (color: oklch(0% 0 0)) keeps legacy engines on your safe hex
fallback.
Upgrading Tailwind v3 hex tokens to Tailwind v4
Tailwind v4 switched its entire default palette to OKLCH inside @theme
blocks using 0..1 decimal lightness (for instance oklch(0.5106 0.23005 276.97)).
Toggle Decimal in the controls above, type your token name (such as
primary or surface), and paste the generated @theme
rule straight into your CSS entrypoint.
Checking Display P3 vs sRGB gamut limits
Raising Chroma C in OKLCH pushes saturated greens, cyans, and reds beyond
what #RRGGBB hex can represent. Paste any oklch(...) string
above to see whether it fits inside sRGB, sits in wide-gamut Display P3, or exceeds
both. When a value overflows sRGB, the tool walks chroma down at constant Lightness and
Hue to give you a faithful hex fallback.
Common questions
Why do CSS custom properties need @supports (color: oklch(0% 0 0))?
Unlike normal properties such as background-color, browsers cannot discard an unsupported oklch() inside a --var declaration at parse time. Older browsers treat the whole custom property as valid until var() resolves and fail silently. Wrapping the OKLCH override inside @supports keeps your hex fallback working everywhere.
Should I write oklch(51% ...) or oklch(0.51 ...) in Tailwind v4?
Both represent the exact same CSS Color 4 value. Tailwind v4's built-in palette tokens use 0..1 decimals (like oklch(0.511 0.262 277)), while many design tools and CSS references write percentage lightness (51.1%). Switch the toggle above to match your codebase convention.
What happens when an OKLCH color sits outside the sRGB gamut?
Wide-gamut screens such as Apple Display P3 panels render high-chroma OKLCH hues beyond #RRGGBB, while standard sRGB monitors clip or desaturate them. This converter computes the exact chroma-reduced sRGB hex at constant Lightness and Hue so fallback colors never shift hue unexpectedly.