Images Tool Box LogoImages Tool Box
Color theory wheel showing HEX RGB HSL color relationships
Design11 min read

Color Theory for Web Design: Understanding HEX, RGB, HSL, and Color Spaces

Learn how HEX, RGB, HSL, and OKLCH color formats work in web design, when to use each one, and how to build accessible color palettes that work across devices in 2026.

By Images Tool Box Team
Share

Color is the most emotionally charged design decision and the most technically misunderstood. The same blue in HEX versus HSL versus OKLCH can render differently. The same accessible contrast in dark mode often fails in light mode. The same palette that looks premium on a designer's MacBook can look muddy on a budget Android phone. This guide covers what each color format is good at, why OKLCH is becoming the default in 2026, and how to build palettes that work across light mode, dark mode, and different devices.

The Four Color Formats You Will Meet

CSS has supported four primary color models. Each has a job.

HEX: The Legacy Default

#0891b2 is three pairs of hexadecimal digits representing red, green, and blue. HEX is the lingua franca of design tools. Figma, Sketch, Photoshop, and every design tool on the planet speak HEX. It is compact (6 characters), unambiguous, and universal for designer-to-developer handoff.

The limitation: humans cannot intuit color from hex digits. You cannot easily "make it 10 percent darker" in hex without converting mentally. HEX also cannot express colors outside the sRGB gamut.

Use HEX for: brand colors, design system tokens that do not need adjustment, anything you copy from a design tool.

RGB: The Literal-Pixel Format

rgb(8 145 178) expresses the same sRGB triplet as HEX, just in decimal. Each channel is 0 to 255. CSS Color Module Level 4 modernized the syntax to use spaces instead of commas, and alpha is now a slash-separated component: rgb(8 145 178 / 0.8).

RGB maps directly to how screens work: mix red, green, and blue light. It is the right format when you are pulling channel values from an image, canvas, or sensor.

Use RGB for: programmatic color manipulation, image processing, canvas drawing, animations that change one channel.

HSL: The Human-Friendly Format

hsl(190 91% 36%) describes color by hue (0 to 360 degrees on the color wheel), saturation (0 to 100 percent), and lightness (0 to 100 percent). It is intuitive: want a darker version? Drop the lightness. Want less saturated? Drop the saturation. Want the complementary color? Rotate hue by 180.

The catch is that HSL's "lightness" is perceptually inconsistent. hsl(60 100% 50%) (pure yellow) looks much lighter than hsl(240 100% 50%) (pure blue) at the same L value. This breaks systematic design. A 5-step lightness ramp produced by stepping the L coordinate will have yellows that blow out and blues that stay too dark.

Use HSL for: prototyping, quick adjustments in browser DevTools, design tools that do not yet support OKLCH.

OKLCH: The Perceptual Default in 2026

oklch(57% 0.13 220) describes color by perceptual lightness (0 to 100), chroma (analogous to saturation, 0 to about 0.4), and hue (0 to 360 degrees). It is built on the OKLab color space, which was designed to approximate human perception: equal numerical changes in L correspond to roughly equal perceived changes in lightness.

Two colors at L=50 in OKLCH look the same brightness regardless of hue. This is exactly what HSL fails at. OKLCH also represents a wider color gamut than sRGB, meaning it can specify colors that modern wide-gamut displays can show but HSL cannot express.

Browser support for OKLCH landed in all major browsers in 2023. By 2026, it is safe to use in production. The CSS Color Module Level 4 specification introduced it alongside LCH, lab(), and color() for wide-gamut color spaces.

Use OKLCH for: building design systems, light/dark mode tokens, anywhere consistent perceptual brightness matters across hues.

When to Use Which Format

SituationBest FormatWhy
Building a design system from scratchOKLCHPerceptually uniform lightness ramps
Working with existing brand colorsHEXThey came as HEX, keep them as HEX
Quick prototyping in DevToolsHSLEasiest mental adjustments
Image manipulation, canvas drawingRGBMatches pixel data format
Accessibility contrast checkingOKLCH or WCAG luminancePerceptual accuracy matters

Building a 2026 Color Palette

1. Brand Colors (1 to 3 hues)

Choose 1 to 3 primary hues that represent your brand. Consider industry norms (tech tends toward blue/purple, finance toward navy/green, fashion toward black/white with a single accent) and emotional fit (warm colors convey energy and urgency, cool colors convey trust and calm).

2. Functional Accent Colors (4 to 5 fixed)

Standard semantic colors: green for success, yellow or amber for warning, red for error, blue for info, gray for neutral. These should be consistent across all themes.

3. A Neutral Scale (9 to 12 grays)

Most UI is gray. Build a scale from gray-50 (page background in light mode) to gray-950 (page background in dark mode), with intermediate values for borders, body text, and headings. In OKLCH, stepping the L channel produces a perceptually uniform gray ramp. In HSL, you will need to manually tune each step.

4. Light/Dark Mode Palette Parity

Every brand and functional color needs a dark-mode counterpart. Naive inversion (just flipping light and dark) does not work. In dark mode, saturated colors need lower chroma to avoid vibrating against dark backgrounds. Backgrounds should not be pure black (OKLCH L=0) but a very dark gray (OKLCH L=15 to 20) to reduce eye strain and create depth.

Accessibility: WCAG Contrast Requirements

Color choices affect accessibility. The WCAG 2.1 contrast guidelines specify minimum contrast ratios:

  • Normal text: 4.5:1 minimum (AA), 7:1 for AAA
  • Large text (18pt or 14pt bold): 3:1 minimum (AA), 4.5:1 for AAA
  • UI components and graphical objects: 3:1 minimum

