In CCS there are several ways to notate color values. Basically we have three options:
- Using a Keyword: e.g.
black
- Hexadecimal Notation: e.g.
#000000
,#000
, and#000000FF
- Functional Notation: e.g.
rgb(0, 0, 0)
,rgba(0, 0, 0, 1)
(and thehsl()
/hsla()
variants)
~
The CSS Color Module Level 4 specification adds an extra variation to the Functional Notation: it allows you to separate the individual RGB (or HSL, etc.) values using spaces instead of commas, e.g. rgb(0 0 0);
.
rgb()
,rgba()
,hsl()
, andhsla()
have all gained a new syntax consisting of space-separated arguments and an optional slash-separated opacity.
Above that rgba()
has become an alias for rgb()
, so our colors in CSS – using the Functional Notation – will soon look as follows:
/* Before: Comma-Separated Functional Color Notation */
div {
color: rgb(0, 0, 0);
color: rgba(0, 0, 0, 1);
}
/* After: Space-Separated Functional Color Notation */
div {
color: rgb(0 0 0);
color: rgb(0 0 0 / 1);
color: rgb(0 0 0 / 100%);
}
~
You should start writing your colors using this new syntax today, as:
- The syntax is already supported by all major browsers.
- New color functions – such as
lab()
,lch()
andcolor()
– will only support the space-separated syntax
Your preprocessor can take care of older browsers such as IE11 😉
~
Thank me with a coffee.
I don\'t do this for profit but a small one-time donation would surely put a smile on my face. Thanks!
To stay in the loop you can follow @bramus or follow @bramusblog on Twitter.