Sub topic 3
Choosing your primary colour
This chapter assumes you know basic HTML and CSS, can read hex and RGB values, and can edit a stylesheet and view it in a browser. It also assumes you have met HSL (hue, saturation, lightness) in the previous chapter. Here you will pick the one colour that identifies your site and write it down as a few usable values.
What the primary colour does
The primary colour is the colour people associate with your site. It appears on the elements that matter most: main buttons, links, active navigation items, and focus rings. Because it carries this meaning, you choose it before the neutral and accent colours. Both of those are derived from it.
A good primary colour does three jobs:
- It fits the brand or the mood of the product.
- It stands out against your background, so interactive elements are easy to find.
- It works at several lightness levels, because you will later need lighter and darker versions of it.
Pick a hue first
Start with the hue, which is the angle on the colour wheel from 0 to 360. Hues carry common associations, though these vary by culture and industry.
| Hue range | Colour | Common association |
|---|---|---|
| 0–20, 340–360 | Red | Urgency, energy, danger |
| 20–50 | Orange, amber | Warmth, friendliness |
| 90–150 | Green | Growth, health, success |
| 180–250 | Cyan to blue | Trust, calm, technology |
| 260–300 | Purple | Creativity, premium feel |
If your organisation already has a logo, take the hue from it. If not, choose from the table, then look at competitors' sites so you do not copy the most common choice by accident.
Set saturation and lightness
Once you have a hue, set the other two HSL values.
- Saturation controls intensity. Values around 60–90% suit buttons and links. Very high values can look harsh on large areas.
- Lightness controls how bright the colour is. Around 40–55% gives a mid-tone that has room to become both lighter and darker.
Use this mid-tone as your base step, called --primary-500 in this tutorial. Test it in the two places it will be used most:
- As a button background with white text on top.
- As link text on your page background.
These two uses pull in opposite directions. A light, bright primary suits a button but may be hard to read as text on white. This is why the palette later includes a darker step for links. Chapter 8 covers the exact contrast calculation. For now, keep the base lightness at or below about 50% so white text has a good chance of being readable.
Write the primary as a small set of values
Choose a hue of 220 (a blue). You can store the base step and two supporting steps as custom properties:
:root {
--primary-100: hsl(220 80% 94%);
--primary-500: hsl(220 80% 50%);
--primary-700: hsl(220 80% 34%);
}All three share the hue 220 and the saturation 80%. Only the lightness changes: 94% for tinted backgrounds, 50% for buttons, and 34% for link text and hover states. Keeping the hue fixed is what makes them read as one colour family.
Try it in a page
Put the values to work in a small page so you see them in context:
.button {
background: var(--primary-500);
color: white;
border: 0;
padding: 0.6rem 1.2rem;
border-radius: 6px;
}
.button:hover {
background: var(--primary-700);
}
a {
color: var(--primary-700);
}
.notice {
background: var(--primary-100);
}Open the page and look at the button, a link, and the notice box together. If the button feels weak, raise the saturation a little. If the page feels loud, lower it.
Common mistakes
- Picking a colour only for how it looks on a swatch. A swatch has no text on it. Always judge the colour with real text and real components.
- Choosing a base that is too light or too dark. At 90% lightness there is no room for lighter tints. At 15% there is no room for darker shades.
- Using the primary everywhere. If every element is blue, nothing stands out. Keep it for actions and key navigation.
- Changing hue between steps. Shifting the hue slightly in each step can look inconsistent unless you do it deliberately.
Where this leads
The hue you pick here is the input for the next steps. The neutral colours are tinted toward it, and the accent colour is found by moving around the wheel from it. Choose carefully now, and later chapters become mechanical.
Exercise
A site uses the primary colour hsl(150 70% 85%) for its main button, with white text. Name two problems with this choice and one change that fixes them.
Show answer
The lightness of 85% is too high. White text on such a pale green will be hard to read, and there is little room to make lighter tints. Lowering the lightness to about 35–45% fixes both, because white text then stands out and the palette can still include lighter tints and darker shades.
Exercise
You change the hue of --primary-700 from 220 to 200 but leave --primary-500 at 220. What is the likely visible effect?
Show answer
The two steps no longer look like one colour family. Hover states and links will appear to shift to a different, greener blue, which looks inconsistent unless it was intended.