HTML and CSS Buttons: 8 Styles to Copy
Updated 2026-10-28. 8 buttons.
An HTML CSS button is a native button element styled with a class: padding, background, border radius and font, plus :hover, :active, :focus-visible and :disabled rules. The eight sets below cover the common needs, from solid and outline buttons to loading, pressed 3D, segmented and icon-only ones, each as plain HTML and CSS and as React.
Start with the solid, outline and ghost set if you are building an interface from scratch: it gives you a clear order of importance for every screen, and its CSS is commented line by line so you can see which rule handles which state. Add the pill with an icon for marketing calls to action, and the loading button anywhere a click waits on a server.
The 3D pressed button and the gradient border button are for moments that should feel special, such as a single checkout or signup action; one per screen is plenty. The segmented group suits view switches and filters where exactly one option is on, and the round icon buttons fit media players and toolbars where space is tight.
The arrow link button is different from the rest: it is an anchor, not a button, because it takes the visitor somewhere. Keep that rule across your site. Anything that navigates is a link, anything that changes something on the page is a button, and both can share the same look.
Compare them
| Variant | Built with | Size (gzipped) | Running cost | Browser support |
|---|---|---|---|---|
| HTML CSS Button Solid Outline Ghost With Hover Active Disabled States | CSS only | 1.4 KB | Plain CSS with one short background and transform transition per button, no script at all. | All current browsers |
| HTML CSS 3D Pressed Button With Solid Edge | CSS only | 0.9 KB | A hard box-shadow and a transform change on press; nothing runs while idle. | All current browsers |
| HTML CSS Arrow Link Button With Sliding Underline | CSS only | 1.2 KB | A scaleX transform on one pseudo-element and a colour change on the circle per hovered row. | All current browsers |
| HTML CSS Gradient Border Button On Dark | CSS only | 0.9 KB | Two background layers per button and a small scale on press, no script. | All current browsers |
| HTML CSS Loading Spinner Button With Busy State | CSS and a small script | 1.4 KB | One rotating border ring animated by transform, plus a click handler and two timeouts. | All current browsers |
| HTML CSS Pill Button With Leading Icon And Trailing Arrow | CSS only | 1.3 KB | Static CSS; the arrow nudge is a transform on one small inline icon. | All current browsers |
| HTML CSS Round Icon Only Buttons In A Player | CSS and a small script | 1.3 KB | Plain circles with a background transition; the only script swaps one label on click. | All current browsers |
| HTML CSS Segmented Button Group | CSS and a small script | 1.1 KB | One delegated click listener per group and a handful of attribute changes per click. | All current browsers |
HTML CSS Button Solid Outline Ghost With Hover Active Disabled States
A teal booking panel with the three button styles most interfaces need: a solid button for the main action, an outline button for the second choice and a ghost button for quiet actions. Each row shows a plain label, a label with a calendar icon and the disabled look. Hover darkens the fill, pressing sinks the button by one pixel, and a keyboard focus ring appears only when tabbing. On phones the buttons wrap under their labels.
<div class="hb1">
<h2 class="hb1-title">Booking actions</h2>
<p class="hb1-lead">Hover, press or tab to each button. The last one in each row is disabled.</p>
<div class="hb1-row">
<!-- Solid: the one main action on a screen -->
<button type="button" class="hb1-btn hb1-solid">Confirm booking</button>
<button type="button" class="hb1-btn hb1-solid">
<svg viewBox="0 0 20 20" aria-hidden="true"><path d="M6 2h2v2h4V2h2v2h2a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2V2zm10 7H4v7h12V9z"/></svg>
Reschedule
</button>
<button type="button" class="hb1-btn hb1-solid" disabled>Unavailable</button>
</div>
<div class="hb1-row">
<!-- Outline: a second choice next to the main one -->
<button type="button" class="hb1-btn hb1-outline">Confirm booking</button>
<button type="button" class="hb1-btn hb1-outline">Reschedule</button>
<button type="button" class="hb1-btn hb1-outline" disabled>Unavailable</button>
</div>
<div class="hb1-row">
<!-- Ghost: quiet actions in toolbars and dialogs -->
<button type="button" class="hb1-btn hb1-ghost">Confirm booking</button>
<button type="button" class="hb1-btn hb1-ghost">Reschedule</button>
<button type="button" class="hb1-btn hb1-ghost" disabled>Unavailable</button>
</div>
</div>
<style>
/* 1. Colours live in variables so one edit re-themes every button. */
.hb1 {
--hb1-brand: #0f766e; /* fill and border */
--hb1-brand-dark: #115e59; /* hover */
--hb1-brand-darker: #134e4a; /* pressed */
--hb1-tint: #f0fdfa; /* hover wash for outline and ghost */
--hb1-tint-strong: #ccfbf1; /* pressed wash */
--hb1-radius: 8px;
max-width: 44rem; margin: 0 auto; padding: 32px 20px;
font-family: ui-sans-serif, system-ui, sans-serif; color: #0f172a;
}
.hb1-title { margin: 0; font-size: 18px; }
.hb1-lead { margin: 4px 0 20px; font-size: 14px; color: #475569; }
.hb1-row { display: flex; flex-wrap: wrap; gap: 12px; padding: 16px 0; border-top: 1px solid #e7e5e4; }
/* 2. Shared base: size, shape, type and the transitions every style uses. */
.hb1-btn {
display: inline-flex; align-items: center; justify-content: center; gap: 8px;
min-height: 44px; padding: 0 20px;
border: 1px solid transparent; border-radius: var(--hb1-radius);
font: 600 14px/1 ui-sans-serif, system-ui, sans-serif;
cursor: pointer;
transition: background-color .15s, transform .15s;
}
.hb1-btn svg { width: 16px; height: 16px; fill: currentColor; }
/* 3. Keyboard focus ring: only shows for keyboard users, never on mouse click. */
.hb1-btn:focus-visible { outline: 2px solid var(--hb1-brand); outline-offset: 2px; }
/* 4. Pressed: sink by one pixel so the click feels physical. */
.hb1-btn:active:not(:disabled) { transform: translateY(1px); }
/* 5. The three styles. */
.hb1-solid { background: var(--hb1-brand); color: #fff; }
.hb1-solid:hover { background: var(--hb1-brand-dark); }
.hb1-solid:active { background: var(--hb1-brand-darker); }
.hb1-outline { background: #fff; border-color: var(--hb1-brand); color: var(--hb1-brand-dark); }
.hb1-outline:hover { background: var(--hb1-tint); }
.hb1-outline:active { background: var(--hb1-tint-strong); }
.hb1-ghost { background: transparent; color: var(--hb1-brand-dark); }
.hb1-ghost:hover { background: var(--hb1-tint); }
.hb1-ghost:active { background: var(--hb1-tint-strong); }
/* 6. Disabled: grey, no pointer, no hover change. The disabled attribute also removes it from the tab order. */
.hb1-btn:disabled,
.hb1-btn:disabled:hover { background: #e2e8f0; border-color: transparent; color: #64748b; cursor: not-allowed; }
.hb1-outline:disabled, .hb1-outline:disabled:hover { background: #fff; border-color: #cbd5e1; }
.hb1-ghost:disabled, .hb1-ghost:disabled:hover { background: transparent; }
@media (prefers-reduced-motion: reduce) {
.hb1-btn { transition: none; }
.hb1-btn:active:not(:disabled) { transform: none; }
}
</style>
With reduced motion: The pressed sink and colour fades are switched off; colours still change instantly on hover and press.
Running cost: Plain CSS with one short background and transform transition per button, no script at all.
- Change `--hb1-brand`, `--hb1-brand-dark` and `--hb1-brand-darker` at the top of the CSS to three shades of your colour; in React swap `teal-700`, `teal-800` and `teal-900`.
- Round the corners into pills by setting `--hb1-radius` to `999px`, or `rounded-full` in place of `rounded-lg`.
- Make the buttons larger by raising `min-height` from 44px to 52px and the side padding from 20px to 28px.
- Remove the one pixel press by deleting the `:active:not(:disabled)` rule if your brand prefers flat buttons.
Full page for HTML CSS Button Solid Outline Ghost With Hover Active Disabled States
HTML CSS 3D Pressed Button With Solid Edge
Chunky quiz buttons in lime, white and sky, each sitting on a darker solid edge drawn by a box-shadow with no blur. Hovering lifts a button by a pixel, and pressing with the mouse, a finger or the Space key pushes the face down into its edge, like a key on a toy keyboard. Each edge colour is a variable.
<div class="hb4">
<p class="hb4-kicker">Question 4 of 10</p>
<h2 class="hb4-title">Which word means a small stream?</h2>
<p class="hb4-lead">Say it out loud, then press Check answer.</p>
<div class="hb4-row">
<button type="button" class="hb4-btn hb4-lime">Check answer</button>
<button type="button" class="hb4-btn hb4-plain">Hint</button>
<button type="button" class="hb4-btn hb4-sky">Skip</button>
</div>
</div>
<style>
.hb4 { max-width: 32rem; margin: 0 auto; padding: 32px 24px 40px; background: #fff; border-radius: 24px; text-align: center; font-family: ui-sans-serif, system-ui, sans-serif; }
.hb4-kicker { margin: 0; font-size: 14px; font-weight: 600; color: #0369a1; }
.hb4-title { margin: 8px 0; font-size: 20px; color: #0f172a; }
.hb4-lead { margin: 0 0 28px; font-size: 14px; color: #475569; }
.hb4-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; }
/* The 3D trick: a hard box-shadow with no blur draws the side of the button.
--edge is the side colour, a darker shade of the face. */
.hb4-btn {
--edge: #4d7c0f;
min-height: 52px; padding: 0 24px;
border: 0; border-radius: 16px;
font: 800 16px/1 ui-sans-serif, system-ui, sans-serif; text-transform: uppercase; letter-spacing: .03em;
cursor: pointer;
box-shadow: 0 6px 0 var(--edge);
transition: transform .08s ease-out, box-shadow .08s ease-out;
}
/* Hover lifts it a pixel; pressing pushes the face down into the edge. */
.hb4-btn:hover { transform: translateY(-1px); box-shadow: 0 7px 0 var(--edge); }
.hb4-btn:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--edge); }
.hb4-btn:focus-visible { outline: 4px solid #7dd3fc; outline-offset: 4px; }
.hb4-lime { background: #a3e635; color: #1a2e05; --edge: #4d7c0f; }
.hb4-plain { background: #fff; color: #1e293b; border: 2px solid #cbd5e1; --edge: #cbd5e1; }
.hb4-sky { background: #0ea5e9; color: #fff; --edge: #0369a1; }
@media (prefers-reduced-motion: reduce) { .hb4-btn { transition: none; } }
</style>
With reduced motion: The face still drops into its edge when pressed, but it jumps there without easing.
Running cost: A hard box-shadow and a transform change on press; nothing runs while idle.
- Set `--edge` on each button to a darker shade of its face colour.
- Make the buttons deeper by raising the 6px shadow and the 5px press distance together.
HTML CSS Arrow Link Button With Sliding Underline
A restaurant's list of next steps on warm cream, where each row is one large link: a serif-flavoured label with a short note under it and a round arrow badge on the right. Hovering or tabbing to a row draws an amber underline from the left, fills the circle and nudges the arrow forward. These are anchors because each one opens another page.
<div class="hb8">
<p class="hb8-kicker">Osteria Lume</p>
<h2 class="hb8-title">Seasonal cooking on Wharf Lane</h2>
<ul class="hb8-list">
<li><a href="#" class="hb8-link"><span><span class="hb8-label">Read the full menu</span><span class="hb8-note">Spring, twelve dishes</span></span><span class="hb8-arrow" aria-hidden="true"><svg viewBox="0 0 20 20"><path d="M11.3 4.3a1 1 0 0 1 1.4 0l5 5a1 1 0 0 1 0 1.4l-5 5a1 1 0 0 1-1.4-1.4L14.6 11H3a1 1 0 1 1 0-2h11.6l-3.3-3.3a1 1 0 0 1 0-1.4z"/></svg></span></a></li>
<li><a href="#" class="hb8-link"><span><span class="hb8-label">Book a table for Friday</span><span class="hb8-note">Two seatings left</span></span><span class="hb8-arrow" aria-hidden="true"><svg viewBox="0 0 20 20"><path d="M11.3 4.3a1 1 0 0 1 1.4 0l5 5a1 1 0 0 1 0 1.4l-5 5a1 1 0 0 1-1.4-1.4L14.6 11H3a1 1 0 1 1 0-2h11.6l-3.3-3.3a1 1 0 0 1 0-1.4z"/></svg></span></a></li>
</ul>
</div>
<style>
.hb8 { --hb8-accent: #b45309; max-width: 42rem; margin: 0 auto; padding: 48px 20px; background: #fffbeb; font-family: ui-sans-serif, system-ui, sans-serif; }
.hb8-kicker { margin: 0; font: italic 14px ui-serif, Georgia, serif; color: #92400e; }
.hb8-title { margin: 4px 0 32px; font: 400 30px/1.2 ui-serif, Georgia, serif; color: #1c1917; }
.hb8-list { margin: 0; padding: 0; list-style: none; border-top: 1px solid #fde68a; }
.hb8-list li { border-bottom: 1px solid #fde68a; }
/* The whole row is one link, so the tap target is large. */
.hb8-link { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 64px; padding: 12px 0; color: #1c1917; text-decoration: none; }
.hb8-link:focus-visible { outline: 2px solid var(--hb8-accent); outline-offset: 4px; }
.hb8-note { display: block; margin-top: 2px; font-size: 14px; color: #57534e; }
/* Underline drawn by a pseudo-element scaled from 0 to 1 from the left edge. */
.hb8-label { position: relative; font-size: 18px; font-weight: 600; }
.hb8-label::after { content: ""; position: absolute; left: 0; bottom: -2px; width: 100%; height: 2px; background: var(--hb8-accent); transform: scaleX(0); transform-origin: left; transition: transform .3s ease-out; }
.hb8-link:hover .hb8-label::after, .hb8-link:focus-visible .hb8-label::after { transform: scaleX(1); }
/* Arrow in a circle that fills and nudges right. */
.hb8-arrow { display: grid; place-items: center; flex-shrink: 0; width: 40px; height: 40px; border: 1px solid #fcd34d; border-radius: 50%; color: #92400e; transition: background-color .2s, color .2s; }
.hb8-arrow svg { width: 18px; height: 18px; fill: currentColor; transition: transform .3s; }
.hb8-link:hover .hb8-arrow, .hb8-link:focus-visible .hb8-arrow { background: var(--hb8-accent); border-color: var(--hb8-accent); color: #fff; }
.hb8-link:hover .hb8-arrow svg { transform: translateX(2px); }
@media (prefers-reduced-motion: reduce) {
.hb8-label::after, .hb8-arrow, .hb8-arrow svg { transition: none; }
}
</style>
With reduced motion: The underline and filled arrow circle appear at once instead of growing and sliding.
Running cost: A scaleX transform on one pseudo-element and a colour change on the circle per hovered row.
- Change `--hb8-accent` for the underline and filled circle colour.
- Speed the underline up or down with the `.3s` on the `::after` transition.
HTML CSS Gradient Border Button On Dark
Two dark buttons for a note-taking app's pricing call, each wrapped in a two pixel rim that runs from mint through cyan to amber. One is softly rounded, the other a pill. The rim is not a border colour: it is a gradient background showing through a transparent border, which is why the corners stay round. Hover lightens the inside.
<div class="hb5">
<h2 class="hb5-title">Field notes, synced everywhere</h2>
<p class="hb5-lead">Plans for researchers who work offline in the field and sync when back in signal.</p>
<div class="hb5-row">
<button type="button" class="hb5-btn">Start a free month</button>
<button type="button" class="hb5-btn hb5-round">Compare plans</button>
</div>
</div>
<style>
.hb5 {
--hb5-fill: #18181b; /* inside of the button: match your background or pick a card colour */
--hb5-fill-hover: #27272a;
--hb5-rim: linear-gradient(120deg, #34d399, #22d3ee 45%, #fbbf24);
background: #09090b; padding: 64px 20px; text-align: center; font-family: ui-sans-serif, system-ui, sans-serif;
}
.hb5-title { margin: 0; font-size: 24px; color: #fff; letter-spacing: -.01em; }
.hb5-lead { max-width: 24rem; margin: 8px auto 32px; font-size: 14px; color: #a1a1aa; }
.hb5-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
/* Two backgrounds on one element:
1. a solid colour clipped to the padding box (the inside)
2. the gradient clipped to the border box, which only shows through the transparent border.
Unlike border-image, this keeps border-radius. */
.hb5-btn {
min-height: 48px; padding: 0 24px;
border: 2px solid transparent; border-radius: 12px;
background: linear-gradient(var(--hb5-fill), var(--hb5-fill)) padding-box, var(--hb5-rim) border-box;
color: #fff; font: 600 14px/1 ui-sans-serif, system-ui, sans-serif;
cursor: pointer; transition: transform .12s;
}
.hb5-btn:hover { background: linear-gradient(var(--hb5-fill-hover), var(--hb5-fill-hover)) padding-box, var(--hb5-rim) border-box; }
.hb5-btn:active { transform: scale(.98); }
.hb5-btn:focus-visible { outline: 2px solid #67e8f9; outline-offset: 3px; }
.hb5-round { border-radius: 999px; }
@media (prefers-reduced-motion: reduce) { .hb5-btn { transition: none; } .hb5-btn:active { transform: none; } }
</style>
With reduced motion: Pressing no longer shrinks the button; the hover colour change still shows.
Running cost: Two background layers per button and a small scale on press, no script.
- Set `--hb5-fill` to the colour behind the button so the inside blends in, or to a card colour for contrast.
- Change the stops in `--hb5-rim`, or the 2px border width for a heavier edge.
HTML CSS Loading Spinner Button With Busy State
A dark invoice settings card where Save changes swaps its label for Saving and a spinning ring, ignores further clicks, then reports Saved and announces it in a status line. A second button sits permanently in its busy state so you can see the loading look without clicking. The ring is a bordered circle with one transparent side.
<div class="hb3">
<h2 class="hb3-title">Invoice settings</h2>
<label for="hb3-terms" class="hb3-label">Payment terms</label>
<input id="hb3-terms" class="hb3-input" value="Net 30 days">
<div class="hb3-row">
<button type="button" class="hb3-btn hb3-save">
<span class="hb3-spin" aria-hidden="true"></span>
<span class="hb3-text">Save changes</span>
</button>
<!-- Always-busy example so you can see the loading look -->
<button type="button" class="hb3-btn hb3-ghost" aria-busy="true" aria-disabled="true">
<span class="hb3-spin" aria-hidden="true"></span>Sending invoice
</button>
</div>
<p class="hb3-status" role="status"></p>
</div>
<style>
.hb3 { max-width: 28rem; margin: 0 auto; padding: 24px; background: #1e293b; border: 1px solid #334155; border-radius: 12px; font-family: ui-sans-serif, system-ui, sans-serif; color: #e2e8f0; }
.hb3-title { margin: 0 0 16px; font-size: 16px; color: #fff; }
.hb3-label { display: block; font-size: 14px; color: #cbd5e1; }
.hb3-input { box-sizing: border-box; width: 100%; height: 44px; margin-top: 6px; padding: 0 12px; border: 1px solid #475569; border-radius: 6px; background: #0f172a; color: #fff; font: inherit; font-size: 14px; }
.hb3-row { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 20px; }
.hb3-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-width: 176px; min-height: 44px; padding: 0 20px; border: 1px solid transparent; border-radius: 6px; font: 600 14px/1 ui-sans-serif, system-ui, sans-serif; cursor: pointer; }
.hb3-btn:focus-visible { outline: 2px solid #a5b4fc; outline-offset: 2px; }
.hb3-save { background: #6366f1; color: #fff; transition: background-color .15s; }
.hb3-save:hover { background: #818cf8; }
.hb3-ghost { background: transparent; border-color: #475569; color: #e2e8f0; }
/* The spinner: a ring with one coloured side, rotated by a transform keyframe. Hidden until busy. */
.hb3-spin { display: none; width: 14px; height: 14px; border: 2.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: hb3-turn .7s linear infinite; }
.hb3-btn[aria-busy="true"] .hb3-spin { display: inline-block; }
.hb3-btn[aria-busy="true"] { cursor: wait; }
.hb3-save[aria-busy="true"] { background: #6366f1b3; }
@keyframes hb3-turn { to { transform: rotate(360deg); } }
.hb3-status { height: 20px; margin: 12px 0 0; font-size: 14px; color: #6ee7b7; }
@media (prefers-reduced-motion: reduce) {
.hb3-spin { animation: none; border-right-color: currentColor; opacity: .6; }
}
</style>
<script>
(function () {
var btn = document.querySelector(".hb3-save");
if (!btn) return;
var text = btn.querySelector(".hb3-text"), status = document.querySelector(".hb3-status");
btn.addEventListener("click", function () {
/* ignore clicks while busy so the form cannot be sent twice */
if (btn.getAttribute("aria-busy") === "true") return;
btn.setAttribute("aria-busy", "true");
btn.setAttribute("aria-disabled", "true");
text.textContent = "Saving";
/* replace this timeout with your real request */
setTimeout(function () {
btn.removeAttribute("aria-busy");
btn.removeAttribute("aria-disabled");
text.textContent = "Saved";
status.textContent = "Payment terms saved.";
setTimeout(function () { text.textContent = "Save changes"; status.textContent = ""; }, 2000);
}, 1800);
});
})();
</script>
With reduced motion: The spinner ring stops turning and shows as a dimmed full circle beside the label.
Running cost: One rotating border ring animated by transform, plus a click handler and two timeouts.
- Replace the 1800ms timeout in the script with your real request and clear the busy attributes when it settles.
- Change spinner speed with the `.7s` in `hb3-turn`, and its thickness with the 2.5px border.
HTML CSS Pill Button With Leading Icon And Trailing Arrow
Three rounded pill buttons for a bakery order block on warm cream: a rose solid pill with a basket icon in front of the label, a white outline pill whose arrow slides right on hover, and a soft tinted pill holding a small New badge. Fully round ends come from a border radius of 999px, which works at any height.
<div class="hb2">
<p class="hb2-kicker">Juniper Street Bakery</p>
<h2 class="hb2-title">Order the Saturday bread box</h2>
<div class="hb2-row">
<!-- Solid pill with a leading icon -->
<button type="button" class="hb2-pill hb2-solid">
<svg viewBox="0 0 20 20" aria-hidden="true"><path d="M3 4h2l1.6 8.1A2 2 0 0 0 8.6 14H15a2 2 0 0 0 2-1.6L18 7H6.2L5.8 5A1.5 1.5 0 0 0 4.3 4H3zm6 13a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0zm7 0a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0z"/></svg>
Add to basket
</button>
<!-- A link that looks like a pill: it goes somewhere, so it stays an anchor -->
<a href="#" class="hb2-pill hb2-line">
See what is inside
<svg class="hb2-arrow" viewBox="0 0 20 20" aria-hidden="true"><path d="M11.3 4.3a1 1 0 0 1 1.4 0l5 5a1 1 0 0 1 0 1.4l-5 5a1 1 0 0 1-1.4-1.4L14.6 11H3a1 1 0 1 1 0-2h11.6l-3.3-3.3a1 1 0 0 1 0-1.4z"/></svg>
</a>
</div>
<!-- Soft tinted pill with a badge inside -->
<button type="button" class="hb2-pill hb2-soft"><span class="hb2-badge">New</span>Rye and caraway loaf this week</button>
</div>
<style>
.hb2 { --hb2-accent: #e11d48; --hb2-accent-dark: #be123c; background: #fff7ed; padding: 64px 20px; text-align: center; font-family: ui-sans-serif, system-ui, sans-serif; }
.hb2-kicker { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .2em; text-transform: uppercase; color: #be123c; }
.hb2-title { margin: 8px 0 32px; font-size: 24px; color: #1c1917; letter-spacing: -.01em; }
.hb2-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-bottom: 16px; }
/* The pill: border-radius larger than half the height always gives round ends. */
.hb2-pill {
display: inline-flex; align-items: center; gap: 10px;
min-height: 48px; padding: 0 20px;
border: 1px solid transparent; border-radius: 999px;
font: 600 14px/1 ui-sans-serif, system-ui, sans-serif; text-decoration: none;
cursor: pointer; transition: background-color .15s, border-color .15s;
}
.hb2-pill svg { width: 18px; height: 18px; fill: currentColor; flex-shrink: 0; }
.hb2-pill:focus-visible { outline: 2px solid var(--hb2-accent); outline-offset: 3px; }
.hb2-solid { background: var(--hb2-accent); color: #fff; padding-left: 16px; }
.hb2-solid:hover { background: var(--hb2-accent-dark); }
.hb2-solid:active { background: #9f1239; }
.hb2-line { background: #fff; border-color: #d6d3d1; color: #292524; padding-right: 16px; }
.hb2-line:hover { background: #fafaf9; border-color: #a8a29e; }
/* The arrow nudges right on hover to hint at movement. */
.hb2-arrow { transition: transform .2s; }
.hb2-line:hover .hb2-arrow { transform: translateX(4px); }
.hb2-soft { min-height: 40px; padding: 0 16px 0 6px; gap: 8px; background: #ffe4e6; color: #9f1239; font-weight: 500; }
.hb2-soft:hover { background: #fecdd3; }
.hb2-badge { padding: 4px 8px; border-radius: 999px; background: #fff; font-size: 12px; font-weight: 600; }
@media (prefers-reduced-motion: reduce) {
.hb2-pill, .hb2-arrow { transition: none; }
.hb2-line:hover .hb2-arrow { transform: none; }
}
</style>
With reduced motion: The arrow stays in place on hover and colour changes happen without fading.
Running cost: Static CSS; the arrow nudge is a transform on one small inline icon.
- Change `--hb2-accent` and `--hb2-accent-dark` for a different solid pill colour.
- Move the icon after the label to make a trailing icon pill, and swap the extra left padding to the right side.
HTML CSS Round Icon Only Buttons In A Player
A deep green podcast player built from round icon-only buttons: save, back 15 seconds, a large mint play button, forward 30 seconds and share. Every circle is 44 pixels or larger so it is easy to tap. Play switches to a pause icon, and the heart fills in when an episode is saved. Hover shows a soft green disc behind each icon.
<div class="hb7">
<p class="hb7-kicker">Episode 31</p>
<h2 class="hb7-title">Growing tomatoes on a balcony</h2>
<p class="hb7-show">The Allotment Hour</p>
<div class="hb7-bar"><span></span></div>
<div class="hb7-controls">
<!-- Icon-only buttons need an aria-label: there is no visible text for screen readers to read -->
<button type="button" class="hb7-btn" aria-label="Back 15 seconds">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M11 6V2L5 8l6 6v-4a5 5 0 1 1-5 5H4a7 7 0 1 0 7-7z"/></svg>
</button>
<button type="button" class="hb7-btn hb7-play" aria-label="Play">
<svg class="hb7-i-play" viewBox="0 0 24 24" aria-hidden="true"><path d="M8 5v14l11-7z"/></svg>
<svg class="hb7-i-pause" viewBox="0 0 24 24" aria-hidden="true"><path d="M7 5h4v14H7zm6 0h4v14h-4z"/></svg>
</button>
<button type="button" class="hb7-btn" aria-label="Forward 30 seconds">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M13 6V2l6 6-6 6v-4a5 5 0 1 0 5 5h2a7 7 0 1 1-7-7z"/></svg>
</button>
</div>
</div>
<style>
.hb7 { max-width: 22rem; margin: 0 auto; padding: 24px; border-radius: 28px; background: #022c22; text-align: center; font-family: ui-sans-serif, system-ui, sans-serif; }
.hb7-kicker { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .2em; text-transform: uppercase; color: #6ee7b7; }
.hb7-title { margin: 4px 0 0; font-size: 18px; color: #fff; }
.hb7-show { margin: 2px 0 20px; font-size: 14px; color: #a7f3d0; }
.hb7-bar { height: 6px; border-radius: 99px; background: #065f46; overflow: hidden; }
.hb7-bar span { display: block; width: 40%; height: 100%; border-radius: 99px; background: #6ee7b7; }
.hb7-controls { display: flex; align-items: center; justify-content: center; gap: 20px; margin-top: 24px; }
/* Round icon button: equal width and height plus a 50% radius. 44px keeps it easy to tap. */
.hb7-btn { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: #d1fae5; cursor: pointer; transition: background-color .15s, transform .12s; }
.hb7-btn svg { width: 20px; height: 20px; fill: currentColor; }
.hb7-btn:hover { background: #065f46; }
.hb7-btn:active { background: #047857; }
.hb7-btn:focus-visible { outline: 2px solid #a7f3d0; outline-offset: 2px; }
.hb7-play { width: 64px; height: 64px; background: #6ee7b7; color: #022c22; }
.hb7-play:hover { background: #a7f3d0; }
.hb7-play:active { transform: scale(.95); background: #6ee7b7; }
.hb7-i-pause, .hb7-play[aria-label="Pause"] .hb7-i-play { display: none; }
.hb7-play[aria-label="Pause"] .hb7-i-pause { display: block; }
@media (prefers-reduced-motion: reduce) { .hb7-btn { transition: none; } .hb7-play:active { transform: none; } }
</style>
<script>
(function () {
var play = document.querySelector(".hb7-play");
if (!play) return;
/* the label is the state: it says what the next press will do */
play.addEventListener("click", function () {
play.setAttribute("aria-label", play.getAttribute("aria-label") === "Play" ? "Pause" : "Play");
});
})();
</script>
With reduced motion: The play button no longer shrinks when pressed, and hover fills appear without fading.
Running cost: Plain circles with a background transition; the only script swaps one label on click.
- Change the 44px width and height together to resize the small circles, and the 64px pair for the main button.
- Swap the path data inside each svg for your own 24 by 24 icons.
HTML CSS Segmented Button Group
Two single-choice button groups above a task list. The first joins List, Board and Calendar into one bordered strip with shared dividers and a dark selected segment. The second is a sunken grey track where the chosen range, Day to Quarter, rises as a white chip. Clicking one option turns the others off, and the heading line updates.
<div class="hb6">
<h2 class="hb6-title">Sprint 14 tasks</h2>
<div class="hb6-row">
<!-- Joined group: borders shared between buttons -->
<div class="hb6-group" role="group" aria-label="Task view">
<button type="button" class="hb6-seg" aria-pressed="false">List</button>
<button type="button" class="hb6-seg" aria-pressed="true">Board</button>
<button type="button" class="hb6-seg" aria-pressed="false">Calendar</button>
</div>
<!-- Track style: a sunken track with a raised selected chip -->
<div class="hb6-track" role="group" aria-label="Date range">
<button type="button" class="hb6-chip" aria-pressed="false">Day</button>
<button type="button" class="hb6-chip" aria-pressed="true">Week</button>
<button type="button" class="hb6-chip" aria-pressed="false">Month</button>
<button type="button" class="hb6-chip" aria-pressed="false">Quarter</button>
</div>
</div>
</div>
<style>
.hb6 { max-width: 42rem; margin: 0 auto; padding: 40px 20px; font-family: ui-sans-serif, system-ui, sans-serif; }
.hb6-title { margin: 0 0 24px; font-size: 18px; color: #0f172a; }
.hb6-row { display: flex; flex-wrap: wrap; align-items: center; gap: 16px 24px; }
/* Joined group: the wrapper draws the outer border and rounds the ends;
each button after the first draws a divider on its left. */
.hb6-group { display: inline-flex; border: 1px solid #cbd5e1; border-radius: 8px; overflow: hidden; }
.hb6-seg { min-height: 40px; padding: 0 16px; border: 0; background: #fff; color: #334155; font: 500 14px ui-sans-serif, system-ui, sans-serif; cursor: pointer; }
.hb6-seg + .hb6-seg { border-left: 1px solid #cbd5e1; }
.hb6-seg:hover { background: #f8fafc; }
.hb6-seg[aria-pressed="true"] { background: #0f172a; color: #fff; }
/* Track style */
.hb6-track { display: inline-flex; padding: 4px; border-radius: 999px; background: #f1f5f9; }
.hb6-chip { min-height: 36px; padding: 0 14px; border: 0; border-radius: 999px; background: transparent; color: #475569; font: 500 14px ui-sans-serif, system-ui, sans-serif; cursor: pointer; }
.hb6-chip:hover { color: #0f172a; }
.hb6-chip[aria-pressed="true"] { background: #fff; color: #0f172a; box-shadow: 0 1px 2px rgb(15 23 42 / .12); }
/* Focus ring sits above neighbours so it is never clipped */
.hb6-seg:focus-visible, .hb6-chip:focus-visible { position: relative; z-index: 1; outline: 2px solid #0f172a; outline-offset: -2px; }
</style>
<script>
(function () {
/* In each group, pressing one button turns the others off. */
document.querySelectorAll(".hb6 [role=group]").forEach(function (group) {
group.addEventListener("click", function (e) {
var btn = e.target.closest("button");
if (!btn) return;
group.querySelectorAll("button").forEach(function (b) { b.setAttribute("aria-pressed", b === btn ? "true" : "false"); });
});
});
})();
</script>
With reduced motion: Colours swap between options instantly; there is no other motion to remove.
Running cost: One delegated click listener per group and a handful of attribute changes per click.
- Swap `#0f172a` in the `[aria-pressed="true"]` rule for your brand colour on the joined group.
- Add or remove buttons freely; the dividers come from the `.hb6-seg + .hb6-seg` rule, so none need extra classes.
Performance notes
Buttons are among the cheapest things a page can draw. Every set here is plain CSS, and the transitions touch only background colour, box shadow on one element or transform, so a hover never triggers layout. The loading spinner rotates with a transform keyframe, which the browser hands to the compositor.
Script appears only where behaviour needs it: the loading demo flips aria-busy, and the segmented group updates aria-pressed. Neither runs anything until a click. If you paste several sets into one page, merge their colour variables into one root block to keep the stylesheet small.
Questions
Should I use a button element or a div for a clickable button?
Always the button element. It is focusable, responds to Enter and Space, submits forms, and is announced as a button by screen readers. A div needs a role, a tabindex and key handlers to match that, and it is easy to miss one.
How do I center text inside a CSS button?
Make the button display: inline-flex with align-items: center and justify-content: center, and give it a min-height instead of a fixed line-height. Icons and text then line up on the same middle line whatever the font.
How do I remove the default button styling?
Set border: 0, background: none, font: inherit and color: inherit on the button, then add your own padding and colours. Keep cursor: pointer and add your own :focus-visible outline, because resetting styles also removes the visible focus on some browsers.
What size should a button be on mobile?
Aim for a tap area of at least 44 by 44 pixels. A min-height of 44px with 16 to 20px of side padding is a safe default; icon-only buttons should be 44px squares or circles even if the icon itself is 20px.
How do I stop a form submitting twice when a button is clicked?
Disable the button or set aria-disabled and ignore further clicks as soon as the first one starts the request, then show a loading state. The loading button in this collection shows the pattern with aria-busy and a spinner.
Also in the gallery: HTML CSS Button Set with Primary, Secondary, Outline, Ghost, Icon, Loading and Destructive Styles, 137 CSS Button Styles You Can Copy, Neo-Brutalist Button Set with Sizes and Icons.
More collections: Gradient Borders in CSS, Rounded and Animated, Dark Mode Toggle Switches in CSS and React, Tailwind Tooltips That Work With Keyboard and Touch, CSS Hover Effects and Magnetic Buttons. All buttons. Build your site free to have a full site built around them.
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App