CSS Reference ยท Functions
The hwb() function
Reference for the CSS hwb() function: how hue, whiteness and blackness mix, what happens when they add up to 100%, alpha, and live examples.
The hwb() function describes a color the way a painter might: pick a hue, then add whiteness (white paint) and blackness (black paint). With both at 0% you get the pure, fully vivid color; adding white gives pastels, adding black gives dark shades, and adding both gives muted tones.
Like hsl(), it is an sRGB notation, so it expresses the same colors as rgb(), just with a more intuitive set of knobs.
.chip { background: hwb(200 10% 5%); }
Try it
In the last row the two amounts add up to 100% or more, so the hue has no effect and you get a gray.
Syntax
hwb(H W B) hwb(H W B / A) hwb(from <color> H W B / A)
There is no legacy comma form and no hwba() alias. The result is a <color>.
Syntax and arguments
| Argument | Description |
|---|---|
H |
Hue, a number (degrees) or an angle. Wraps around at 360. |
W |
Whiteness, 0% to 100%. |
B |
Blackness, 0% to 100%. |
A |
Optional alpha, number 0โ1 or percentage. |
Usage notes
- When
W + Breaches 100% or more, the two values are scaled down proportionally and the result is a gray; hue is ignored. - Same colors as
hsl(). Anyhwb()color can be written withhsl()orrgb(); choose the one that makes your edits easiest. - Good for tints and shades. Raise
Wfor tints, raiseBfor shades, without touching hue or having to think about saturation. - Still not perceptually uniform. Equal changes of
Wdo not give equal visual steps across hues. - Contrast. As with every notation, check text contrast against the actual rendered color.
Browser support
hwb() is supported in current versions of all major browsers; check a compatibility table if you need older ones.
Related
hsl()โ hue, saturation, lightnessrgb()โ red, green, blue- Color values
- Lesson: Colors