This content originally appeared on Manuel Matuzović - Web development blog and was authored by Manuel Matuzović
Like the lab() color function, hwb()
is one of the more recent methods for defining colors in CSS. Just like rgb()
and hsl()
it uses colors from the sRGB color space. HWB, which stands for hue-whiteness-blackness, describes colors with a starting hue, then a degree of whiteness and blackness to mix into that base hue.
The function takes 3 space-separated values.
div {
background-color: hwb(234deg 30% 34%);
}
h - hue
The first value defines the hue. It's an angle of the color circle given in degs
, rads
, grads
, or turns
. The value can also be a unitless number, which defaults to deg
.
The color circle starts and ends with red (red=0deg=360deg), green is at 120deg and blue at 240deg.
div {
background-color: hwb(0 0% 0%);
}
div {
background-color: hwb(206 0% 0%);
}
w – whiteness
The second parameter specifies the amount of white to mix in, as a percentage from 0% (no whiteness) to 100% (full whiteness).
div {
background-color: hwb(206 68% 0%);
}
b - blackness
The third parameter specifies the amount of black to mix in, as a percentage from 0% (no blackness) to 100% (full blackness).
div {
background-color: hwb(206 0% 42%);
}
opacity
You can also add a fourth parameter for the alpha value.
div {
background-color: hwb(206 0% 42% / 0.5);
}
This content originally appeared on Manuel Matuzović - Web development blog and was authored by Manuel Matuzović
Manuel Matuzović | Sciencx (2022-11-04T09:38:54+00:00) Day 30: the hwb() color function. Retrieved from https://www.scien.cx/2022/11/04/day-30-the-hwb-color-function/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.