liveBook · Manning

Hue

As explained in Math for Web Design

Hue is the perceptual attribute that identifies a color by its position among color families such as red, green, or blue.

Need colors that work together on a web page? Start with hue: a color’s position around a color wheel. In HSL, 0° is red, 120° is green, and 240° is blue. The wheel wraps around, so 360° returns to red. section 7.1.2 section 7.3

Figure 7.2 You can visualize the HSL color model as a cylinder.

The HSL cylinder makes the three controls easier to separate: hue is the angle around it, saturation is distance from its center, and lightness is height. section 7.1.2

Set a hue in CSS

`h1 { color: hsl(300 100% 25%); }` sets hue to 300°, saturation to 100%, and lightness to 25%. Change the first value to choose another color family; change the others to adjust its purity or brightness. At 0% saturation, the result is grayscale rather than a distinguishable hue. section 7.1.2 section 7.2.2

Hue is also an angle in OKLCH, but its numbers are not interchangeable with HSL’s: OKLCH hue is derived from a perceptual color model. Rotating an HSL hue can change apparent brightness; rotating an OKLCH hue while holding lightness and chroma fixed maintains perceived brightness. For example, `oklch(0.42 0.2 328)` specifies lightness, chroma, then hue. Check wide-gamut OKLCH colors on ordinary displays when you are not targeting Display P3. section 7.1.4

For an HSL palette, calculate new hues from a base angle H:

  • Complementary: use `(H + 180) % 360`. A 240° base gives 60°. section 7.3.1
  • Analogous: use hues near H, typically H ± 30°; ±15° gives less contrast. section 7.3.2
  • Triadic: use H and H ± 120° for three evenly spaced hues. section 7.3.3
  • Split-complementary: use H plus hues 30° on either side of its complement, or H + 150° and H + 210°. section 7.3.4

CSS custom properties and `calc()` can apply those offsets to one base hue; CSS handles the wraparound. If a color starts as RGB instead, JavaScript can derive its HSL hue by finding the dominant normalized RGB channel, calculating a position in one of six wheel sectors, and multiplying by 60°. Grayscale colors take a separate path because their channel difference is zero. section 7.3.1 section 7.2.2

Make hue respond to scrolling

A reading-progress bar can use `const hue = scrollProgress * 120` and `progressBar.style.backgroundColor = `hsl(${hue}, 70%, 50%)``. As progress moves from 0 to 1, its background moves from red toward green while saturation and lightness stay fixed. section 13.3.1

Hue shifts are useful, but they are not a substitute for checking the whole color. A dark-mode switch based on simple RGB inversion can produce garish colors or distort contrast; adjust lightness and luminance while keeping hue and saturation in check. section 7.5.1

How Math for Web Design covers it

How deep it goes
Defines hue as a color-wheel angle, works through palette offsets and RGB conversion, and distinguishes HSL from OKLCH behavior.
Examples
Uses CSS heading colors, angle-based palettes, RGB-to-HSL JavaScript, and a scroll-driven red-to-green progress bar.
What it assumes
Introduces hue and HSL components from their definitions; uses CSS for color rules and JavaScript for conversion and scrolling examples.
What you can do after
Build it from scratch: calculate related HSL hues with CSS offsets or map scroll progress to a changing hue in JavaScript.
How it connects
Connects hue to HSL, OKLCH, saturation, lightness, chroma, RGB conversion, and complementary, analogous, and triadic color schemes.

Also explained in

Compare how 6 books explain hue →

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.