Sub topic 9
Ranking buttons: primary, secondary and tertiary
This chapter assumes you can write basic HTML and CSS, including selectors, the box model, colors, and pseudo-classes such as :hover. It also assumes you know the difference between a button and a link from the earlier chapters. Here you will learn how to show which action on a page matters most, and how to build that ranking in CSS.
Why ranking matters
A page often offers several actions at once. A checkout page might let people pay, save the cart for later, apply a coupon, or go back. If every action looks the same, the user has to read each label and decide which one to use. If every action looks loud, the page feels noisy and no action stands out.
Button hierarchy is the practice of giving each action a visual weight that matches its importance. The most important action looks the strongest. Less important actions look quieter. People notice the difference before they read the labels, so the ranking guides them through the page.
The ranking is a signifier, in the sense used in the first chapter. A strong, filled button signals "this is the main thing to do here." An outlined button signals "this is available, but it is not the main thing." A plain text-style button signals "this is a minor option."
The three levels
Most interfaces need only three levels.
| Level | Typical look | Used for | Example label |
|---|---|---|---|
| Primary | Solid fill, white text | The one action you most want the user to take | Create account |
| Secondary | Outline, transparent fill, colored text | Important alternatives that are not the main action | Save draft |
| Tertiary | No border, no fill, often underlined or colored text | Low-priority or optional actions | Cancel |
Primary
A primary button is the main action in a given area. It has the most visual weight: a solid fill, strong contrast against the page, and often a bolder label. It answers the question "What is this view for?"
Keep to one primary button per view or per section. When two buttons compete for the same weight, users hesitate. A page can still have several primary buttons if they belong to separate regions that are clearly divided, such as two cards that each have their own "Buy" action. Within one region, choose one.
Secondary
A secondary button supports the primary one. It offers a valid alternative, such as "Save draft" next to "Publish." It must still look clickable, so it keeps a visible border and a clear label. It is quieter than the primary because it has no fill.
You can have more than one secondary button in a region. Several secondary buttons of equal weight are fine, because none of them competes with the primary action.
Tertiary
A tertiary button is for actions the user may want but that you do not want to promote, such as "Cancel," "Skip," or "Learn more." It has no border and no fill, so it takes up the least attention.
Tertiary buttons carry a risk. When you remove the border and fill, you also remove the main cues that make an element look clickable. A tertiary button that is only colored text looks the same as a link or a plain label. To keep it recognizable, give it padding, a hover state, a focus indicator, and a label that reads as an action. Many designers also keep an underline on tertiary actions.
If the action navigates somewhere, remember the earlier rule: use a link. A tertiary "Learn more" that goes to another page should be an <a> element styled to match, not a <button>.
Ranking with more than visual weight
Fill and border are the strongest tools, but they are not the only ones. These properties also change how loud a button feels:
- Size: a larger button draws more attention. Keep every button at least 44px tall for touch, and make the primary one larger only if you have room.
- Position: users often look for the main action at the end of a flow. In a form, the primary action usually sits at the end of the form, next to the secondary one.
- Order: put the primary action first in the source and tab order when it is the most likely choice, or place it at the end of a row to follow your platform's convention. Pick one pattern and use it everywhere.
- Spacing: a button with room around it stands out more than one packed tight against others.
- Color: use your brand or accent color for the primary button and a neutral or the same color in outline form for secondary buttons.
Do not rank only by color. A red primary button next to a gray secondary one may be clear to most users, but users with low vision or color blindness may not tell the difference. Fill versus outline is a difference in shape and weight, so it still works without color.
Implementing the three levels in CSS
The best approach is a shared base class that defines the shape and size, plus modifier classes that change the weight. This keeps all buttons consistent in size, padding, and focus behavior, and the ranking differs only in the pieces that need to differ.
The primary and secondary styles come from the button styling you have already seen. This example adds a tertiary level and a full set of states.
<div class="actions">
<button type="submit" class="btn">Publish article</button>
<button type="button" class="btn btn--secondary">Save draft</button>
<button type="button" class="btn btn--tertiary">Cancel</button>
</div>.actions {
display: flex;
flex-wrap: wrap;
gap: 0.75rem;
align-items: center;
}
.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:active {
transform: translateY(1px);
}
.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 {
border-color: transparent;
background: transparent;
color: #1d4ed8;
text-decoration: underline;
text-underline-offset: 0.15em;
}
.btn--tertiary:hover {
background: #eff6ff;
border-color: transparent;
color: #1e3a8a;
}A few details in this code are worth noticing.
- Every level uses the same
min-height, padding, and border width. The tertiary button has a border, but it is transparent. This keeps all three buttons the same size, so the row does not shift when the style changes, and it leaves a space that the hover background can fill. - Every level inherits the same
:focus-visibleoutline. Ranking changes how loud a button looks, but it must never remove the keyboard focus indicator. - The tertiary button keeps an underline. This is the cue that stops it from reading as plain text.
- Each modifier class overrides only what it needs to. Because
.btn--secondary:hoverand.btn--tertiary:hoverare more specific than.btn:hoveronce they apply to the same element, their background values win. If a modifier hover style does not seem to apply, check that its rule comes after the base rule and has equal or higher specificity.
Seeing the ranking in a layout
The diagram below shows how a decision about the user's goal turns into a button level.
Common mistakes
Too many primary buttons
If a toolbar has five filled buttons, none of them stands out. Demote the others to secondary or tertiary, or group them with headings so each group has its own primary.
Destructive actions styled as primary
A "Delete account" button should not look like the best option on the page. Give destructive actions a clear, calm style, such as an outline in a warning color, and require a confirmation step. If the destructive action is the main purpose of a confirmation dialog, you can make it primary there, because the context has already made the choice explicit. Pair it with a clearly labeled safe option such as "Keep account."
Hiding the safe action
When "Cancel" is nearly invisible and "Confirm" is loud, users may confirm by accident. A tertiary cancel is acceptable, but it must still be findable. Check that its contrast meets the minimum ratio and that it has a hover and a focus state.
Equal weight for unequal choices
Two buttons that look the same, such as "Accept all cookies" and "Manage preferences," tell users the choices are equal. If they are not equal, rank them. If you intend them to be equal, for fairness or legal reasons, give them matching styles on purpose.
Ranking that changes between pages
If the primary button is blue and filled on one page and an outlined green button on the next, users must relearn the pattern each time. Define the levels once and reuse them. The consistency chapter covers how to organize this.
Losing contrast in the quiet levels
Lighter styling is not an excuse for low contrast. The label text of a secondary or tertiary button still needs at least a 4.5:1 contrast ratio against its background, and the border of a secondary button needs at least 3:1 against the page, as covered in the contrast chapter. The blue #1d4ed8 on white used above passes both.
Applying ranking to links
Links can take part in the hierarchy too. A link that looks like a button, as in the earlier example of <a href="/signup" class="btn">, is still a link. It navigates, and screen readers announce it as a link. You can give it any of the three levels with the same classes.
For example, a hero section on a landing page might show a primary link, "Start free trial," and a tertiary link, "See pricing." Both navigate, so both are <a> elements. Only their classes differ.
<a href="/trial" class="btn">Start free trial</a>
<a href="/pricing" class="btn btn--tertiary">See pricing</a>A quick check you can run
Try the squint test. Open your page, blur your eyes or zoom the browser out until the text is unreadable, and look at the shapes. You should be able to point to the primary action in the region. Then do the reverse: press Tab through the page and confirm that every level shows a clear focus outline.
Exercise
A form has three actions: "Submit application," "Save and finish later," and "Discard." Which button level fits each action, and why? Also say which HTML element each one would likely use if "Discard" only closes the form and does not leave the page.
Show answer
"Submit application" is primary because it is the main goal of the form and is the one action you want most users to take. "Save and finish later" is secondary because it is a valid alternative that keeps the user's work. "Discard" is tertiary because it is a low-promotion action, though it should keep an underline, a hover state, and a focus outline so it still looks clickable. All three perform actions on the current page, so each is a button element. Submit uses type="submit", and the other two use type="button".
Exercise
In the CSS above, the tertiary button has "border-color: transparent" instead of "border: none". What problem does that choice avoid?
Show answer
The transparent border keeps the same 2px of space on each side, so the tertiary button has the same size as the primary and secondary buttons. With "border: none," the button would be 4px shorter and narrower, and the row of buttons would look misaligned and could shift when styles change.
Exercise
A page shows four filled blue buttons next to each other: "Buy now," "Add to wishlist," "Share," and "Compare." What is wrong with the hierarchy, and how would you fix it?
Show answer
All four buttons have the same visual weight, so none signals the main action. Keep "Buy now" as the primary filled button, make "Add to wishlist" secondary with an outline, and make "Share" and "Compare" tertiary text-style buttons that keep an underline and visible focus and hover states.