Web Color Systems: RGB, HSL, OKLCH, P3

Color on the web used to mean hex codes and sRGB. Modern CSS supports several color systems with meaningfully different ergonomics and capabilities. This guide explains what each system is, when to use it, and how to mix them safely.

The Systems at a Glance

SystemSyntaxGamutBest for
Hex#ff6633sRGBConcise; ubiquitous
RGBrgb(255 102 51)sRGBDirect channel control
HSLhsl(15 100% 60%)sRGBHue rotation, simple palettes
LCHlch(60% 80 30)WidePerceptually uniform
OKLCHoklch(0.6 0.2 30)WideModern design systems
Display P3color(display-p3 1 0.4 0.2)P3Vivid colors on modern displays

Perceptual Uniformity Matters

OKLCH is designed to be more perceptually uniform than HSL. Equal lightness values can produce more consistent-looking color scales, but perceived brightness still varies with color, viewing conditions and the observer. Neither OKLCH lightness nor visual similarity replaces a contrast check using the applicable accessibility method.

Wide-Gamut Color

Some displays support a gamut wider than sRGB, including Display P3, but support cannot be assumed from a device’s age. CSS colors may also lie outside the display’s gamut. Provide suitable fallbacks and test rendering on target browsers and screens; gamut mapping can change the appearance.

A Modern Color Workflow

  1. Author in OKLCH for clarity and perceptual uniformity.
  2. Provide hex fallbacks for older browsers if you support them.
  3. Define color tokens (--brand-500, etc.) using OKLCH; use them everywhere downstream.
  4. Build scales by varying L while holding C and H — produces uniform brightness steps.
  5. Test contrast pairs early and lock them into your token system.

Converting Between Systems in Practice

You rarely convert by hand, but knowing how the systems relate prevents nasty surprises:

  • Hex and RGB are the same thing in different clothing — #3366cc is exactly rgb(51 102 204). Hex is just two hexadecimal digits per channel.
  • HSL is a reversible transform of RGB, so conversion is reversible in exact arithmetic; rounding or limited precision can change values; both describe sRGB colours.
  • OKLCH and Lab can describe colours outside sRGB, so converting a wide-gamut colour down to hex is lossy — it needs gamut mapping into sRGB; clipping is one possible approach.
  • Let CSS do the work: modern browsers accept oklch() directly, and color-mix() blends across spaces, so author in whichever space is easiest to reason about and ship that.

Choose an authoring space for the workflow, provide suitable fallbacks, and avoid unintended conversion of out-of-sRGB colors to hex. Gamut mapping can change hue, chroma or lightness; it does not simply dull every color.

Try It Yourself

Extract palettes from images and explore color relationships with DesignKit tools.

Color Palette Extractor →

Frequently Asked Questions

RGB describes a colour by how much red, green and blue light the screen emits — the hardware's native channels. HSL re-expresses that same sRGB colour as hue, saturation and lightness, which is far easier to adjust by eye. They are mathematically interchangeable and render identically; HSL is just a friendlier set of dials on the same colour.
OKLCH is designed to make perceptual adjustments more consistent than HSL. Equal lightness values do not guarantee identical perceived brightness or equal WCAG contrast across hues and viewing conditions.
Display P3 has a wider gamut than sRGB. Availability depends on the display and rendering environment; provide an sRGB fallback rather than assuming all readers can see the wider gamut.
Modern: OKLCH with hex fallback. Wide gamut: color(display-p3 ...) or oklch above sRGB.
WCAG contrast calculations use relative luminance, not the authoring model’s lightness value. Convert supported colors appropriately and account for compositing and gamut mapping; this suite’s checker accepts opaque sRGB HEX colors.