Sub topic 9
Ranking buttons: primary, secondary and tertiary
This chapter assumes you can write basic HTML and CSS, know how pseudo-classes such as :hover and :focus-visible work, and have already styled a single button as described in the earlier chapter on button visual design.
Why rank buttons at all
A page often offers several actions at once. If every button looks the same, the user has to read each label to find the main one. A visual hierarchy lets them see the most important action first. The common model has three levels:
- Primary: the one action you most want the user to take on this screen.
- Secondary: a useful alternative that matters less.
- Tertiary: a low-emphasis action, such as "Cancel" or "Learn more".
You create the ranking by varying visual weight. Weight comes from fill, border, color saturation and size. A solid fill is the heaviest, an outline is lighter, and plain text with an underline or no border is the lightest.
Rules that keep the ranking clear
- Use one primary button per view or form. Two filled buttons compete, and the user has to stop and compare them.
- Make rank depend on weight, not on size alone. Keep the same height and padding across levels so the targets stay easy to hit. Change fill and border instead.
- Keep every level recognizable as clickable. A tertiary button still needs a signifier, such as an underline, a visible focus outline and enough contrast. Lowering weight must not remove the cue.
- Place the primary action where the user expects it. In a form, that is usually next to the last field, with the secondary action beside it.
Building the levels in CSS
The base .btn class from the earlier chapter is the primary style. A modifier class changes only what differs. This keeps all levels sharing the same size, shape and focus behavior.
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
min-height: 44px;
padding: 0 1.25rem;
border: 2px solid #1d4ed8;
border-radius: 8px;
background: #1d4ed8;
color: #ffffff;
font: inherit;
font-weight: 600;
text-decoration: none;
cursor: pointer;
}
.btn:hover {
background: #1e40af;
border-color: #1e40af;
}
.btn:focus-visible {
outline: 3px solid #1d4ed8;
outline-offset: 3px;
}
.btn--secondary {
background: transparent;
color: #1d4ed8;
}
.btn--secondary:hover {
background: #eff6ff;
color: #1e40af;
}
.btn--tertiary {
background: transparent;
border-color: transparent;
color: #1d4ed8;
text-decoration: underline;
text-underline-offset: 0.15em;
}
.btn--tertiary:hover {
background: #eff6ff;
color: #1e40af;
}The tertiary button keeps the 44px minimum height and its padding, so its clickable area is as large as the others. Only the fill and border disappear. The underline remains as the signifier.
Using the levels in markup
Here the form has one primary action, one secondary action and one tertiary action.
<form>
<button type="submit" class="btn">Place order</button>
<button type="button" class="btn btn--secondary">Save for later</button>
<button type="button" class="btn btn--tertiary">Cancel</button>
</form>"Place order" is the main outcome. "Save for later" is a reasonable alternative. "Cancel" is available but deliberately quiet.
Common errors
- Several primary buttons in one area. Demote all but one.
- Destructive actions styled as primary by default. On a confirmation dialog, "Delete" can be primary because it is the point of the dialog. Elsewhere, give it less weight so it is not hit by accident.
- Tertiary buttons that look like plain text. Without an underline or other cue, users miss them. Check them against the contrast and color rules from earlier chapters.
- Different styles for the same level on different pages. Define the levels once as classes and reuse them.
Exercise
A checkout page has the buttons "Pay now", "Back to cart" and "Apply discount code". Assign a level (primary, secondary or tertiary) to each, and say which CSS properties you would change to produce the difference between levels while keeping touch targets equally easy to hit.
Show answer
"Pay now" is primary (solid fill), because it completes the main task. "Apply discount code" is secondary (outlined), because it is a useful optional step. "Back to cart" is tertiary (text style with underline), because it leaves the current step. Change only background, border-color and text-decoration, and color. Keep min-height, padding and border width the same across levels so every target stays at least 44px tall.