Sub topic 8
Complementary colours: opposites on the wheel
This chapter assumes you can describe a colour by hue, saturation, and lightness (HSL), and that you have seen a colour wheel. You should also know that the RYB (paint) and RGB (screen) wheels place some hues differently. The chapter covers what a complement is, how to calculate one, how to use it, and where it goes wrong.
What a complement is
A complementary pair is two hues that sit directly opposite each other on the colour wheel. On a 360-degree wheel, that means the hues are 180 degrees apart.
Opposite hues give the strongest hue contrast a wheel can offer. Placed side by side, each colour makes the other look more intense. A small amount of a complement in a mostly blue layout draws the eye at once.
The pair is useful for one more reason. If you mix two complements as pigments, they cancel each other and produce a neutral grey or brown. This is why complements are used to dull a colour. Adding a little orange to a blue gives a muted, natural blue. It does not give a bright, different blue.
The complement depends on the wheel
"Opposite" has no single answer, because the wheels are built differently. The pair you get depends on the wheel you use.
| Base colour | RYB complement (painters) | RGB/HSL complement (screens) |
|---|---|---|
| Red | Green | Cyan |
| Yellow | Purple (violet) | Blue |
| Blue | Orange | Yellow |
| Orange | Blue | Azure (light blue) |
Both columns are valid for their own medium. Traditional painting teaches the RYB pairs: red and green, blue and orange, yellow and purple. Code and screen design use the RGB-based HSL wheel, where red's opposite is cyan and blue's opposite is yellow.
For screen work, HSL arithmetic is the practical choice. Your colour picker, your CSS, and your display all work in RGB, so the HSL wheel describes what you will see.
Calculating a complement
On the HSL wheel, add 180 to the hue and wrap the result into the range 0 to 359. Saturation and lightness stay the same unless you change them on purpose.
In CSS, calc() does the addition. Because the hue is stored in a custom property, changing one value updates the whole pair.
:root {
--base-hue: 210;
}
.base {
background: hsl(var(--base-hue) 65% 45%);
}
.complement {
background: hsl(calc(var(--base-hue) + 180) 65% 45%);
}A base hue of 210 is a mid blue. Adding 180 gives 390. CSS accepts hue values above 360 and wraps them, so 390 is read as 30, a warm orange. The pair is blue and orange.
In JavaScript, wrap the hue yourself, because other code may use the number before CSS sees it. The modulo step below keeps the result between 0 and 359, including when an offset is negative.
function harmony(baseHue, offsets, saturation = 65, lightness = 50) {
return offsets.map((offset) => {
const hue = (((baseHue + offset) % 360) + 360) % 360;
return `hsl(${hue} ${saturation}% ${lightness}%)`;
});
}
const complementary = harmony(210, [0, 180]);
console.log(complementary);The output is ["hsl(210 65% 50%)", "hsl(30 65% 50%)"]. The double modulo is needed because JavaScript's % keeps the sign of the left operand. For example, -30 % 360 is -30, not 330. Adding 360 and taking the remainder again fixes this.
The problem with equal strength
Two complements at the same saturation and lightness compete for attention. Put them next to each other at full strength and you get an effect called vibration. The edge between them seems to shimmer, and the text becomes hard to read.
The complementary pair in the CSS example above has this risk. Both colours have the same saturation and similar lightness. That is fine for two swatches, but it is a poor choice for a text block on a coloured background.
Using complements well
The usual fix is to give the two colours different jobs, so they are not equal partners.
- Pick a dominant colour. Use one hue for most of the area, such as backgrounds and large surfaces. A 60-30-10 split is a common guide, and the complement belongs in the 10.
- Use the complement as an accent. Buttons, links, badges, and highlights are good places for it. The contrast makes the important element stand out.
- Vary lightness and saturation. Make the accent more saturated and the dominant colour calmer. Or make one light and the other dark. Different lightness values also help with readability.
- Add neutrals. White, off-white, grey, or near-black space gives the pair room. Neutrals also carry most of the text.
Here is a small example that applies these rules. The blue is the dominant hue, with a deep tint for the surface and a pale tint for the page. The orange is saturated and used only on the call to action.
:root {
--base-hue: 210;
}
body {
background: hsl(var(--base-hue) 30% 96%);
color: hsl(var(--base-hue) 40% 15%);
}
.header {
background: hsl(var(--base-hue) 65% 30%);
color: white;
}
.cta {
background: hsl(calc(var(--base-hue) + 180) 90% 50%);
color: hsl(var(--base-hue) 40% 10%);
}The call-to-action button is the only warm element on the page, so it is the first thing a visitor notices. If the header were also orange, the button would lose that effect.
Accessibility and colour-blindness
A complementary pair can fail two accessibility checks.
- Contrast ratio. Two complements with the same lightness can have a very low contrast ratio even though their hues are far apart. A blue and an orange at 50% lightness look different, yet text in one on the other may fall short of the WCAG minimum of 4.5:1 for body text. Check the ratio with a contrast checker. Do not rely on your eye.
- Red-green confusion. The traditional RYB pair of red and green is the worst case for the most common forms of colour-blindness. Someone with red-green colour vision deficiency may see the two as nearly the same. Blue and orange is a much safer pair, because the difference in both hue and lightness survives.
Never use a complementary pair as the only way to show a status, such as red for an error and green for success. Add an icon, a label, or a pattern as well.
Common mistakes
- Mixing wheels. Calculating a complement in HSL and expecting the RYB result, or the other way around.
- Equal weight. Giving both hues the same area, which makes the design noisy.
- Text on a vibrating pair. Setting orange text on a blue background at similar lightness.
- Forgetting the wrap. Writing a hue of 390 or -30 into a system that does not wrap it. CSS does, but many canvas libraries and colour functions do not.
- Treating 180 degrees as exact. The rule gives a starting point. Many designers nudge the accent by 10 to 20 degrees to get a pair that looks better, and that is acceptable.
Quick reference
| Task | Method |
|---|---|
| Find the complement in HSL | Add 180 to the hue, then wrap with modulo 360 |
| Soften a pair | Lower the saturation of the larger area |
| Avoid vibration | Change the lightness of one colour |
| Make an accent stand out | Keep it to about 10% of the area |
| Stay accessible | Check contrast ratios and avoid red-green as the only signal |
Exercise
A base colour has the hue 300 in HSL. What is its complement, and what does the JavaScript expression (((300 + 180) % 360) + 360) % 360 return? Why does the code include the second + 360 and % 360?
Show answer
The complement is hue 120, a green, which is opposite magenta on the HSL wheel. The expression returns 120, because 480 % 360 is 120, adding 360 gives 480, and 480 % 360 is 120 again. The second + 360 and % 360 do not change this result. They are needed for negative values, because JavaScript's % can return a negative number, and the extra step brings it back into the range 0 to 359.
Exercise
You are designing a page with a deep blue header and an orange sign-up button. A colleague suggests making the page background orange too, so that the colours are balanced. Give two reasons to refuse, and say what you would do instead.
Show answer
First, equal areas of two complements compete for attention and can cause vibration at their edges, and the orange button would no longer stand out. Second, large saturated areas make text harder to read and may fail the 4.5:1 contrast ratio. Instead, use a pale tint or a neutral for the background, keep the blue as the dominant colour, and reserve orange for the button, which follows the 60-30-10 proportion.