With the relative color syntax we can modify existing colors using color functions. If an origin color is specified, each color channel can either be directly specified, or taken from the origin color and modified.
For example, we can take a HEX color and add opacity using the rgb() color function and the from keyword.
div {
--color: #FF0000;
}
div {
background-color: rgb(from var(--color) r g b / 50%);
}
rgb(255 0 0 / 50%)
Or we can take the color and replace a specific channel.
div {
background-color: rgb(from var(--color) r g 150);
}
rgb(255 0 0 / 50%)
We can even use the calc() function.
div {
background-color: hsl(from var(--color) h s calc(l - 10%));
}
hsl(0deg 100% 40%)
We can use channel keywords in their corresponding argument, but we don't have to. We can use them in any position.
div {
background-color: rgb(from var(--color)
calc(r * .3 + g * .59 + b * .11)
calc(r * .3 + g * .59 + b * .11)
calc(r * .3 + g * .59 + b * .11));
}
rgb(30% 30% 30%)
How cool is that!? Is there a catch? Well, yeah, it's currently only supported in Safari behind a flag.
My blog doesn't support comments yet, but you can reply via blog@matuzo.at.

