Bea’s leaf green now gives you a tint, a shade, and a see-through version, all mixed from one token. You still pick two colors by eye: the darker terracotta of the “Borrow seeds” button on hover and the softer green of each seed card’s small print. If Bea nudges her terracotta, the hover color stays put, and nobody notices until the two clash.
In this lesson, you’ll derive both colors from their tokens, so they follow any change Bea makes, and give older browsers plain values to fall back on. Start with the button and why the last lesson’s tool isn’t quite right for it.
Derive a Shade From the Accent
A hover color should look like the same button pressed a little deeper: the same hue and strength of color, only darker. Find the two hand-picked values in the components of styles.css:
.borrow-button:hover {
background-color: #a5502f;
}
.seed-details {
color: #4f5f48;
}
They’re the only two rules where a component reads a raw color instead of a role.
Why not mix the accent with black, as you did for the green shade? In oklab, 80 percent terracotta with 20 percent black gives a lightness of 0.48, close to what you want. But its chroma drops from 0.13 to 0.104, because black has no color to add, so the mix comes out duller, more brown than terracotta. Add a row to your swatches.html test strip to compare it with the color you’ll build next:
<h2>Hover Shades</h2>
<div class="strip">
<div class="swatch" style="--swatch: oklch(60% 0.13 40)"></div>
<div class="swatch" style="--swatch: color-mix(in oklab, oklch(60% 0.13 40) 80%, black)"></div>
<div class="swatch" style="--swatch: oklch(from oklch(60% 0.13 40) calc(l - 0.1) c h)"></div>
</div>
Save, and the new row shows the accent, the mix with black, and the derived shade:

The middle patch has lost some of its color. The third is about as dark but keeps the terracotta’s strength, and it’s what the button needs.
That third patch is a relative color: oklch(from <color> l c h). After from comes the origin color, here the terracotta. The browser converts it to oklch(), and inside the parentheses, l, c, and h stand for its lightness, chroma, and hue.
Write them back as they are, and you get the same color. Do math on one of them with calc(), and only that channel changes. So calc(l - 0.1) takes ten points off the lightness and keeps the chroma and the hue.
Watch out for the units. Inside a relative color, the channels are plain numbers, and l runs from 0 to 1 even though you wrote the terracotta as 60%. So calc(l - 10%) makes the whole color invalid, and the button loses its hover background altogether.
If that rule feels odd after writing 60% yourself, the button below opens a chat with your mentor about this paragraph, so you can talk it through:
Now give the hover color a role. In :root, add it under --color-accent, deriving it from the accent role itself:
--color-accent: var(--terracotta-60);
--color-accent-hover: oklch(from var(--color-accent) calc(l - 0.1) c h);
The small print gets the same treatment. Muted text is the body text with its lightness raised, so derive it from --color-text with twenty points more:
--color-text: var(--green-20);
--color-text-muted: oklch(from var(--color-text) calc(l + 0.2) c h);
Then replace the two hex values in the components with the roles:
.borrow-button:hover {
background-color: var(--color-accent-hover);
}
.seed-details {
color: var(--color-text-muted);
}
Hover over “Borrow seeds” in the live preview, and it darkens as before. To read the exact value, select the button in DevTools and open the :hov menu in the Styles pane. Check :hover, then look at background-color in the Computed pane, which shows oklch(0.5 0.13 40). The seed card’s small print computes to oklch(0.4 0.06 140).
Keep a Fallback for Older Browsers
Relative colors are newer than oklch() and color-mix(), so check which browsers support them. They have no MDN reference page of their own, and the Baseline badge at the top of MDN’s oklch() reference covers only the function itself, which is Widely available.
For the relative syntax, find the row for relative oklch colors in the same page’s Browser compatibility table. It shows full support from Chrome and Edge 122, Firefox 128, and Safari 18, released in September 2024, so relative colors are still Baseline Newly available. In an older browser, your button would lose its color on hover, so it needs a fallback.
With most new values, you write a plain declaration first and the new one after it, and a browser that can’t read the second keeps the first. That doesn’t work with custom properties. A browser accepts any value in one and doesn’t check a var() until the page applies it. By then the plain declaration has already lost, so the button gets no background at all.
Instead, put plain values on the roles first, and the derived ones inside an @supports rule. It works like a media query, but it asks whether the browser understands a declaration. In :root, replace the two derived lines with plain values that match what they compute to today:
--color-accent-hover: oklch(50% 0.13 40);
--color-text-muted: oklch(40% 0.06 140);
Then, after the :root rule, add the derived versions inside a condition that only a browser with relative colors passes:
@supports (color: oklch(from red l c h)) {
:root {
--color-accent-hover: oklch(from var(--color-accent) calc(l - 0.1) c h);
--color-text-muted: oklch(from var(--color-text) calc(l + 0.2) c h);
}
}
The condition tests a relative color with no var(), so the browser can check it right away. Where it passes, the derived roles win, as they come later. Where it fails, the browser skips the block and the plain values stay. The condition checks only that the browser reads the syntax, not that it gets the math right.
MDN marks some earlier versions as partial: they read the syntax but get some math wrong. Chrome and Edge 119 to 121 read l from 0 to 100, so they pass the condition, but taking 0.1 off barely moves the color. No @supports condition catches that, but those versions date from early 2024 and few visitors still run them. Safari 16.4 to 17 gets math on h wrong, which your shades don’t use.
You can watch both paths without an old browser. The plain values match the derived ones, so make them differ first: change the lightness of --terracotta-60 to 55%, and read background-color in the Computed pane, with :hover forced as before. It’s oklch(0.45 0.13 40), following the new terracotta.
Now change from in the condition to frm, which no browser understands, save, and read it again. The hover color goes back to oklch(0.5 0.13 40), the plain value, which ignores the new terracotta.
Change frm back to from and the lightness back to 60%. The plain values don’t follow Bea’s brand, so if she changes her terracotta, update them too.
Try explaining the fallback in your own words. The button below opens a chat with your mentor and a starter message. Add your explanation of when the plain values win, send it, and the mentor checks it:
Check Your Understanding
Try these before you open the answers:
- Bea wants a lighter terracotta edge around the “Borrow seeds” button. Add
--color-accent-light, fifteen points lighter than the accent, with its fallback, and give.borrow-buttonthe edge withbox-shadow: 0 0 0 2px var(--color-accent-light);. - How can you see the fallback for
--color-accent-lighttake over in a current browser? - Why derive the hover color with a relative color rather than
color-mix()with black?
- Add a plain value on
:root, such as--color-accent-light: oklch(75% 0.13 40);, and add--color-accent-light: oklch(from var(--color-accent) calc(l + 0.15) c h);in the@supportsblock. - Change the terracotta’s lightness so the derived color moves, then break the condition with
frm. Select the button and readbox-shadowin the Computed pane: its color goes back tooklch(0.75 0.13 40), the plain value. Undo both changes afterward. - A relative color changes only the channel you do math on, so the hover shade keeps the accent’s hue and chroma. Mixing with black lowers the chroma as well, and the shade comes out duller.
Bea’s palette now has a scale, mixed tints, a see-through green, and two derived roles with a fallback.
Next comes the course’s first coding exercise. You edit CSS in the editor on the exercise page and click Run Tests. Automated tests then check your code. When a test fails, its message tells you what to fix before you run again. The tests read your CSS, not how the colors look, so compare shades in your test strip. The Contents tab below the editor explains how coding exercises work.
In Exercise: Mix the Seed Packet Palette, you’ll build a whole seed packet palette from one base color, deriving and mixing every shade it needs.