Sub topic 13
Building a cohesive palette step by step
This chapter assumes you can already read HSL and HSV values, and that you know the harmonies (complementary, analogous, triadic), tints, tones and shades, and value contrast from earlier chapters. Here you combine them into one repeatable process. The goal is a small palette where every color has a job and the colors visibly belong together.
Why palettes fall apart
Most palettes that look "off" fail in one of three ways:
- Too many hues. Each color was picked independently, so nothing connects them.
- Uncontrolled saturation. One fully saturated color beside several muted ones makes the saturated one scream.
- Value clumping. Colors with similar value look flat. Text becomes hard to read and nothing leads the eye.
The fix is to decide hue, saturation, and value in separate passes, in that order. Each pass narrows the choices for the next one.
Step 1: Pick one base hue
Start with a single hue that carries the identity of the project. It may come from a logo, a photo, or the mood you want (blue for calm, orange for energy). Write it down as a hue angle, for example 210 degrees for a medium blue.
Do not choose the final shade yet. At this stage you only need the hue. Everything else in the palette will be derived from this number, which is why the CSS example in this chapter stores it in one variable.
Step 2: Choose a harmony for supporting hues
Use the color wheel to decide how many other hues you need and where they sit.
| Harmony | Hue offsets from base | Typical effect | Risk |
|---|---|---|---|
| Monochromatic | none (base only) | Calm, unified | Can feel flat without strong value changes |
| Analogous | about -30 and +30 | Soft, related | Little emphasis for calls to action |
| Complementary | +180 | Strong accent against the base | Clashes if both are equally saturated |
| Split-complementary | +150 and +210 | Contrast with less tension | Needs careful value control |
| Triadic | +120 and +240 | Lively, varied | Easy to overload |
For most interfaces, a good default is one base hue, one accent hue, and neutrals. The accent is often the complement or a split-complement. The neutrals are not a new hue. You take the base hue and drop its saturation close to zero.
Tinted neutrals matter. A gray with a slight tilt toward 210 looks like it belongs with a blue brand color. A pure gray (zero saturation) can look disconnected next to it.
Step 3: Set a saturation budget
Saturation is the property most likely to get out of hand, so assign it by role before you assign anything else. A workable budget:
- Neutrals (backgrounds, borders, body text): saturation near 2 to 15 percent.
- Base color (main brand surfaces, links, primary buttons): the highest saturation you will allow in large areas, often 60 to 85 percent.
- Accent (one call to action, highlights): high saturation, but used on small areas only.
- Muted variants (secondary buttons, disabled states, charts in the background): around 20 to 40 percent.
The rule behind the budget is that visual weight comes from saturation times area. A small patch of saturated orange can balance a large patch of muted blue. Two large saturated areas compete.
Step 4: Assign values by role
Now decide how light or dark each role is. Think in terms of a value ladder instead of individual colors:
- Page background: lightest (or darkest, in a dark theme).
- Surfaces such as cards: one small step away from the background.
- Borders and dividers: a small step beyond the surface.
- Base color: a mid-to-dark value that can hold white text or sit clearly on the background.
- Body text: the extreme opposite of the background.
If you convert the design to grayscale, you should still be able to tell these roles apart. If two roles collapse into the same gray, they need more value separation. Hue difference alone will not save them, and it fails entirely for readers with color vision deficiency.
Remember from the earlier chapter on perceived lightness that equal numeric value does not look equally light. A yellow and a blue with the same HSV value will not look equally bright. When you place different hues on the same role, adjust the numbers until they look right to the eye and meet the contrast checks in step 5.
Step 5: Test contrast and adjust
Check every foreground and background pair that actually appears together: body text on background, text on cards, white text on the base color, text on the accent. WCAG (the Web Content Accessibility Guidelines) sets 4.5:1 as the minimum for normal-size text and 3:1 for large text and interface components.
When a pair fails, change value first. Changing hue to fix contrast usually breaks the harmony you chose in step 2. If the pair still fails after a value change, lower the saturation of the larger area.
Putting it together in CSS
CSS lets you store the hue once and derive the rest. This example applies steps 1 through 4: one base hue, a complementary accent, tinted neutrals, and values chosen by role.
:root {
--hue: 210;
--accent-hue: calc(var(--hue) + 180);
/* Neutrals: the base hue at very low saturation */
--bg: hsl(var(--hue) 20% 98%);
--surface: hsl(var(--hue) 20% 94%);
--border: hsl(var(--hue) 15% 82%);
--text: hsl(var(--hue) 30% 12%);
/* Base color family */
--brand: hsl(var(--hue) 80% 40%);
--brand-hover: hsl(var(--hue) 80% 32%);
--brand-muted: hsl(var(--hue) 30% 55%);
/* Accent: used on small areas only */
--accent: hsl(var(--accent-hue) 90% 55%);
}
body {
background: var(--bg);
color: var(--text);
}
.card {
background: var(--surface);
border: 1px solid var(--border);
}
.button-primary {
background: var(--brand);
color: white;
}
.button-primary:hover {
background: var(--brand-hover);
}Changing --hue to 150 or 330 re-themes the whole page. The saturation and lightness numbers keep the same structure, so the roles stay legible. You will still need to retest contrast after each change, because the same lightness percentage in HSL looks different at different hues.
Generating and testing a palette in Python
The same process works in code. This script builds roles from a base hue using HSV, then checks contrast with the WCAG formula.
import colorsys
BASE_HUE = 210
def hex_color(hue_deg, s, v):
r, g, b = colorsys.hsv_to_rgb((hue_deg % 360) / 360, s, v)
return "#{:02x}{:02x}{:02x}".format(
round(r * 255), round(g * 255), round(b * 255)
)
def luminance(hex_value):
r, g, b = (int(hex_value[i:i + 2], 16) / 255 for i in (1, 3, 5))
def linear(c):
return c / 12.92 if c <= 0.04045 else ((c + 0.055) / 1.055) ** 2.4
return 0.2126 * linear(r) + 0.7152 * linear(g) + 0.0722 * linear(b)
def contrast(a, b):
lighter, darker = sorted((luminance(a), luminance(b)), reverse=True)
return (lighter + 0.05) / (darker + 0.05)
palette = {
"surface": hex_color(BASE_HUE, 0.04, 0.98),
"brand": hex_color(BASE_HUE, 0.80, 0.80),
"accent": hex_color(BASE_HUE + 180, 0.85, 0.95),
"text": hex_color(BASE_HUE, 0.30, 0.15),
}
for name, value in palette.items():
print(f"{name:8} {value}")
for fg, bg in [("text", "surface"), ("text", "accent")]:
ratio = contrast(palette[fg], palette[bg])
status = "pass" if ratio >= 4.5 else "FAIL"
print(f"{fg} on {bg}: {ratio:.1f}:1 {status}")With HSV, the brand color above works out to #297acc. The script checks the pairs that appear in the design, which are text on surface and text on accent. Add white on brand to the list and see what happens: it sits close to the 4.5:1 line, so a small value drop may be needed. That kind of borderline pair is why you test instead of trusting the numbers you chose.
Common errors
- Choosing accents first. An accent only reads as an accent against a calm base. Set the base and neutrals before the accent.
- Reusing one saturation everywhere. If every color has 80 percent saturation, nothing stands out. Vary saturation by role.
- Pure gray neutrals with a vivid brand. The gray looks dull and unrelated. Tint neutrals with the base hue.
- Fixing contrast by changing hue. This breaks the harmony. Adjust value first.
- Skipping the grayscale check. Hue differences hide weak value structure. Desaturate a screenshot and look.
Summary of the process
You choose hue once, spread supporting hues with a harmony, budget saturation by role, lay out values as a ladder, and then test and adjust. Each decision constrains the next, which is what keeps the result cohesive.
Exercise
You build a palette on hue 30 (orange) with a complementary accent. The accent and the base color both have saturation 90 percent and both cover large areas of the page, and the design feels chaotic. Using the five steps, which step do you revisit, and what do you change?
Show answer
Revisit step 3, the saturation budget. The accent hue is 210 (30 + 180). Keep the base color's saturation as the high one for large areas, or lower it, and reduce the saturation of whichever color covers more area, for example to 30 to 40 percent. Keep the accent's high saturation but limit it to small elements such as one button. Then retest contrast in step 5 after changing saturation.
Exercise
A card with text in your palette fails the 4.5:1 contrast check. The hues follow a good triadic harmony. Should you change the text hue or its value first, and why?
Show answer
Change the value first. Making the text darker, or the card lighter, raises contrast without moving any color off its chosen angle on the wheel, so the triadic harmony stays intact. Changing hue to fix contrast would break the harmony and may not even help, since contrast depends mostly on relative luminance.