Sub topic 12
Keeping clickable styles consistent across a site
A single well-styled button is not enough. If every page defines its own buttons and links, users have to relearn what is clickable on each screen. This chapter assumes you know basic HTML and CSS (selectors, the box model, pseudo-classes) and have read the earlier chapters on button design, link design, interaction states, focus indicators and target size. Here you collect those decisions into one set of reusable styles.
Why consistency matters
Users learn a signifier once and expect it everywhere. If links are underlined and blue on one page, then plain gray on another, they stop trusting the cue. Consistency also reduces maintenance. A change to the button radius should happen in one place, not in forty.
Three kinds of inconsistency show up most often:
- The same action is styled differently on different pages.
- Different actions share one style, so a destructive action looks like a harmless one.
- States are missing from some components, so focus or hover works on one button and not another.
Define the decisions once
Use CSS custom properties (variables) to hold the values that make clickable elements recognizable. These are often called design tokens. Components then read the tokens instead of repeating raw values.
:root {
--color-action: #1d4ed8;
--color-action-hover: #1e40af;
--color-action-visited: #6d28d9;
--color-action-tint: #eff6ff;
--color-on-action: #ffffff;
--radius-control: 8px;
--size-target: 44px;
--focus-ring: 3px solid var(--color-action);
}If the brand color changes, you edit --color-action and every button and link follows. You should also check the new value against the contrast ratios from the earlier chapter. A token change that fails contrast is then a single bug, not scattered ones.
One base class, small variants
Build one base class for every button and add modifiers for rank. The base carries everything shared: size, shape, font and focus behavior. A modifier changes only what differs.
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
min-height: var(--size-target);
padding: 0 1.25rem;
border: 2px solid var(--color-action);
border-radius: var(--radius-control);
background: var(--color-action);
color: var(--color-on-action);
font: inherit;
font-weight: 600;
text-decoration: none;
cursor: pointer;
}
.btn:hover {
background: var(--color-action-hover);
border-color: var(--color-action-hover);
}
.btn:focus-visible {
outline: var(--focus-ring);
outline-offset: 3px;
}
.btn--secondary {
background: transparent;
color: var(--color-action);
}
.btn--secondary:hover {
background: var(--color-action-tint);
color: var(--color-action-hover);
}Because the base class is not tied to an element, it works on both <button> and a link that navigates. Choose the element by what the control does, then apply .btn for the look.
<button type="button" class="btn">Save changes</button>
<button type="button" class="btn btn--secondary">Cancel</button>
<a href="/signup" class="btn">Create an account</a>Avoid naming variants after appearance, such as .btn-blue. Rank names like secondary still make sense after a redesign.
Keep links consistent too
Define one rule for links in running text and one for links in navigation if they truly differ. Do not style links page by page. Keep the same underline, the same visited color and the same focus ring everywhere.
a:not(.btn) {
color: var(--color-action);
text-decoration: underline;
text-underline-offset: 0.15em;
}
a:not(.btn):visited {
color: var(--color-action-visited);
}
a:focus-visible {
outline: var(--focus-ring);
outline-offset: 2px;
}The :not(.btn) selector stops link styling from leaking onto links that are styled as buttons.
How the pieces fit together
Common mistakes
- Setting
outline: noneon one component and forgetting to restore a focus indicator. - Copying button CSS into a new file instead of reusing the class.
- Using different minimum sizes for similar buttons, so some fall below the target size.
- Defining the hover state but not the focus-visible state.
Audit what you have
Search your stylesheets for hard-coded colors and for outline: none. Every match is a place where the system may be bypassed. Then open several pages and tab through them. The focus ring should look identical everywhere.
Exercise
Your site has a primary button, and a developer needs a red "Delete account" button. Describe how to add it without copying the whole button CSS, and name one state you must not forget.
Show answer
Add a modifier such as .btn--danger that overrides only the color values (ideally through new tokens like --color-danger), and keep the shared .btn base for size, shape and font. You must define the hover state and the :focus-visible outline for the new variant, and check that its text and background meet the contrast ratio.
Exercise
Why is a:not(.btn) used in the link rule instead of plain a?
Show answer
Plain a would also style links that use the .btn class, applying link color and underline to something meant to look like a button. :not(.btn) limits the text-link rules to ordinary links.