2.2 · Color

Derive colors: relative color syntax

Derive hover states, tints and complements from a single color.

oklch(from var(--brand) l c h) takes an existing color apart into its channels, so you can change one and keep the rest. calc(l - 0.1) darkens it, / 0.15 sets the opacity, and calc(h + 180) gives its complement.

The input can be any color format: hex, a named color or another variable. One brand color becomes a full set of states.

Before
--brand: #7c4dff;
--brand-hover: #6a3df0;  /* by hand */
--brand-active: #5a2fe0;
--brand-ghost: rgb(124 77 255 / 0.15);
/* …repeat for every brand color */
Now
--brand: #7c4dff;

&:hover {
  background:
    oklch(from var(--brand) calc(l - 0.08) c h);
}
&.ghost {
  background:
    oklch(from var(--brand) l c h / 0.15);
}