Colors, Gamuts & Color Spaces
Stop picking random hex codes from Google. Master how computer monitors generate light, why the 30-year-old sRGB standard fails on modern Retina screens, and how the modern oklch() space gives you mathematically uniform, perceptual colors.
1. The 1st-Year Mental Model: Additive Light vs Physical Paint
Real World Art Class (Subtractive Pigment)
When painting on paper, paint reflects ambient light while absorbing other wavelengths. If you mix Red, Yellow, and Blue together, it turns into a murky brown/black. Darkness is the baseline; ink takes light away.
All pigments combined = #000000 Black
Your Monitor Screen (Additive Light)
A computer display is millions of microscopic LED flashlights. Black is the monitor turned off. When you fire all Red, Green, and Blue sub-pixels at 100% brightness simultaneously, the human eye perceives blinding pure White light!
All lights at maximum (255, 255, 255) = Pure White #ffffff
2. The 4 Generations of CSS Color Formats
| Format | Modern Syntax | Mental Formula | Limitation |
|---|---|---|---|
| Hexadecimal | #3b82f6 or #3b82f6cc | Base-16 red, green, blue (00-ff) + alpha | Incomprehensible to humans without color picker |
| RGB (Legacy & Modern) | rgb(59 130 246 / 0.8) | 0 to 255 channel levels + alpha opacity | Hard to calculate "make this 15% darker" in head |
| HSL (Human Friendly) | hsl(217 91% 60%) | Hue wheel (0-360°), Saturation %, Lightness % | Perceptually uneven (Yellow 50% looks blinding; Blue 50% looks dark) |
| OKLCH (Next-Gen) | oklch(0.65 0.22 250 / 0.9) | Lightness (0-1), Chroma/Purity (0-0.4), Hue angle (0-360°) | Zero flaw! Truly uniform human perception + accesses wide P3 gamut |
3. Interactive Lab: Test HSL vs Modern OKLCH
Modern UI Card Example
Notice how altering hue in OKLCH keeps perceived brightness steady, preventing the washed-out yellow or dim blue problem common to HSL!
4. Deep Visualizer: Gradients & System Palette
Color, Contrast & Gradient Studio
Design accessible palettes with OKLCH wide-gamut colors, real-time WCAG 2.2 contrast validation, and modern gradient interpolation.
Try these
- Toggle "in oklch" interpolation on the gradient to observe how it removes muddy gray transitional midpoints.
- Test contrast scores against white vs black to find an accessible text color pairing.
- Switch to the Harmonies tab to generate mathematically balanced color schemes (Complementary, Triadic).
- Compare the modern oklch() color syntax with traditional hsl() and hex values.
High-Precision CSS Surface
Interpolation mode: in oklch
First-Year Student Traps: CSS Colors
- 1.The Comma Trap: Modern CSS syntax uses spaces instead of commas:
rgb(255 100 50 / 0.8)instead ofrgba(255, 100, 50, 0.8). The slash syntax clearly delineates channels from alpha! - 2.The Gray Mud Trap in Gradients: Interpolating between two colors in legacy sRGB often passes through an ugly desaturated gray middle. With modern CSS, add
in oklch:linear-gradient(in oklch to right, red, blue)for breathtaking vibrant transitions. - 3.The "transparent" Keyword Trap: Historically,
transparentwas computed asrgba(0, 0, 0, 0)(transparent black). When fading from white to transparent, you might see a dirty grayish flash! Always fade torgb(255 255 255 / 0)instead.
Backgrounds, Gradients & Parallax Layers
Stack multiple images, build pure CSS pie charts with conic gradients, and create fixed parallax effects.