On compliance vs readability: Generating text colors with CSS • Lea Verou

May 20, 2024

Out of all the CSS features I have designed, Relative Colors aka Relative Color Syntax (RCS) is definitely among the ones I’m most proud of. In a nutshell, they allow CSS authors to derive a new color from an existing color value by doing arbitrary math on color components in any supported color space:

--color-lighter: hsl(from var(--color) h s calc(l * 1.2));
--color-lighterer: oklch(from var(--color) calc(l + 0.2) c h);
--color-alpha-50: oklab(from var(--color) l a b / 50%);

The elevator pitch was that by allowing lower level operations they provide authors flexibility on how to derive color variations, giving us more time to figure out what the appropriate higher level primitives should be.

Source: On compliance vs readability: Generating text colors with CSS • Lea Verou

CSS has gained increasing abilities to calculate–but traditionally length units. We can now do color calculations in CSS. Lea Verou discusses them and their usefulness here.