Sub topic 4
Designing a button that reads as pressable
This chapter assumes you know basic HTML elements and attributes, and CSS selectors, the box model, colors, and pseudo-classes. It also assumes you can inspect an element in your browser's developer tools. Earlier chapters covered affordances and signifiers, choosing between a button and a link, and contrast. Here you apply those ideas to build one button style that people recognize as pressable without being told.
What makes a button look pressable
A button has no inherent look. The browser gives <button> a default style, but most sites replace it. Once you do, you are responsible for every cue that says "press me." Users decide in a fraction of a second, so the cues need to be strong and familiar.
These are the visual signifiers a button usually carries:
- A filled or outlined shape with a clear boundary.
- Rounded corners that suggest a physical, tappable object.
- Generous padding, so the label sits inside the shape instead of touching its edges.
- Strong contrast between label and background.
- A pointer cursor on hover, on devices that have a cursor.
- A label that names an action.
No single cue is required, but the more of them you remove, the more the button looks like plain text. A button with no fill, no border, and no padding is a link-looking word. Users will miss it.
Start with the right element
Visual design cannot repair a wrong element. Use a <button> when the control performs an action on the current page, such as saving, submitting, or opening a dialog. Use an <a href> when it navigates somewhere. A <button> gives you keyboard activation with Enter and Space, a button role for screen readers, and form behavior, all without extra code.
<button type="button" class="btn" id="save">Save changes</button>
<a href="/signup" class="btn">Create an account</a>The second example is a link with button styling. That is acceptable because its purpose is still navigation, and the browser and assistive technology still treat it as a link. Both elements share the .btn class, so they look the same. Always set type="button" on buttons that are not meant to submit a form. Without it, a <button> inside a form defaults to type="submit".
Building the base style
The following CSS builds a filled primary button. Read it first, then each property is explained below.
.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;
}Display and alignment
display: inline-flex lets the button sit in a line of content while centering its label on both axes. It also works for icon-plus-text buttons, because flex handles the spacing between children. Centering matters most when min-height is larger than the text: the label stays vertically centered instead of hugging the top.
This also helps links. An <a> is display: inline by default, so vertical padding and height do not behave as you expect. Making it inline-flex gives it a proper box.
Fill, border, and contrast
The fill #1d4ed8 is a saturated blue, and the label is white. That pair has a contrast ratio of roughly 6.7:1, which passes the 4.5:1 minimum for normal text. The button's boundary also matters. WCAG 1.4.11 asks for at least 3:1 contrast for the visual information needed to identify a user interface component. Here the blue fill against a white page easily clears that.
The border is the same color as the fill. This looks redundant, but it does two jobs:
- It keeps the box size the same across variants. The secondary button (below) uses the same border width, so the two variants line up.
- In forced-colors modes, such as Windows High Contrast, the browser overrides backgrounds. A real border survives, so the button keeps its outline. A button that relies on its background alone can vanish.
Shape
border-radius: 8px softens the corners. A value around 4 to 8px reads as a modern, tappable rectangle. A very large radius gives a pill shape. Both are fine. Choose one for your whole site, because a mix of shapes makes it harder for users to learn what a button looks like. The consistency chapter returns to this.
Size and padding
min-height: 44px guarantees a comfortable touch target. Use min-height, not height. If the user enlarges their text size or the label wraps to two lines, a fixed height clips the text, while a minimum grows with the content.
padding: 0 1.25rem adds space on the left and right. The vertical space comes from min-height and the centering. Padding in rem scales with the user's font size setting, so the button stays proportionate when text is enlarged. Wide horizontal padding is a strong signifier, because it makes the label look contained by the button.
Typography
Buttons do not inherit font settings from their parent. A <button> uses the system's control font by default, which often looks out of place next to your body text. font: inherit fixes that. Follow it with font-weight: 600 so the label reads as heavier than surrounding copy. Declare font-weight after the font shorthand. The shorthand resets the weight, so an earlier declaration would be lost.
text-decoration: none matters only for the link version. Anchors are underlined by default, and an underlined label inside a filled shape looks wrong. Remove the underline here, since the fill and shape now carry the cue. The next chapter covers when links should keep theirs.
Cursor
cursor: pointer shows the hand icon on mouse devices. This is a convention rather than a standard requirement: native buttons show the default arrow in most browsers. Many designers add the pointer because it gives a clear hover signal. It has no effect on touch screens, so never rely on it alone.
A secondary variant
Not every button should be a heavy filled block. An outlined button is a lower-emphasis option that still looks pressable, because it keeps a visible border.
.btn--secondary {
background: transparent;
color: #1d4ed8;
}The border is inherited from .btn, so the outline stays. Used as class="btn btn--secondary", the button has a blue outline and blue label on a transparent background. Ranking primary against secondary is covered in a later chapter. The point here is that the secondary style keeps the border. Removing it would turn the control into plain colored text.
States that complete the picture
A pressable object responds. The base style should come with at least hover, pressed, and keyboard focus feedback. The full treatment of states is a later chapter, but include these from the start:
.btn:hover {
background: #1e40af;
border-color: #1e40af;
}
.btn:active {
transform: translateY(1px);
}
.btn:focus-visible {
outline: 3px solid #1d4ed8;
outline-offset: 3px;
}The hover state darkens the fill, and the border changes with it so the edge does not show a stray lighter ring. The :active state moves the button down 1px, a small cue that imitates a physical press. The :focus-visible rule draws an outline when the browser decides the user is navigating by keyboard. The offset separates the ring from the button edge, so it stays visible against the same-colored border.
A hover cue alone is not enough. Touch users never hover, and keyboard users see only the focus outline. Treat hover as an enhancement and never as the only way to discover that something is a button.
Common mistakes
| Mistake | Why it hurts | Fix |
|---|---|---|
| Ghost button with no border | Looks like plain text, so users overlook it | Keep a visible border or fill |
| Fixed `height` | Clips text at larger sizes or when the label wraps | Use `min-height` |
| Label contrast under 4.5:1 | Hard to read for low-vision users | Check the pair with a contrast tool |
| `outline: none` with no replacement | Keyboard users lose their position | Style `:focus-visible` instead |
| Button looks different on every page | Users must relearn the pattern | Share one `.btn` class |
| A `<div>` styled as a button | No keyboard or screen reader support | Use `<button>` or `<a>` |
| Light gray fill on a white page | The boundary fails the 3:1 contrast need | Darken the fill or add a stronger border |
Edge cases
- Long labels. A label that wraps to two lines still works with
min-height, but vertical padding is then needed so the lines do not touch the edges. Addpadding-block: 0.5remif wrapping is expected. - Icons. An icon beside the label fits easily inside
inline-flex. Addgap: 0.5rem. Mark purely decorative icons witharia-hidden="true". An icon-only button needs an accessible name, such as anaria-label. - Dark backgrounds. The blue fill may fail against a dark page. Re-check both the label contrast and the boundary contrast in each context, not once for the whole site.
- Forced colors. Keep the border, as described above, and test in a high-contrast mode.
- Browser defaults. Some browsers add extra inner padding or a default border to
<button>. Settingborder,padding, andfontexplicitly, as this style does, gives the same result everywhere.
Exercises
Exercise
A designer asks you to remove the border from a button, because the fill already shows its shape. Give two reasons to keep a border anyway.
Show answer
First, forced-colors modes such as Windows High Contrast override background colors, but a real border stays visible, so the button keeps its outline. Second, a border of the same width on every variant keeps the boxes the same size, so a transparent-background secondary button still has a visible edge and lines up with the primary one.
Exercise
Why does the style use min-height: 44px and padding in rem instead of height: 44px and padding in px?
Show answer
A fixed height clips the label when the user enlarges text or when the label wraps to a second line. min-height guarantees the touch target size but grows with the content. Padding in rem scales with the user's font size setting, so the button stays in proportion when text is enlarged.
Exercise
You apply .btn to an <a href="/pricing"> element and the underline still shows through the label. Which declaration is missing, and why does the link version need it when <button> does not?
Show answer
text-decoration: none is missing. Anchors are underlined by default, while buttons are not. On a filled button, the shape and fill already signal interactivity, so the underline is removed to keep the label clean.