Day 30: the hwb() color function

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 start…


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%);
}
red color
Screenshot of Stefan Judis' “hwb() playground”
div {
background-color: hwb(206 0% 0%);
}
blue color

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%);
}
light blue color

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%);
}
dark blue color

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ć


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Day 30: the hwb() color function." Manuel Matuzović | Sciencx - Friday November 4, 2022, https://www.scien.cx/2022/11/04/day-30-the-hwb-color-function/
HARVARD
Manuel Matuzović | Sciencx Friday November 4, 2022 » Day 30: the hwb() color function., viewed ,<https://www.scien.cx/2022/11/04/day-30-the-hwb-color-function/>
VANCOUVER
Manuel Matuzović | Sciencx - » Day 30: the hwb() color function. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/11/04/day-30-the-hwb-color-function/
CHICAGO
" » Day 30: the hwb() color function." Manuel Matuzović | Sciencx - Accessed . https://www.scien.cx/2022/11/04/day-30-the-hwb-color-function/
IEEE
" » Day 30: the hwb() color function." Manuel Matuzović | Sciencx [Online]. Available: https://www.scien.cx/2022/11/04/day-30-the-hwb-color-function/. [Accessed: ]
rf:citation
» Day 30: the hwb() color function | Manuel Matuzović | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.