liveBook · Manning

HSL method

As explained in Math for Web Design

The HSL color model represents colors using hue, saturation, and lightness components in a cylindrical coordinate system.

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

How Math for Web Design covers it

How deep it goes
Explains cylindrical coordinates, CSS syntax, palette offsets, and stepwise RGB conversions, while noting HSL’s limits in perceived brightness.
Examples
Shows a purple heading, complementary and analogous palettes, RGB conversion routines, and a scroll-driven red-to-green progress bar.
What it assumes
Introduces hue, saturation, and lightness from their numeric ranges while using CSS declarations and JavaScript calculations for implementation.
What you can do after
Build it from scratch with CSS hue-based palettes and JavaScript color conversions, then test transformed light/dark pairs against their backgrounds.
How it connects
Connects HSL to RGB conversion, color harmony, CSS custom properties, dark mode, and OKLCH.

Also explained in

Compare how 4 books explain HSL method →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Math for Web Design. The section links point to the parts of the book it draws on.