Sub topic 9
Adding success, warning, and error colours
Status colours tell users whether something worked, needs attention, or failed. This chapter adds them to the palette you built in the earlier chapters. It assumes you can write CSS custom properties, read HSL values, and check contrast ratios with the WCAG formula from the contrast chapter.
Why status colours need their own roles
Your primary colour carries the brand, and your accent draws attention to one thing. Neither should also mean "error". If your primary is red and the same red marks a failed form field, users cannot tell a brand element from a problem.
Status colours are a fourth group that sits beside the three core roles. Each one has a conventional meaning that users already know from other software:
| Status | Usual hue | Typical use |
|---|---|---|
| Success | Green, around 140 | Saved, paid, verified |
| Warning | Amber, around 40 | Needs review, expiring soon |
| Error | Red, around 0 to 10 | Failed, invalid, destructive |
Keep these hues close to convention. A purple error message forces users to learn something new at the moment they are least patient.
Build a small scale for each status
A status colour is rarely used at one lightness. You need at least three steps:
- A light tint for the background of a message box.
- A mid step for icons and borders.
- A dark step for text on the light tint.
Use the same HSL approach as the other scales. Keep the hue fixed and change lightness.
:root {
/* Success */
--success-100: hsl(140 55% 92%);
--success-500: hsl(140 60% 36%);
--success-700: hsl(140 65% 20%);
/* Warning */
--warning-100: hsl(40 95% 90%);
--warning-500: hsl(38 92% 46%);
--warning-700: hsl(32 90% 24%);
/* Error */
--error-100: hsl(5 85% 94%);
--error-500: hsl(5 75% 46%);
--error-700: hsl(5 80% 28%);
}Note that the warning hue shifts slightly (40, 38, 32) as it darkens. Dark amber at a constant hue of 40 looks muddy and olive. Moving the hue a little toward orange keeps it clean.
Do not rely on colour alone
About 1 in 12 men has some form of colour-vision deficiency, and red and green are the pair most often confused. WCAG success criterion 1.4.1 (Use of Color) also says colour must not be the only way to convey information.
Pair every status colour with a second signal:
- An icon, such as a check, a triangle, or a cross.
- A text label, such as "Error:" at the start of the message.
- For form fields, a message below the field and not only a red border.
Check contrast for each pairing
Each status colour is used in specific pairings, and each pairing must pass. Test the combinations you actually ship:
- Dark step text on the light tint, such as
--error-700on--error-100. This needs at least 4.5:1 because it is normal-size text. - The mid step used as an icon or border against the page background. This needs at least 3:1 as a UI component.
- White text on a solid mid-step button, such as
--error-500behind a "Delete" label. This needs 4.5:1.
Amber is the usual failure. A bright amber cannot hold white text, because yellow-range hues have high luminance. If --warning-500 fails with white text, use dark text on it, or use --warning-700 text on --warning-100. Do not darken amber until it turns brown just to force white text to pass.
Add the semantic layer
Components should not reference --error-700 directly. Give them semantic names, as you did for text and borders in the previous chapters. A message component then needs only a role.
:root {
--color-success-bg: var(--success-100);
--color-success-text: var(--success-700);
--color-success-border: var(--success-500);
--color-warning-bg: var(--warning-100);
--color-warning-text: var(--warning-700);
--color-warning-border: var(--warning-500);
--color-error-bg: var(--error-100);
--color-error-text: var(--error-700);
--color-error-border: var(--error-500);
}
.message {
padding: 0.75rem 1rem;
border-left: 4px solid var(--message-border);
background: var(--message-bg);
color: var(--message-text);
}
.message--success {
--message-bg: var(--color-success-bg);
--message-text: var(--color-success-text);
--message-border: var(--color-success-border);
}
.message--error {
--message-bg: var(--color-error-bg);
--message-text: var(--color-error-text);
--message-border: var(--color-error-border);
}The .message class never names a status. Adding a warning variant means setting three variables on a new modifier class.
Keep status colours distinct from the rest of the palette
Check your accent against the three status hues. An orange accent at hue 35 sits almost on top of the warning amber, and users will read accent buttons as warnings. If they collide, move the accent to another hue, or reserve the accent for small highlights and rely on icons to separate warnings.
The same check applies to the primary. A green primary makes success messages look like brand decoration. In that case, shift the success hue toward teal or use a more saturated green, and always include the check icon.
Common mistakes
- Using pure
red,green, andyellowkeywords. They are saturated and harsh next to a tuned palette. - Testing contrast only in the light theme. The dark theme needs its own check, covered in a later chapter.
- Using the error colour for emphasis, such as a red "Sale" badge. This weakens the meaning of red for real errors.
Exercise
Your design uses --warning-500: hsl(38 92% 46%) as the background of a "Review needed" banner with white text, and the contrast ratio comes out at 2.4:1. Name two ways to fix this without making the warning colour look brown, and state the ratio you need.
Show answer
Normal-size text needs at least 4.5:1. Fix it by switching to dark text (for example --warning-700 or a near-black neutral) on the amber background, or by using the light tint --warning-100 as the background with --warning-700 text and keeping amber only for the border and icon. Also add a warning icon or "Warning:" label so the meaning does not depend on colour.
Exercise
Why should a .message--error rule set variables like --message-bg instead of using --error-100 directly?
Show answer
The semantic layer keeps components independent from raw palette steps. You can change which step an error uses, or reassign it for dark mode, in one place without editing component rules, and you can add new message types by setting the same three variables.