CSS Buttons
Buttons are the “do it” controls — send, save, next. CSS can give them a clear skin and honest feedback when someone hovers, presses, focuses, or finds them disabled. Keep the HTML semantic (button or submit input); this lesson is about the look and the states.
A button toolkit
📊 Buttons at a glance
| Piece | Everyday job |
|---|---|
padding + background + border |
Build a solid, readable button face |
border-radius |
Soften corners (or go pill with a large radius) |
:hover / :active |
Show “I’m interactive” and “I’m pressed” |
:focus-visible |
Keep a keyboard focus ring you can see |
:disabled + cursor |
Mute unavailable buttons; hand cursor when clickable |
Style one shared .btn (or button) so primary actions match across the page. Field padding for text inputs stayed in the previous lesson — here we dress the click targets.
A solid primary button
Start with comfortable padding, a clear background, readable text color, and a calm border-radius. Prefer font: inherit so the button matches nearby copy.
Base primary button
cssbutton,
.btn {
display: inline-block;
padding: 0.65rem 1.1rem;
font: inherit;
font-weight: 600;
color: #fff;
background: #0b5fff;
border: 1px solid #0b5fff;
border-radius: 0.5rem;
cursor: pointer;
}
Hover and active — honest feedback
:hover can darken or lighten the face slightly. :active should feel pressed — a shade darker or a tiny shift — not a brand-new neon theme.
Hover and active
cssbutton:hover,
.btn:hover {
background: #094fd6;
border-color: #094fd6;
}
button:active,
.btn:active {
background: #0844b8;
border-color: #0844b8;
}
Focus you can see
Never strip focus styles without a replacement. :focus-visible draws a clear ring for keyboard users while keeping mouse clicks calm.
Visible focus ring
cssbutton:focus-visible,
.btn:focus-visible {
outline: 2px solid #0b5fff;
outline-offset: 3px;
}
Disabled buttons stay visible
A disabled button should look unavailable — lower opacity or muted colors — and refuse the pointer. Do not hide it from the layout.
Disabled tone
cssbutton:disabled,
.btn:disabled {
opacity: 0.55;
cursor: not-allowed;
background: #8aa9e8;
border-color: #8aa9e8;
}
A calm button habit
Keep one primary skin, clear hover/active, a visible focus ring, and muted disabled. Outline/ghost variants can share the same padding and radius so the set feels related — not five unrelated widgets.
Outline companion
css.btn-outline {
color: #0b5fff;
background: transparent;
border: 1px solid #0b5fff;
}
.btn-outline:hover {
color: #fff;
background: #0b5fff;
}
Try it yourself
- Style a primary
buttonwith padding, background, text color, andborder-radius. - Darken
:hoverand deepen:activeslightly. - Add a
:focus-visibleoutline — no bareoutline: none. - Mute a
:disabledbutton and setcursor: not-allowed. - Optional: add a
.btn-outlinesibling that shares padding and radius.
Common mistakes
outline: nonewith no focus replacement (keyboard users get lost)- Tiny padding that fails mobile tap targets
- Turning this lesson into text-input / textarea styling (that was form-controls)
- A wild neon theme on
:hoverthat breaks brand calm - Styling only
atags and forgetting realbuttonelements
Summary
- Padding, background, border, and radius build a solid button face
:hoverand:activegive honest interaction feedback- Keep a visible
:focus-visiblering - Mute
:disabled; usecursor: pointerwhen clickable - Leave field chrome to the form-controls lesson; here dress the click targets
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 Instructions
- Read each question carefully
- Select the best answer for each question
- You can retake the quiz as many times as you want
- Your progress will be shown at the top