Skip to main content
Home/Blog/What are CSS color formats and which should I use for modern web development?
Web Design

What are CSS color formats and which should I use for modern web development?

Explore the various CSS color formats available including HEX, RGB, RGBA, HSL, HSLA, and modern CSS Color Module features, and learn best practices for color specification in contemporary web development.

By Inventive HQ Team•
What are CSS color formats and which should I use for modern web development?

CSS gives you several practical ways to write a color, and oklch() is useful for deliberately designed palettes. The formats fall into two camps: the sRGB-bound classics — named keywords, hexadecimal (#ff5733), rgb(), hsl(), and hwb() — which every browser has understood for years, and the modern wide-gamut, perceptually-uniform spaces — lab(), lch(), oklab(), and oklch() — which can express colors outside sRGB, including P3 shades that sRGB hex and RGB values cannot express. A key modernization people miss: rgb() and hsl() no longer need the rgba()/hsla() variants for transparency — you add alpha inline with a slash, as in rgb(255 0 0 / 50%). And currentColor is a special keyword, not a format: it makes an element inherit whatever text color is currently in effect.

That is the summary an AI overview gives you. Here is what it can't: why the perceptual formats are worth switching to, the exact syntax and gamut of each format side by side, and a defensible rule for which one to use when. Skip to the comparison table if you just want the cheat sheet.

The comparison table: common formats and syntax

Every format below produces a color; they differ in what they can express, whether they carry an alpha channel, and how pleasant they are to reason about by hand.

FormatExample syntaxGamutAlpha?Reach for it when…
NamedrebeccapurplesRGBtransparent onlyPrototyping, transparent, quick demos
Hex#ff5733 / #ff5733ccsRGB8-digit (RRGGBBAA)Copy-paste from design tools; compact tokens
rgb() / rgba()rgb(255 87 51 / 80%)sRGBYes (slash or 4th arg)Programmatic channel math; interop with JS/canvas
hsl() / hsla()hsl(9 100% 60% / 80%)sRGBYes (slash or 4th arg)Hand-tuning by hue/lightness; simple theming
hwb()hwb(9 20% 10%)sRGBYes (slash)"Tint/shade" thinking: hue + white + black
lab()lab(60% 55 45)Beyond sRGBYes (slash)Perceptual accuracy; print-adjacent work
lch()lch(60% 72 40)Beyond sRGBYes (slash)Perceptual + polar hue control (CIELAB)
oklab()oklab(0.7 0.12 0.08)Beyond sRGBYes (slash)Perceptually-uniform blends and gradients
oklch()oklch(70% 0.15 40 / 80%)Beyond sRGBYes (slash)Default for 2026 — themes, scales, brand palettes
color()color(display-p3 1 0 0)Explicit color space, including display-p3Yes (slash)Specifying a wide-gamut color directly
Relative color syntaxrgb(from var(--brand) r g b / 50%)Depends on source and functionYesDeriving channels or alpha from an existing color
currentColorborder: 1px solid currentColorInherits colorInheritsIcons/borders that must track text color

The single most useful row is the last real one. If you take nothing else from this article, make oklch() your default and drop back to hex only for pasted snippets.

The anatomy of a modern color function

The polar functions lch() and oklch() share a useful shape: lightness, chroma, hue, and optional alpha after a slash. hwb() also uses a hue angle, but its other channels are whiteness and blackness.

Anatomy of an oklch() color The value oklch(70% 0.15 40 / 80%) broken into Lightness, Chroma, Hue, and Alpha channels, with a highlight sweeping across each part in turn. One shape, four modern formats: lch, oklch, oklab, hwb oklch(70% 0.15 40 / 80%) Lightness 0% → 100% perceived brightness Chroma 0 → ~0.4 colorfulness Hue 0 → 360° which color Alpha / 0–100% optional

Read that as: 70% OKLCH lightness, a moderate amount of color, at hue 40° (a warm orange-red), painted at 80% opacity. Compare it to rgb(255 87 51 / 80%), which encodes the same idea as three opaque hardware channels you cannot reason about — nudge one number and you have no idea whether the result gets lighter, darker, or shifts hue.

Why the perceptual formats win: uniformity

The reason to prefer oklch() over hsl() is not gamut — it is that HSL lies about lightness. In HSL, every fully-saturated color claims 50% lightness, but a 50% yellow is visually far brighter than a 50% blue. Build a UI palette by rotating the hue and your "same brightness" colors will look wildly uneven, and text contrast will vary hue to hue. OKLCH is designed for more even perceived lightness across hues, but fixed lightness does not guarantee equal WCAG contrast.

HSL versus OKLCH lightness uniformity Illustrative rows of swatches across hues. The HSL row varies in apparent brightness while the OKLCH row is designed for more even lightness. A marker sweeps across both rows. Same "50% lightness", two color spaces hsl(H 100% 50%) yellow & cyan blaze; blue sinks — uneven brightness oklch(65% 0.14 H)

The bottom row illustrates more even apparent brightness as the hue rotates. OKLCH helps build scales and hover states, but test the resulting colors and text contrast rather than assuming a lightness value guarantees accessibility.

The trade-off is real but small: oklch() numbers are less familiar than hex, and you usually author them with a tool rather than from memory. Which is exactly what the picker below is for.

Color Picker & Converter - HEX, RGB, HSL

Pick colors and convert between HEX, RGB, HSL, and HSV formats. Includes palette generator, contrast checker, and CSS export.

Open the full Color Picker & Converter - HEX, RGB, HSL tool →
Loading interactive tool...

Practical rules for 2026

  • Author intentional colors in oklch(). Brand colors, theme tokens, gradients, and any color scale belong here. Step the lightness for a scale; rotate the hue for a palette; both behave predictably.
  • Keep hex for pasted snippets and design-tool exports. It is compact, universal, and what Figma/Sketch/Illustrator hand you. There is no need to convert a one-off value.
  • Use the modern space-separated alpha syntax. Write rgb(255 0 0 / 50%) and hsl(200 75% 50% / 0.5) rather than reaching for rgba()/hsla(). Prefer a color's own alpha over the opacity property, which fades the element and all its descendants.
  • Use currentColor for icons and borders that should follow the text color through hover and dark-mode changes — it removes a whole class of duplicated color rules.
  • Fallbacks are mostly optional now, but if you support legacy browsers, declare an sRGB value first and the modern one second, or gate it with @supports (color: oklch(0% 0 0)).
:root {
  /* one hue, a perceptually-even scale — trivial in oklch, painful in hsl */
  --brand-50:  oklch(97% 0.02 260);
  --brand-500: oklch(55% 0.15 260);
  --brand-900: oklch(25% 0.08 260);
}

.button {
  background: #3366cc;                 /* sRGB fallback for ancient browsers */
  background: oklch(55% 0.15 260);     /* modern browsers use this */
  color: oklch(98% 0.01 260);
  border: 1px solid currentColor;      /* border tracks the text color */
}

.button:hover {
  /* bump lightness by a fixed amount — looks right at every hue */
  background: oklch(60% 0.15 260);
}

Browser support, briefly

Check browser support against your audience before shipping newer color syntax. Named colors, hex, rgb(), hsl(), and hwb() are universally supported. The wide-gamut perceptual formats — lab(), lch(), oklab(), and oklch() — are supported in every current engine: Chrome and Edge 111+ (March 2023), Firefox 113+ (May 2023), and Safari 15.4+ (March 2022). That is multiple years of coverage, which is why oklch() is now a reasonable default rather than a progressive enhancement. Provide an sRGB fallback only if your analytics show meaningful traffic from browsers older than those versions.

The bottom line

CSS color formats split cleanly into "old and universal" (named, hex, rgb, hsl, hwb — all sRGB) and "modern and perceptual" (lab, lch, oklab, oklch — beyond sRGB). For code you paste, hex is fine. For color you design — themes, scales, brand systems — author it in oklch(): it is uniform, wide-gamut, alpha-capable, and supported everywhere that matters. Reach for currentColor to keep icons and borders in sync, and use the slash-alpha syntax so you never need rgba() again.

Design That Converts

User experience drives business results. Our team creates designs that are beautiful, accessible, and effective.