Sub topic 7
Expanding each colour into a scale of shades
This chapter assumes you can write CSS custom properties and read HSL values, as covered in the earlier chapters on colour models and on choosing the primary, neutral, and accent colours. You already have one base value for each role. A real interface needs more than that, so here you turn each base colour into a scale of lighter and darker steps.
Why one value per colour is not enough
A single primary blue is enough for a button. It is not enough for the rest of a page. You also need:
- a pale blue for a selected table row or an info banner background,
- a mid-light blue for a border on a focused input,
- a darker blue for a hover state,
- a very dark blue for link text that must be readable on a light page.
If you pick these values ad hoc, you end up with dozens of nearly identical blues scattered through the stylesheet. A scale fixes this. A scale is an ordered set of steps that share a hue and differ mainly in lightness. You decide the steps once and then reuse them everywhere.
Three terms are often mixed up:
| Term | How it is made | Result |
|---|---|---|
| Tint | Mix the colour with white | Lighter, softer |
| Shade | Mix the colour with black | Darker, richer |
| Tone | Mix the colour with grey | Less intense, same lightness range |
In practice, a scale uses all three ideas. Light steps are tints, dark steps are shades, and small saturation changes act like tones.
The standard numbered scale
Most design systems name steps with numbers from 50 to 900. Low numbers are light and high numbers are dark. Step 500 is the base colour, the one you chose in the earlier chapters.
:root {
--primary-50: hsl(220 72% 96%);
--primary-100: hsl(220 76% 91%);
--primary-200: hsl(220 80% 82%);
--primary-300: hsl(220 80% 71%);
--primary-400: hsl(220 80% 60%);
--primary-500: hsl(220 80% 50%);
--primary-600: hsl(220 80% 41%);
--primary-700: hsl(220 80% 33%);
--primary-800: hsl(220 76% 25%);
--primary-900: hsl(220 72% 17%);
}The numbering is a convention, not a rule of CSS. Its value is that the same number means the same job in every colour. Once 500 is "the base" and 700 is "dark enough for text on white" in your primary scale, the same should hold for the accent and neutral scales. Ten steps is a good default. Fewer than seven makes it hard to find a step for subtle backgrounds and strong text. More than eleven makes it hard to tell neighbouring steps apart, so people choose inconsistently.
What each range is for
A scale is easier to use when each range has a purpose.
| Steps | Typical use |
|---|---|
| 50 to 100 | Page or section backgrounds, selected rows, subtle banners |
| 200 to 300 | Borders, dividers, disabled fills |
| 400 to 500 | Solid fills such as buttons and badges, icons |
| 600 to 700 | Hover and active states, links, text on light backgrounds |
| 800 to 900 | Headings, text on tinted backgrounds, dark-theme surfaces |
Treat the table as a starting point. Contrast checks in the next chapter will move some of these assignments.
Generating a scale with HSL
Because the palette is written in HSL, the recipe is simple. Keep the hue fixed, step the lightness along a ladder, and nudge the saturation at the extremes.
Writing ten lines by hand is fine once. If you maintain three or four scales, generate them. The following Node.js script prints a complete scale for any hue and saturation.
const steps = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900];
const lightness = [96, 91, 82, 71, 60, 50, 41, 33, 25, 17];
const saturationFactor = [0.9, 0.95, 1, 1, 1, 1, 1, 1, 0.95, 0.9];
function buildScale(name, hue, saturation) {
const lines = steps.map((step, i) => {
const s = Math.round(saturation * saturationFactor[i]);
return ` --${name}-${step}: hsl(${hue} ${s}% ${lightness[i]}%);`;
});
return lines.join("\n");
}
const scales = [
["primary", 220, 80],
["neutral", 220, 15],
["accent", 35, 95],
];
const body = scales.map(([name, hue, sat]) => buildScale(name, hue, sat)).join("\n\n");
console.log(":root {\n" + body + "\n}");Run it with node scale.js and paste the output into your stylesheet. The primary scale matches the CSS block above. The script produces hsl(220 72% 96%) for step 50 and hsl(220 80% 50%) for step 500.
Two design choices are in this code:
- The lightness ladder is not evenly spaced. The gaps are about 9, 9, 11, 11, 10, 9, 8, 8, 8 points. The light end is slightly compressed because very pale colours are hard to tell apart on a screen. Even spacing in numbers does not give even spacing to the eye.
- Saturation drops at both ends. A fully saturated colour at 96% lightness looks faintly neon, and at 17% lightness it looks muddy. Reducing saturation a little keeps the extremes calm.
Scales for each role
The same method gives different results for each colour role.
Primary. Use the full ten steps. The primary appears as fills, links, focus rings, and tinted backgrounds, so it needs the widest range.
Neutral. Use the same ladder with low saturation, tinted toward the primary hue. Neutrals do the most work on a page, because they supply text, surfaces, and borders. The neutral scale usually needs more usable steps at the extremes than other scales. Backgrounds in the 50 to 100 range and text in the 800 to 900 range differ only slightly in lightness from their neighbours, and that difference matters. The earlier palette used hand-picked values such as --neutral-50 and --neutral-900. A generated scale fills the gaps between them.
Accent. You can use fewer steps. An accent used "sparingly" often needs only a pale tint for a highlight background, the base for a badge or call-to-action, and a dark step for hover. If you generate all ten, you do not have to use all ten. Unused steps cost nothing in CSS.
Where HSL lightness misleads you
HSL is convenient, but its lightness value is not the same as how light a colour looks. This causes the most common scale errors.
Compare two colours with the same HSL lightness of 50%:
hsl(220 80% 50%)is a strong blue.hsl(55 80% 50%)is a bright, light-looking yellow.
Both have L = 50%, but the yellow reflects far more light. Its relative luminance, the measure used by WCAG, is several times higher than the blue's. So the same step number does not give the same contrast against white across different hues.
This has practical consequences:
- Your accent scale will not line up with your primary scale. The orange accent at step 500 is
hsl(35 95% 50%), and it has much lower contrast against white than the blue primary at step 500. White text on it may fail. - Equal numbers do not mean equal accessibility. You cannot assume that "700 is dark enough for text" holds for every hue without checking.
- Yellows and greens need darker text steps. For these hues, step 800 or 900 is often the first step that reaches readable contrast on light backgrounds.
Fix this by measuring. The contrast function from the Topic Spine computes luminance directly, so you can check candidate steps:
function channel(value) {
const s = value / 255;
return s <= 0.04045 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4);
}
function luminance([r, g, b]) {
return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b);
}
function contrastRatio(colorA, colorB) {
const a = luminance(colorA);
const b = luminance(colorB);
const lighter = Math.max(a, b);
const darker = Math.min(a, b);
return (lighter + 0.05) / (darker + 0.05);
}
console.log(contrastRatio([0, 0, 0], [255, 255, 255])); // 21The next chapter uses this function in depth. For now, understand why you need it. The scale gives you candidate colours, and the contrast ratio tells you which ones you can use for text.
Perceptually even scales
If you generate many scales and want steps that look consistent across hues, you can work in a perceptual colour space such as OKLCH, where lightness is closer to how humans see it. CSS supports oklch(), so a scale can be written directly:
:root {
--primary-500: oklch(0.55 0.2 260);
--primary-700: oklch(0.42 0.17 260);
}The trade-off is familiarity. HSL is easier to read and adjust by hand, and the tutorial's palette uses it. OKLCH gives more predictable lightness across hues but has values that are harder to guess, and some colours fall outside the displayable range and get clipped. For a small palette with three hues, HSL plus contrast checks is enough. For a large system with many hues, consider OKLCH.
Deriving states from the scale
Once you have a scale, interactive states become simple steps, not new colours:
.button {
background: var(--primary-500);
color: white;
}
.button:hover {
background: var(--primary-600);
}
.button:active {
background: var(--primary-700);
}
.button:focus-visible {
outline: 3px solid var(--primary-300);
outline-offset: 2px;
}This pattern gives consistent behaviour across components. Hover is always one step darker, and active is always two. A reviewer can check the rule without opening the browser.
Common mistakes
- Changing hue between steps. Shifting hue slightly is a legitimate technique, but doing it by accident makes the scale look like several different colours. Keep the hue fixed unless you have a reason.
- Skipping the visual check. Numbers can look even and still produce a visible jump. Put all steps side by side as swatches and look at them.
- Using step numbers as meaning.
--primary-600says nothing about its job. The semantic layer, covered in a later chapter, names the job, for example--color-button-hover. - Generating too many steps. A forty-step scale cannot be used consistently.
- Forgetting the neutral scale. Teams often build a careful primary scale and leave greys as unrelated hex values. The page then looks disjointed.
Summary
A scale expands one base colour into ordered steps that share a hue. Use ten steps numbered 50 to 900, with 500 as the base. Generate them by fixing the hue, stepping the lightness along a ladder, and easing the saturation at the ends. Give each range a job, but verify with measured contrast, because HSL lightness does not match perceived brightness across hues.
Exercise
Your accent colour is hsl(35 95% 50%) and your primary colour is hsl(220 80% 50%). A teammate says, "Both are step 500, so white text will have the same contrast on both." Explain why this is unreliable, and say what you should do.
Show answer
HSL lightness is not perceived brightness. Both colours have 50% lightness, but orange reflects much more light than blue, so its relative luminance is much higher and its contrast against white is much lower. The blue is about 5.6:1 against white, which passes 4.5:1. The orange is well below that and fails for normal text. Compute the contrast ratio with the luminance formula for each candidate pair, and choose a darker orange step or dark text on the orange background where the ratio is below 4.5.
Exercise
You modify the buildScale script so that saturation stays at 80% for every step. The darkest step now looks muddy and the lightest looks slightly neon. Which array in the script do you change to fix this, and in which direction?
Show answer
Change the saturationFactor array. Use values below 1 for the first and last entries, such as 0.9, so the lightest and darkest steps are less saturated than the middle steps.