hexcolors

Learn / Blog / Developers

Hex vs RGB vs HSL: which color format should you use?

When to write colors as hex, RGB, HSL or OKLCH in CSS, and why it matters.

November 12, 20261 min readBy the hexcolors team

Key takeaways

  • Hex is the best format for sharing and storing a single color.
  • RGB is convenient for transparency and calculations.
  • HSL and OKLCH are best for creating lighter, darker and softer variations.

CSS gives you many ways to write the same color. They all end up as red, green and blue light on a screen, but they are not equally convenient to work with. Here is when each one earns its place.

Hex: compact and universal

Hex is the shortest way to write an opaque color, such as #1E90FF. Design tools, brand guides and documentation all use it, which makes it the best format for sharing a color. Eight-digit hex adds an alpha pair at the end, so #1E90FF80 is the same blue at about 50 percent opacity.

RGB: good for transparency and math

rgb(30 144 255) is easy to read once you know the channels, and the modern syntax accepts alpha after a slash: rgb(30 144 255 / 50%). It is the natural choice when JavaScript calculates colors or mixes channels directly.

HSL: good for adjusting colors

HSL describes hue, saturation and lightness, which matches how people think about changing a color. Want a darker hover state? Lower the lightness. Need a softer background version? Lower the saturation. That is why palette scales are usually built in HSL. The converter shows any color in every format.

OKLCH: perceptual lightness

HSL has a flaw: two colors with the same lightness value can look very different in brightness. OKLCH is designed so that equal lightness looks equal, which makes generated scales more even. It is supported in current browsers, so it is worth trying for new design systems.

A simple rule

Store brand colors as hex, derive variations in HSL or OKLCH, and use CSS variables so each color is defined once:

:root {
  --brand: #1e90ff;
  --brand-hover: hsl(209 100% 48%);
  --brand-soft: rgb(30 144 255 / 12%);
}
The hexcolors teamWe build free color tools and write practical guides. Follow us on X, Instagram and LinkedIn.