Need a lighter heading color or a coordinated set of UI colors? HSL gives you three separate controls: hue for the color family, saturation for its intensity, and lightness for how light or dark it is. CSS accepts them directly: `h1 { color: hsl(300 100% 25%); }` sets a dark purple heading. section 7.1.2
Picture a cylinder. Hue is an angle around it: 0° is red, 120° green, and 240° blue; the wheel returns to red at 360°. Saturation is distance from the center: 100% gives a pure hue, while 0% gives gray. Lightness is height: 0% is black, 100% white, and 50% is normal brightness. To make a color pastel, lower its saturation and raise its lightness. section 7.1.2
Figure 7.2 You can visualize the HSL color model as a cylinder.
The cylinder makes the three independent adjustments—angle, distance from center, and height—easier to visualize. section 7.1.2
An HSL value can also include transparency: `hsl(300 100% 25% / 0.75)`. Changing one component at a time makes the result easier to predict than changing several RGB channels together. section 7.1.2
Hue arithmetic turns one base color into a palette:
- Complementary colors sit 180° apart. For a base hue of 240°, `(240 + 180) % 360` gives 60°. section 7.3.1
- Analogous colors sit nearby, typically at the base hue plus and minus 30°; use 15° for a closer grouping. section 7.3.2
- Triadic colors are evenly spaced at the base hue plus and minus 120°. section 7.3.3
Keep a complementary pair tied to one CSS value
`:root { --base-hue: 39; --main-color: hsl(var(--base-hue) 100% 50%); --comp-color: hsl(calc(var(--base-hue) + 180) 100% 50%); }` Change `--base-hue` to update both colors; CSS handles the hue wrapping. section 7.3.1
When a color starts as RGB, convert each channel from 0–255 to 0–1. The difference between the largest and smallest channels is chroma, and their average is HSL lightness. If chroma is zero, set hue and saturation to zero: the color is gray. Otherwise, calculate saturation from chroma and lightness, then determine hue from whichever RGB channel is largest. To convert back, normalize HSL, handle zero saturation as equal RGB channels, interpolate the three channels around the hue wheel, and scale them to 255. section 7.2.2 section 7.2.3
Color a reading-progress indicator
Let `scrollProgress` run from 0 at the top of a page to 1 at the bottom. Set `const hue = scrollProgress * 120` and use ``progressBar.style.backgroundColor = `hsl(${hue}, 70%, 50%)`;``. The bar changes gradually from red to green as its width tracks reading progress. section 13.3.1
For a paired light/dark palette, a starting transformation is to invert lightness with `100 - l`, reduce saturation, and optionally shift hue slightly. Test each transformed color against its new background. HSL makes those adjustments straightforward, but OKLCH offers better perceptual fidelity: equal HSL lightness values do not necessarily look equally bright. section 7.5.2 section 7.5.4