Contrast is calculated using relative luminance, not HSL lightness. A color that looks "light enough" in HSL may fail WCAG because HSL lightness does not match perceived brightness. This is why OKLCH is better for accessibility work: its lightness channel correlates with perceived brightness, making it easier to predict whether a color combination will pass.

Test your color combinations with a contrast checker before shipping. Common failures: gray text on white (often below 4.5:1), brand color buttons with white text (frequently below 4.5:1 for yellow and light blue brands), and dark mode text that is too low contrast against the dark background.

Color Spaces: sRGB, P3, Rec2020

All the formats above are color models (ways of describing a color). The color space is the gamut the model maps onto. sRGB is the default for the web and roughly matches the colors a 1996 CRT could display. MDN's color documentation covers the full range.

Modern displays (MacBook Pro, iPhone 15+, high-end Android phones, many monitors) support wider gamuts like Display P3 and Rec. 2020. OKLCH and LCH can express colors in these wider gamuts. If you specify oklch(70% 0.25 50) on a P3 display, you get a more vivid orange than sRGB can represent. On an sRGB display, the browser gamut-maps it to the closest representable color.

For most websites, sRGB is still the practical default. Wide-gamut color is valuable for photography portfolios, design showcases, and any context where color fidelity matters. Use the color() function to specify wide-gamut colors explicitly: color(display-p3 1 0.5 0).

Real-World Examples

A SaaS startup built their design system tokens in OKLCH. Their primary brand color was oklch(62% 0.19 260) (a vivid blue). They generated a 9-step lightness ramp by varying L from 30 to 95 while keeping chroma and hue constant. The ramp looked perceptually uniform across every step, something their previous HSL-based system never achieved. Dark mode tokens used the same hue with reduced chroma (0.12 instead of 0.19) to prevent the blue from vibrating against the dark background.

A news website with a legacy HEX-based color system wanted to add dark mode. They converted their key brand colors to OKLCH, adjusted the lightness for dark backgrounds, and reduced chroma by about 30 percent. The result was a dark mode that felt like the same brand rather than an inverted version of it. They used the color scheme generator to explore harmony-based variations of their brand hue.

A web app used HSL for its chart colors, assigning hues at 60-degree intervals (0, 60, 120, 180, 240, 300). The yellow chart series (hsl(60 80% 55)) appeared much brighter than the blue series (hsl(240 80% 55)), making the chart look unbalanced. Switching to OKLCH with constant L and C across all series produced a chart where every series had equal visual weight.

Benefits of Understanding Color Formats

  • Perceptually consistent palettes that look balanced across all hues
  • Accessible contrast by choosing formats that match perceived brightness
  • Wide-gamut color support for displays that can show more vivid colors
  • Clean light/dark mode parity without manual per-hue tuning
  • Better design system maintainability with tokens that scale predictably

Tips for Best Results

  1. Start your design system in OKLCH. Even if you deploy as HEX, authoring in OKLCH gives you perceptually uniform lightness ramps that require no manual tuning.

  2. Test contrast, do not guess. HSL lightness does not predict WCAG contrast reliably. Use a contrast checker or calculate relative luminance directly.

  3. Reduce chroma in dark mode. Saturated colors against dark backgrounds create a vibrating effect. Dropping chroma by 25 to 35 percent usually fixes it.

  4. Avoid pure black for dark mode backgrounds. Use a very dark gray (OKLCH L=15 to 20) instead. Pure black reduces depth and increases eye strain when reading light text.

  5. Extract palettes from images. Use the palette from image tool to pull dominant colors from a brand photo or mood board. This grounds your palette in real visual content rather than abstract color theory.

FAQ

What is the difference between HEX and RGB?

They describe the same color in the same color space (sRGB). HEX is base 16 (compact, used by design tools). RGB is base 10 (readable, used in code). #0891b2 and rgb(8 145 178) are the same color.

Why is OKLCH better than HSL?

OKLCH is perceptually uniform. Two colors at the same OKLCH lightness look equally bright regardless of hue. HSL's lightness is mathematical, not perceptual: yellow at HSL lightness 50 looks much brighter than blue at HSL lightness 50. This makes OKLCH better for building consistent color ramps and design systems.

Should I use OKLCH or HEX for my design system?

Author your tokens in OKLCH for perceptual consistency, then convert to HEX for deployment if your tooling does not support OKLCH natively. Most modern browsers support OKLCH since 2023, so you can also deploy it directly.

What is a color space vs a color format?

A color format (HEX, RGB, HSL, OKLCH) is a way of describing a color. A color space (sRGB, Display P3, Rec. 2020) is the range of colors that can be displayed. All HEX and RGB colors are in sRGB. OKLCH and LCH can express colors in wider gamuts like P3.

How do I check if my colors meet WCAG contrast requirements?

Use a contrast checker tool. The WCAG requirement is 4.5:1 for normal text and 3:1 for large text. Contrast is calculated using relative luminance, not HSL lightness. You can also use the color blindness simulator to check how your palette appears to users with different types of color vision deficiency.

Can I generate a color scheme automatically?

Yes. The color scheme generator creates harmony-based palettes (complementary, analogous, triadic, tetradic) from a starting color. It uses HSL-based hue rotation to find harmonically related colors.

Related Tools

Conclusion

Understanding color formats is not academic. It directly affects whether your design system is consistent, whether your contrast passes accessibility standards, and whether your palette looks the same across devices. HEX remains the handoff format for design tools. RGB is the right choice for image processing. HSL is convenient for quick tweaks. OKLCH is the 2026 default for design systems that need perceptual uniformity. Start your next palette with the color scheme generator and test it with the color blindness simulator to make sure it works for everyone.

IT

Images Tool Box Team

Writing about image tools, optimization, and web performance.