In this lesson, you mixed a pale tint, a shade and a see-through version of Bea’s leaf green from the brand token, --green-50, instead of typing each one by hand. Your hand-typed scale can’t follow a change to the brand green, and it has no see-through step, but mixed tokens do both. You read each result’s lightness in the Computed pane of Chrome DevTools.
Key Points
color-mix()takes a color space first, then two colors. The percentage after a color is that color’s share, and the other color gets the rest. Sovar(--green-50) 80%, whiteis 80% green and 20% white.- Oklab is the space that
oklch()is built on. Its first number is the same lightness, and the other two set the hue and how colorful the color is. The Computed pane shows an oklab mix with its lightness first, written from 0 to 1, so0.6is the60%you’d write inoklch(). - In oklab, even shares give even tints. With the green at lightness 0.5, mixing 80%, 50% and 20% green with white gives lightness 0.6, 0.75 and 0.9. Each step of 30% moves the lightness by the same 0.15.
- Mixing with black gives a shade. Half green and half black in oklab lands at lightness 0.25, halfway from the green to black.
- Mixing with
transparentturns the percentage into opacity. The result keeps the green’s color. The number after the slash, as in/ 0.3, is its opacity, so whatever sits behind a card’s border shows through it. - The space you name decides how the colors blend. The same half-and-half shade comes out lighter in srgb, at about 0.31, because srgb averages the red, green and blue numbers the screen stores, and those don’t step evenly in lightness. Oklab and oklch both average the same lightness, so they agree on 0.25. Mixed with black, the whole color matches too. Black has no chroma, so in both spaces the green keeps its hue.
- If you leave the space out, the browser mixes in oklab, not srgb. Write the space anyway, because older browsers don’t support the form without it.
- Every mixed token reads the brand token, so changing
--green-50changes the tint, the shade and the see-through green with it.
The Final Tokens
Under the brand green on :root, you added the three mixed primitives and two new roles that point at them. --color-border stays as it was, so the borrow form’s fields keep their solid green:
:root {
--green-50: oklch(50% 0.12 140);
--green-tint: color-mix(in oklab, var(--green-50) 20%, white);
--green-shade: color-mix(in oklab, var(--green-50) 50%, black);
--green-glass: color-mix(in oklab, var(--green-50) 30%, transparent);
--color-border: var(--green-50);
--color-surface-highlight: var(--green-tint);
--color-card-border: var(--green-glass);
}
The “Returns week” banner and the seed cards read their new roles:
.returns-banner {
background: var(--color-surface-highlight);
}
.seed-card {
border: 2px solid var(--color-card-border);
}
Bea’s hover colors are still picked by hand. Next, in Derive Hover Shades From a Token, you’ll build those from the brand green too.