← Blog

HEX vs RGB vs HSL vs OKLCH: Which Color Format to Use

They all describe the same colors — #1E90FF, rgb(30 144 255) and hsl(210 100% 56%) are one pixel value three ways. The difference is what each format makes easy, and that decides which one belongs in your codebase.

HEX: the exchange format

Six hex digits, two per channel. Compact, universal, and what every tool exports — but unreadable to humans. Nobody can look at #6d5efc and say 'slightly warmer, please'. Use HEX to store and share colors, not to reason about them.

RGB: the machine format

The same three channels in decimal. Its one unique job in CSS is alpha without a separate property era: rgb(30 144 255 / 0.5). Otherwise it has HEX's problem with more characters.

HSL: readable, but it lies

Hue, saturation, lightness — finally human-shaped. Want it darker? Lower L. The catch: HSL's 'lightness' isn't perceptual. hsl(60 100% 50%) yellow is blindingly bright while hsl(240 100% 50%) blue is dark, yet both claim 50% lightness. Build a palette by holding HSL numbers equal and your yellows will scream while your blues sulk.

OKLCH: what HSL promised

OKLCH keeps the human-shaped controls (lightness, chroma, hue) but measures them perceptually: two colors with the same OKLCH lightness genuinely look equally bright. That's why new design systems generate shade scales in OKLCH — every 500-level color in the palette carries the same visual weight. Browser support has been universal since 2023.

TaskBest format
Storing brand colors in docsHEX
Quick transparency tweakRGB / HEX with alpha
Hand-adjusting one color in devtoolsHSL
Generating scales & design tokensOKLCH
Gradients that don't gray outAny, interpolated in OKLab

The practical setup

Define tokens in OKLCH so the math is honest, let your build output HEX for compatibility, and read any format with a converter when files disagree. Our converter shows all four formats side by side with copy buttons — paste whatever you have, leave with whatever you need.

Sources and further reading