# Color in UI

> Colour theory for interfaces: hue, saturation and lightness, building a palette and tonal scales, assigning colour roles, the 60-30-10 rule, WCAG contrast, colour blindness and cultural meaning.

Web page: https://odeocreative.me/tutorials/ui-design/color
Author: Hecham Gazhi (https://odeocreative.me)

Track: [UI Design Tutorial](/md/tutorials/ui-design.md)

## What colour does in UI

In interfaces, colour has jobs. It **creates hierarchy** (the accent button stands out), **communicates meaning** (red for errors, green for success), **shows state** (selected, disabled, hovered), **groups** related elements, and **expresses the brand**.

Because colour is so powerful, the best UIs use it with restraint: mostly neutrals, one accent for actions and highlights, and a small set of status colours.

## Colour basics: HSL

It's easier to design with colour when you think in **HSL** instead of hex codes:

| Property | What it is | Range |
| --- | --- | --- |
| Hue | The colour itself, as a position on the colour wheel | 0–360° (0 red, 120 green, 240 blue) |
| Saturation | How vivid or grey the colour is | 0% (grey) – 100% (pure colour) |
| Lightness | How light or dark it is | 0% (black) – 100% (white) |

```css
/* Same hue, different lightness = a tonal scale */
--blue-100: hsl(216 92% 94%);
--blue-500: hsl(216 92% 52%);   /* ≈ #146ef5 */
--blue-700: hsl(216 85% 35%);
```

> Tip: Pure grey (0% saturation) can feel cold and lifeless. Many designers add a tiny bit of the brand hue or a warm tint to neutrals.

## Building a palette

1. **Pick a primary (brand) colour** for actions and key highlights.
2. **Choose neutrals** for text, backgrounds, borders and surfaces — they'll make up most of the UI.
3. **Add semantic colours**: success (green), warning (amber/orange), error (red), info (blue).
4. **Generate tonal scales** for each, usually 50 (lightest) to 900 (darkest), so you have light tints for backgrounds and dark shades for text.
5. **Test contrast** for every text/background combination you plan to use.

## Colour roles

Assign colours to **roles**, not to individual screens. Roles become tokens in your design system and keep usage consistent.

| Role | Typical colour | Used for |
| --- | --- | --- |
| Background | White or very light neutral | Page background |
| Surface | White / neutral-50 | Cards, sheets, menus |
| Text primary | Neutral-900 | Headings, body text |
| Text secondary | Neutral-600 | Descriptions, metadata |
| Border | Neutral-200 | Dividers, input borders |
| Primary action | Brand-500 / 600 | Main buttons, links, selected states |
| Error | Red-600 | Error messages, destructive actions |
| Success | Green-600 | Confirmations |

## The 60-30-10 rule

Borrowed from interior design, the **60-30-10** guideline is a quick way to balance colour: about **60%** dominant colour (usually neutrals/background), **30%** secondary colour (surfaces, sections), and **10%** accent (buttons, highlights).

It's not a strict formula, but it prevents the two most common problems: an accent colour that's everywhere (so nothing stands out) and a UI with no clear dominant tone.

## Contrast and accessibility

Text must contrast enough with its background to be readable — for people with low vision, on a phone in sunlight, or on a cheap screen. The **WCAG 2.2** guidelines define minimum contrast ratios:

| Content | Level AA | Level AAA |
| --- | --- | --- |
| Normal text | 4.5:1 | 7:1 |
| Large text (≥ 24px regular or ≥ 18.66px bold) | 3:1 | 4.5:1 |
| UI components and graphics (borders of inputs, icons) | 3:1 | — |

> Common mistake: Light grey placeholder or helper text on white. It looks elegant in design files and fails contrast for many users. Check it with a contrast tool (Figma plugins, WebAIM Contrast Checker, or browser dev tools).

## Colour blindness

Around 1 in 12 men and 1 in 200 women have some form of colour vision deficiency, most commonly difficulty distinguishing red and green.

- **Never use colour alone** to convey meaning. Add icons, text labels or patterns.
- Error fields: red border **plus** an error icon **plus** a message.
- Charts: use labels, different line styles, or colours that differ in lightness as well as hue.
- Test designs with colour-blindness simulators (available in Figma plugins and browser dev tools).

## Meaning, culture and brand

- Common conventions: red = error/danger/stop, green = success/go, amber = warning, blue = information/links.
- Meanings vary by culture — red signals luck and celebration in China; white is associated with mourning in some cultures. In financial apps, some markets use red for price increases. Know your audience.
- Keep the primary colour for actions, so users learn that "this colour = I can click it".
- Brand colours aren't always suitable for UI. A light yellow brand may need a darker shade for text and buttons to pass contrast.

**Do**

- Use mostly neutrals and one accent.
- Define colours as roles/tokens.
- Check contrast for every text colour.
- Pair colour with icons or text for meaning.

**Don't**

- Use the accent colour for decoration everywhere.
- Rely on red vs green alone.
- Use pure black #000 text on pure white for long reading — a near-black is softer.
- Pick a palette only because it looks good on Dribbble.

## Key takeaways

- Colour creates hierarchy, meaning, state and brand — use it with restraint.
- Think in HSL and build tonal scales (50–900) for brand, neutrals and status colours.
- Assign colours to roles (text, surface, border, action, error) and reuse them.
- Meet WCAG AA contrast: 4.5:1 for normal text, 3:1 for large text and UI components.
- Never use colour as the only signal; consider colour blindness and culture.

## Exercise: Build an accessible palette

1. Pick a brand colour and generate a 50–900 scale (use a tool like Figma's colour picker or an online scale generator).
2. Create a neutral scale with a slight tint of the brand hue.
3. Define 8 roles (background, surface, text primary/secondary, border, action, error, success).
4. Check the contrast of every text role on its background and fix failures.
5. Design one card and one form with only these roles.

## Quiz

1. In the 60-30-10 guideline, what is the 10%?
   - Background
   - **Accent colour** ✓
   - Body text
   - Borders
   - Why: A small amount of accent draws attention to key elements.

2. Minimum WCAG AA contrast for normal text is…
   - 3:1
   - **4.5:1** ✓
   - 7:1
   - 10:1
   - Why: 4.5:1 for normal text; 3:1 for large text and UI components.

3. In HSL, which value controls how vivid or grey a colour is?
   - Hue
   - **Saturation** ✓
   - Lightness
   - Alpha
   - Why: Saturation goes from grey (0%) to the pure colour (100%).

4. An error is shown only with a red border. What's the problem?
   - Red isn't on-brand
   - **Colour-blind users may miss it — colour is the only signal** ✓
   - Borders can't be red
   - Nothing
   - Why: Add an icon and a message so the state is clear without colour.

5. Why keep the primary colour mainly for actions?
   - It saves ink
   - **Users learn that this colour means clickable** ✓
   - Figma requires it
   - It's cheaper
   - Why: Consistent use of the action colour builds a reliable signal.
