Sub topic 4
Designing a button that reads as pressable
This chapter assumes you know basic HTML elements and attributes, CSS selectors, the box model, colors, and pseudo-classes. You should also be able to open your browser's developer tools. Here you build the base look of a button. Later chapters cover hierarchy, target size, and states in more depth.
What makes a button look pressable
A button needs a few visual cues that together say "press me". Each cue works as a signifier, a visible hint that points to an action.
- Fill or border. A solid background or a clear outline marks the edge of the control. Plain text with no edge reads as a label.
- Shape. Rounded corners, usually 4px to 12px, look like a physical key. Keep the radius the same across all buttons.
- Padding. Space around the text gives the button body. Cramped text looks like a tag.
- Strong text. A heavier font weight and a high-contrast text color keep the label readable.
- Cursor.
cursor: pointershows a hand over the button on devices with a mouse.
Contrast matters here. The label must have at least a 4.5:1 ratio against the fill, and the button edge should have at least 3:1 against the page background.
Start with the right element
Use a <button> for actions on the current page, such as saving or opening a dialog. Use an <a> for navigation, even when it is styled like a button. The same CSS class can serve both.
<p>
Read the <a href="/docs/getting-started">getting started guide</a>
before you continue.
</p>
<button type="button" class="btn" id="save">Save changes</button>
<a href="/signup" class="btn">Create an account</a>Set type="button" on buttons that are not meant to submit a form. Without it, a button inside a form submits that form by default.
The base button style
The following CSS turns both elements into a filled, rounded button. It also adds hover feedback, a pressed effect, and a keyboard focus outline.
.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;
}Several lines in this block do specific jobs:
display: inline-flexwithalign-itemsandjustify-contentcenters the label inside the box. It also makes an<a>behave like a<button>, so both get the same size.min-height: 44pxgives a comfortable touch target. The target size chapter explains why.font: inheritstops the browser from using its own small default font on<button>.text-decoration: noneremoves the link underline from the<a>version. The fill and shape now carry the signal instead.border: 2px soliduses the same color as the fill. This lets the secondary variant switch to a transparent background without the size changing.:activemoves the button down 1px, which imitates a physical press.:focus-visibledraws an outline only when the browser decides the user needs one, which is usually keyboard navigation.
Filled versus outlined
The .btn--secondary rule keeps the border and drops the fill. It still looks clickable because the edge is visible, but it carries less visual weight than the filled button. Place a filled button beside an outlined one and the user reads the filled one as the main choice.
Common mistakes
- Text only. A bare word with no fill, border, or underline gives no hint that it can be clicked.
- Low-contrast fill. A pale gray button on a white page fails the 3:1 edge guideline.
- Different shapes everywhere. Mixed radii and paddings make users doubt which items are buttons.
- Removed focus outline. The button works with a mouse but is invisible to keyboard users.
- Browser font defaults. Without
font: inherit, buttons look out of place next to the surrounding text.
Exercise
A designer wants a "Download report" control that starts a file download through a URL like /reports/q3.pdf. Which element would you use, and which CSS would you apply to make it look like the filled button from this chapter? Why do the border and background colors match in .btn?
Show answer
Use an <a href="/reports/q3.pdf" download class="btn">Download report</a>, because the control goes to a URL, so it is a link. Applying the .btn class gives it the fill, rounded corners, padding, and 44px minimum height, and text-decoration: none removes the underline. The border and background match so the button looks like one solid shape. The border keeps the same size when the secondary variant makes the background transparent, so the two variants do not shift the layout.