Sub topic 3
Choosing Your Primary Colour
This chapter assumes you can write basic CSS, read hex and RGB values, and know what HSL's hue, saturation and lightness mean from the previous chapter. You also need a stylesheet you can edit and view in a browser. By the end you will be able to pick a primary colour on purpose, adjust it until it works as a button and link colour, and record it as the middle step of a scale.
What the primary colour has to do
The primary colour is the one that makes your interface recognisable. It appears on the main call-to-action button, on links, on selected states such as the active tab, and often in the logo. It is not the colour that covers the most area. Neutrals do that, as the 60-30-10 chapter explains later.
Because it appears in many places, the primary colour has to satisfy several constraints at once:
- It should fit the brand or the purpose of the site.
- It should stand out from the neutral background and text.
- It should carry text, either as a background behind white text or as a text colour on a light background.
- It should be easy to extend into lighter and darker shades.
A colour that looks good in a logo can fail the last three. Choosing a primary colour means picking a hue that suits the site, then tuning saturation and lightness until it works in the interface.
Step 1: Start from meaning or from an existing brand
If the organisation already has a brand colour, use it as the starting hue and skip the rest of this section. You can usually adjust the saturation and lightness for the web, but changing the hue makes the site look off-brand.
If there is no brand colour, choose a hue that matches the tone of the product. These associations are common in Western interfaces. They are tendencies, not rules, and they vary by culture and industry.
| Hue family | Common association | Typical use |
|---|---|---|
| Blue | Trust, calm, competence | Finance, healthcare, productivity tools |
| Green | Growth, health, nature | Sustainability, wellness, money apps |
| Red | Urgency, energy, danger | Food, media, sales |
| Orange and yellow | Warmth, optimism | Consumer and community products |
| Purple | Creativity, premium feel | Creative tools, education |
| Black or grey | Neutral, sophisticated | Fashion, editorial, luxury |
Two cautions apply here. First, red is also the colour of errors, so a red primary makes error messages harder to tell apart. If you choose red, give errors a different treatment, such as an icon and text. Second, blue is the default for so many products that it carries little distinction. That is not a reason to avoid it, but a distinctive hue gets noticed more.
Also look at your competitors. If every site in your category uses the same blue, a different hue helps you stand out, as long as it still suits the product.
Step 2: Fix the hue and tune saturation and lightness
In HSL, the hue is a number from 0 to 360 on the colour wheel. Pick it once and keep it for every shade of the primary. Saturation and lightness are what you adjust.
- Saturation controls how vivid the colour is. High saturation (80-100%) looks energetic and works well for buttons. Low saturation (30-50%) looks muted and professional. Fully saturated colours often look harsh on large areas and can vibrate against neighbouring colours.
- Lightness controls how close the colour is to white or black. For a mid-tone primary, aim for roughly 40-55%. Much lighter and white text on it becomes unreadable. Much darker and it blends into dark text and borders.
A practical starting point is a saturation of 70-85% and a lightness of 45-55%. The palette from the topic spine uses this range:
:root {
/* Primary: one hue, varied lightness */
--primary-100: hsl(220 80% 94%);
--primary-500: hsl(220 80% 50%);
--primary-700: hsl(220 80% 34%);
}All three share hue 220, which is a blue. --primary-500 is the brand-recognisable middle step, and it is the colour you tune in this chapter. The 100 and 700 steps are previews of the scale you will build later.
Equal lightness does not mean equal brightness
HSL lightness is a mathematical value, not a perceptual one. At the same saturation and lightness, yellow looks much brighter than blue. For example, hsl(50 95% 50%) is a very bright yellow, while hsl(220 80% 50%) is a medium blue, even though both have lightness 50%.
This matters for text. White text on a mid-lightness blue is readable. White text on a mid-lightness yellow is not. If your hue is in the yellow-to-green range, you will need either a much darker primary or dark text on top of it.
Step 3: Test the colour in the roles it will play
Before you commit, check the primary colour in the two roles it must handle:
- As a background, such as a button, with white (or dark) text on top.
- As a foreground, such as link text, on your light page background.
WCAG, the Web Content Accessibility Guidelines, sets minimum contrast ratios for these pairs: 4.5:1 for normal text and 3:1 for large text and interface components. You will study the formula properly in the contrast chapter. For now, this script lets you test a candidate. It converts an HSL value to RGB, then applies the WCAG relative luminance formula.
function hslToRgb(h, s, l) {
s /= 100;
l /= 100;
const k = (n) => (n + h / 30) % 12;
const a = s * Math.min(l, 1 - l);
const f = (n) =>
l - a * Math.max(-1, Math.min(k(n) - 3, 9 - k(n), 1));
return [f(0), f(8), f(4)].map((v) => Math.round(v * 255));
}
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);
return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);
}
const white = [255, 255, 255];
const candidates = {
"primary-500": hslToRgb(220, 80, 50),
"primary-700": hslToRgb(220, 80, 34),
};
for (const [name, rgb] of Object.entries(candidates)) {
const ratio = contrastRatio(rgb, white);
console.log(name, rgb, ratio.toFixed(2), ratio >= 4.5 ? "passes" : "fails");
}Run it with Node.js. Both candidates should pass against white: primary-500 at roughly 5.6:1 and primary-700 at roughly 9.4:1.
That result tells you how to assign the steps:
--primary-500works as a button background with white text. It clears 4.5:1, though not by much, so a slightly lighter or less saturated version would fail.--primary-700is the better choice for link text. Links are small and thin, so the extra margin helps, and it also stays readable on tinted surfaces.
This is why the topic spine's semantic layer uses --color-link: var(--primary-700) and --color-button-bg: var(--primary-500). One primary hue ends up with two different jobs at two different lightness values.
The decision process
The steps above form a loop. You pick a hue, tune it, test it, and adjust until the tests pass.
Edge cases and common mistakes
The hue shifts when you lower lightness. Browsers keep the hue number, but the colour can look different at the extremes. A very dark blue can look almost black, and a very light one can look grey. Check each step by eye as well as by number.
A brand colour fails the test. Suppose the brand colour is a light orange that fails against white text. Keep the brand colour for logos and large decorative areas, where contrast rules are looser. Then define a darker variant of the same hue for buttons and links. Document that the two are deliberately different.
Pure, fully saturated colours. A value such as hsl(220 100% 50%) is vivid, but on a large area it tires the eye and can look unprofessional. Lower the saturation a little unless the brand demands it.
Relying on hue alone. Roughly 1 in 12 men has some form of colour-vision deficiency. A primary colour that is the only signal of an action, such as a blue link with no underline in body text, can be missed. Pair colour with another cue, such as an underline, an icon or a label.
Choosing in isolation. A primary colour looks different next to different neutrals. Always judge it against your actual background and text colours, not on a blank canvas. You will build those neutrals in the next chapter.
What you should have at the end
After this chapter you should have:
- A single hue number for the primary colour.
- A tuned
--primary-500that passes 4.5:1 with white text. - A rough idea of a darker step, such as
--primary-700, for link text. - A note of why you chose the hue, which helps whoever maintains the palette later.
The next chapters build on this. The neutrals are tinted toward your primary hue, and the accent is derived from it using the hue wheel. A well-chosen primary makes both easier.
Exercise
A designer proposes hsl(50 95% 50%), a bright yellow, as the primary colour for button backgrounds with white text. Will it pass the 4.5:1 requirement, and what would you do?
Show answer
It will fail. Yellow has a high relative luminance, so against white the contrast ratio is only about 1.5:1. There are two fixes. Keep the yellow but put dark text, such as --neutral-900, on the button, which gives a ratio well above 4.5:1. Or darken the colour until white text passes, which pushes it toward brown or olive and may no longer suit the brand. In both cases, check the pair with a contrast calculation instead of judging by eye.
Exercise
Using the script in this chapter, you change the primary to hsl(220 80% 60%). It fails against white text at 4.5:1. Name two changes that could bring it back above the threshold, and say which step of the scale you would use for link text.
Show answer
Lower the lightness (for example back to 50% or below) or lower the saturation slightly. Lowering lightness is the more reliable change, because it directly reduces the colour's luminance difference from white. For link text, use a darker step such as primary-700, because links are small and thin and benefit from a larger contrast margin than a button background does.