As web development has matured from primitive 8-bit displays to wide-gamut Display P3 screens and CSS Color Module Level 4, frontend developers face a bewildering choice of color formats: HEX, RGB, HSL, HSV, CMYK, LAB, and OKLCH.
Why do we use HEX for brand tokens, RGB for canvas manipulation, HSL for CSS transitions, CMYK for packaging print, and OKLCH for modern design systems? In this comprehensive reference guide, we examine each color space, its mathematical structure, and exactly when to use each in production.
1. HEX (Hexadecimal Color Notation)
A hexadecimal color is a six-digit, base-16 representation of Red, Green, and Blue. Each pair of digits corresponds to an 8-bit integer between 00 (0) and FF (255):
- Pros: Ultra-compact, universally supported across all browsers since HTML 2.0, copy-paste friendly.
- Cons: Unintuitive to humans. You cannot easily adjust brightness or saturation without software.
- Best For: Static CSS design tokens, brand style guides, Figma exports, and Tailwind configuration.
2. RGB & RGBA (Red, Green, Blue)
RGB is an additive color model that matches the physical light-emitting subpixels of OLED, LCD, and LED monitors:
- Pros: Maps 1:1 to browser graphics hardware and the HTML5 Canvas ImageData API.
- Cons: Lacks intuitive controls for hue or saturation shifting.
- Best For: WebGL, Canvas pixel processing, and dynamic alpha-transparency overlays.
3. HSL (Hue, Saturation, Lightness)
Designed in the 1970s to mimic human cognitive color perception, HSL separates color identity (Hue) from chromatic intensity (Saturation) and brightness (Lightness):
- Pros: Incredibly easy for humans to adjust. To make a button hover state, simply increment Lightness by 10%.
- Cons: Flawed perceptual uniformity. Pure yellow at 50% lightness appears dramatically brighter to human eyes than pure blue at 50% lightness.
- Best For: Interactive UI themes, CSS hover states, and dynamic gradient generators.
4. CMYK (Cyan, Magenta, Yellow, Key Black)
Unlike screens that emit light (additive), physical inks absorb (subtract) light:
- Pros: The international industry standard for offset lithography, digital printing, packaging, and merchandise.
- Cons: Cannot produce vibrant neon greens or electric blues that screens display (smaller color gamut).
- Best For: Print marketing materials, business cards, stickers, and physical apparel.
5. OKLCH: The Modern CSS Future
Introduced in CSS Color Module Level 4, OKLCH (Lightness, Chroma, Hue) is a perceptually uniform color space that accesses wide-gamut Display P3 colors:
Unlike HSL, in OKLCH, a lightness of 0.7 has identical perceived brightness whether the color is yellow, blue, or red. This makes generating accessible design token systems completely predictable!
Summary: Color Space Decision Matrix
| Color Model | Type | Primary Use Case | Browser Support |
|---|---|---|---|
| HEX | Additive (sRGB) | Design tokens, Figma, Tailwind CSS | 100% (Universal) |
| RGB | Additive (sRGB) | HTML5 Canvas, WebGL, Image Processing | 100% (Universal) |
| HSL | Additive (sRGB) | CSS Hover States, Color Palettes | 100% (Universal) |
| CMYK | Subtractive | Commercial Printing, Packaging | Print Only |
| OKLCH | Perceptual (P3) | Modern CSS Design Systems | >92% (Modern) |
Need to convert between all these formats?
Use our Universal Color Converter to translate HEX, RGB, HSL, CMYK, and OKLCH in 1 click.