51 CSS Buttons
08 / 51

All 51 in 51 CSS Buttons

  1. 01CSS Submit Button (Form Primary)
  2. 02CSS Primary and Secondary Button Pair
  3. 03CSS Ghost / Outline Button
  4. 04CSS Icon-Only Button with Accessible Tooltip
  5. 05CSS Gradient CTA Button
  6. 06CSS Loading Spinner Button (State Transition)
  7. 07CSS Disabled Button State (Full State Reference)
  8. 08CSS Button Group Component (Segmented Radio-Like)
  9. 09CSS Add to Cart Button
  10. 10CSS Download Progress Button
  11. 11CSS Like Heart Button
  12. 12CSS Confirm Delete Button
  13. 13CSS Play Pause Button
  14. 14CSS Subscribe Confetti Button
  15. 15CSS Magnetic Mercury Ripple Button
  16. 16CSS Brutalist Glitch Button
  17. 17CSS Neon Plasma Burst Button
  18. 18CSS Clay Press Button
  19. 19CSS Editorial Ink Spread Button
  20. 20CSS Particle Shard Burst Button
  21. 21CSS Brushed Brass Plate Button
  22. 22CSS Washi Paper Crane Button
  23. 23CSS Frosted Ice Cube Button
  24. 24CSS Vintage Typewriter Key Button
  25. 25CSS Lacquered Walnut Wood Button
  26. 26CSS Pharma Gel Capsule Button
  27. 27CSS Aged Copper Coin Button
  28. 28CSS Origami Fortune Cookie Button
  29. 29CSS Holographic Foil Sticker Button
  30. 30CSS Brutalist Concrete Slab Button
  31. 31CSS Mercury Bead Morph Button
  32. 32CSS Soft Pill Modern SaaS Button
  33. 33CSS Masking Tape Label Button
  34. 34CSS Obsidian Glass Shard Button
  35. 35CSS Wine Velvet Ribbon Button
  36. 36CSS LED Segment Display Button
  37. 37CSS Cassette Mixtape Label Button
  38. 38CSS Chalkboard Menu Button
  39. 39CSS Vinyl Record Sleeve Ripple Button
  40. 40CSS Polaroid Snapshot Button
  41. 41CSS Airline Boarding Pass Button
  42. 42CSS Aged Brass Subway Token Button
  43. 43CSS Vintage Rx Pharmacy Label Button
  44. 44CSS Bakelite Radio Dial Toggle Button
  45. 45CSS Regal Postage Stamp Button
  46. 46CSS Victorian Cigar Band Foil Button
  47. 47CSS Vintage Calculator Key Button
  48. 48CSS Toolbox Latch Spotlight Button
  49. 49CSS Receipt Paper Total Count-Up Button
  50. 50CSS IBM Punch Card Magnetic Follow Button
  51. 51CSS Brass Periscope Lens Button
Pure CSSMIT licensed

CSS Button Group Component (Segmented Radio-Like)

A segmented control built on real radio inputs, so arrow-key navigation, roving focus and form serialisation come from the platform rather than from JavaScript. A single sliding thumb tracks the checked segment via :has(), and the active label crosses over the thumb by inverting colour at the same moment.

Live Demo
Plain CSSTailwind v4
Try it

Build UI like this from scratch: Flexbox, Grid, animations & responsive CSS

ZTM · The CSS Bootcamp · 30‑day money-back guarantee · Affiliate link

10% off at checkout with code
Check ZTM Course

The code

<div class="cb-08">
  <div class="cb-08__stage">
    <div class="cb-08__group" role="group" aria-label="Chart range">
      <span class="cb-08__thumb" aria-hidden="true"></span>
      <label class="cb-08__seg"><input type="radio" name="cb-08-range" value="day"><span>Day</span></label>
      <label class="cb-08__seg"><input type="radio" name="cb-08-range" value="week" checked><span>Week</span></label>
      <label class="cb-08__seg"><input type="radio" name="cb-08-range" value="month"><span>Month</span></label>
      <label class="cb-08__seg"><input type="radio" name="cb-08-range" value="year"><span>Year</span></label>
    </div>
  </div>
</div>
@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@500;600;700&display=swap');

.cb-08 {
  --bg: #f1f2f4;
  --track: #e6e7ea;
  --surface: #ffffff;
  --muted: #63636e;
  --ink-on: #0d0d12;
  --thumb: #ffffff;
  --accent: #5b21b6;
  --n: 4;
  --radius: .7rem;
  --spring: linear(0,.42 8%,.79 17%,1.02 24%,1.09 29%,1.06 36%,1 48%,1);
  --sans: "Manrope",ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif;
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
  display: block;
  background: var(--bg);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

@supports (color: oklch(50% 0 0)) {
  .cb-08 {
    --bg: oklch(95.8% .004 265);
    --track: oklch(92.5% .005 265);
    --accent: oklch(44% .2 296);
    --muted: oklch(48% .012 280);
  }
}

@media (prefers-color-scheme: dark) {
  .cb-08:not([data-theme="light"]) {
    --bg: #0a0a0d;
    --track: #191922;
    --surface: #0f0f14;
    --thumb: #2c2c3a;
    --ink-on: #f6f6fa;
    --muted: #9494a2;
    --accent: #a78bfa;
  }
}

.cb-08[data-theme="dark"] {
  --bg: #0a0a0d;
  --track: #191922;
  --surface: #0f0f14;
  --thumb: #2c2c3a;
  --ink-on: #f6f6fa;
  --muted: #9494a2;
  --accent: #a78bfa;
}

.cb-08,
.cb-08 *,
.cb-08 *::before,
.cb-08 *::after {
  box-sizing: border-box;
}

.cb-08__stage {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: clamp(1.5rem,6vw,4rem);
}

.cb-08__group {
  position: relative;
  display: flex;
  width: min(100%,25rem);
  padding: .3rem;
  background: var(--track);
  border-radius: calc(var(--radius) + .3rem);
  box-shadow: inset 0 1px 2px color-mix(in oklab,var(--ink-on) 12%,transparent);
}

.cb-08__thumb {
  position: absolute;
  z-index: 0;
  top: .3rem;
  left: .3rem;
  bottom: .3rem;
  width: calc((100% - .6rem) / var(--n));
  background: var(--thumb);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px color-mix(in oklab,var(--ink-on) 18%,transparent), 0 6px 14px -8px color-mix(in oklab,var(--ink-on) 40%,transparent);
  transition: translate .45s cubic-bezier(.16,1,.3,1);
}

@supports (transition-timing-function: linear(0,1)) {
  .cb-08__thumb {
    transition: translate .5s var(--spring);
  }
}

.cb-08__seg {
  position: relative;
  z-index: 1;
  flex: 1 1 0;
  cursor: pointer;
  display: grid;
  place-items: center;
  min-height: 2.75rem;
  padding: 0 .5rem;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 600;
  letter-spacing: -.005em;
  color: var(--muted);
  transition: color .25s ease;
  -webkit-tap-highlight-color: transparent;
}

.cb-08__seg input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  clip-path: inset(50%);
}

.cb-08__seg:hover {
  color: color-mix(in oklab,var(--ink-on) 70%,var(--muted));
}

.cb-08__seg:has(input:checked) {
  color: var(--ink-on);
}

.cb-08__seg:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.cb-08__group:has(.cb-08__seg:nth-of-type(2) input:checked) .cb-08__thumb {
  translate: 100% 0;
}

.cb-08__group:has(.cb-08__seg:nth-of-type(3) input:checked) .cb-08__thumb {
  translate: 200% 0;
}

.cb-08__group:has(.cb-08__seg:nth-of-type(4) input:checked) .cb-08__thumb {
  translate: 300% 0;
}

.cb-08__group:active .cb-08__thumb {
  scale: .97;
}

@supports not selector(:has(*)) {
  .cb-08__thumb {
    display: none;
  }

  .cb-08__seg:has(input:checked),
    .cb-08__seg input:checked ~ span {
    color: var(--ink-on);
  }

  .cb-08__seg input:checked ~ span {
    text-decoration: underline;
    text-underline-offset: .4em;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cb-08__thumb,
    .cb-08__seg {
    transition: none;
  }
}

@media (forced-colors: active) {
  .cb-08__group {
    border: 1px solid ButtonText;
  }

  .cb-08__thumb {
    background: Highlight;
  }

  .cb-08__seg:has(input:checked) {
    color: HighlightText;
  }
}
Paste this into ChatGPT, Claude, Cursor, or any coding assistant. The block below is pre-framed with everything the AI needs to integrate this demo into your project — markup, styles, scoping notes, and the source URL. Hit Copy and paste straight into your chat.
Here's a working CSS Button from CodeFronts. Use it as-is or adapt to your framework. All classes are scoped under a unique prefix so the code won't collide with your existing styles. MIT licensed.
Demo: CSS Button Group Component (Segmented Radio-Like)
Source: https://codefronts.com/components/css-buttons/css-button-group-component-segmented-radio-like/

A segmented control built on real radio inputs, so arrow-key navigation, roving focus and form serialisation come from the platform rather than from JavaScript. A single sliding thumb tracks the checked segment via :has(), and the active label crosses over the thumb by inverting colour at the same moment.
## HTML
```html
<div class="cb-08">
  <div class="cb-08__stage">
    <div class="cb-08__group" role="group" aria-label="Chart range">
      <span class="cb-08__thumb" aria-hidden="true"></span>
      <label class="cb-08__seg"><input type="radio" name="cb-08-range" value="day"><span>Day</span></label>
      <label class="cb-08__seg"><input type="radio" name="cb-08-range" value="week" checked><span>Week</span></label>
      <label class="cb-08__seg"><input type="radio" name="cb-08-range" value="month"><span>Month</span></label>
      <label class="cb-08__seg"><input type="radio" name="cb-08-range" value="year"><span>Year</span></label>
    </div>
  </div>
</div>
```
## CSS
```css
@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@500;600;700&display=swap');

.cb-08 {
  --bg: #f1f2f4;
  --track: #e6e7ea;
  --surface: #ffffff;
  --muted: #63636e;
  --ink-on: #0d0d12;
  --thumb: #ffffff;
  --accent: #5b21b6;
  --n: 4;
  --radius: .7rem;
  --spring: linear(0,.42 8%,.79 17%,1.02 24%,1.09 29%,1.06 36%,1 48%,1);
  --sans: "Manrope",ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif;
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
  display: block;
  background: var(--bg);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

@supports (color: oklch(50% 0 0)) {
  .cb-08 {
    --bg: oklch(95.8% .004 265);
    --track: oklch(92.5% .005 265);
    --accent: oklch(44% .2 296);
    --muted: oklch(48% .012 280);
  }
}

@media (prefers-color-scheme: dark) {
  .cb-08:not([data-theme="light"]) {
    --bg: #0a0a0d;
    --track: #191922;
    --surface: #0f0f14;
    --thumb: #2c2c3a;
    --ink-on: #f6f6fa;
    --muted: #9494a2;
    --accent: #a78bfa;
  }
}

.cb-08[data-theme="dark"] {
  --bg: #0a0a0d;
  --track: #191922;
  --surface: #0f0f14;
  --thumb: #2c2c3a;
  --ink-on: #f6f6fa;
  --muted: #9494a2;
  --accent: #a78bfa;
}

.cb-08,
.cb-08 *,
.cb-08 *::before,
.cb-08 *::after {
  box-sizing: border-box;
}

.cb-08__stage {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: clamp(1.5rem,6vw,4rem);
}

.cb-08__group {
  position: relative;
  display: flex;
  width: min(100%,25rem);
  padding: .3rem;
  background: var(--track);
  border-radius: calc(var(--radius) + .3rem);
  box-shadow: inset 0 1px 2px color-mix(in oklab,var(--ink-on) 12%,transparent);
}

.cb-08__thumb {
  position: absolute;
  z-index: 0;
  top: .3rem;
  left: .3rem;
  bottom: .3rem;
  width: calc((100% - .6rem) / var(--n));
  background: var(--thumb);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px color-mix(in oklab,var(--ink-on) 18%,transparent), 0 6px 14px -8px color-mix(in oklab,var(--ink-on) 40%,transparent);
  transition: translate .45s cubic-bezier(.16,1,.3,1);
}

@supports (transition-timing-function: linear(0,1)) {
  .cb-08__thumb {
    transition: translate .5s var(--spring);
  }
}

.cb-08__seg {
  position: relative;
  z-index: 1;
  flex: 1 1 0;
  cursor: pointer;
  display: grid;
  place-items: center;
  min-height: 2.75rem;
  padding: 0 .5rem;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 600;
  letter-spacing: -.005em;
  color: var(--muted);
  transition: color .25s ease;
  -webkit-tap-highlight-color: transparent;
}

.cb-08__seg input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  clip-path: inset(50%);
}

.cb-08__seg:hover {
  color: color-mix(in oklab,var(--ink-on) 70%,var(--muted));
}

.cb-08__seg:has(input:checked) {
  color: var(--ink-on);
}

.cb-08__seg:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.cb-08__group:has(.cb-08__seg:nth-of-type(2) input:checked) .cb-08__thumb {
  translate: 100% 0;
}

.cb-08__group:has(.cb-08__seg:nth-of-type(3) input:checked) .cb-08__thumb {
  translate: 200% 0;
}

.cb-08__group:has(.cb-08__seg:nth-of-type(4) input:checked) .cb-08__thumb {
  translate: 300% 0;
}

.cb-08__group:active .cb-08__thumb {
  scale: .97;
}

@supports not selector(:has(*)) {
  .cb-08__thumb {
    display: none;
  }

  .cb-08__seg:has(input:checked),
    .cb-08__seg input:checked ~ span {
    color: var(--ink-on);
  }

  .cb-08__seg input:checked ~ span {
    text-decoration: underline;
    text-underline-offset: .4em;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cb-08__thumb,
    .cb-08__seg {
    transition: none;
  }
}

@media (forced-colors: active) {
  .cb-08__group {
    border: 1px solid ButtonText;
  }

  .cb-08__thumb {
    background: Highlight;
  }

  .cb-08__seg:has(input:checked) {
    color: HighlightText;
  }
}
```

How this works

Each segment is an <input type="radio"> visually hidden inside its <label>. That gives keyboard users the native radio behaviour — arrows move and select, Tab enters and leaves the group as one stop:

<label class="cb-08__seg">
  <input type="radio" name="cb-08-range" checked>
  <span>Week</span>
</label>

The thumb is one absolutely-positioned element sized to calc(100% / var(--n)). :has() reads which input is checked on the parent and translates the thumb by whole multiples of its own width, so adding a segment is a change to --n and one extra rule:

.cb-08__group:has(.cb-08__seg:nth-child(2) input:checked) .cb-08__thumb{ translate:100% 0; }
.cb-08__group:has(.cb-08__seg:nth-child(3) input:checked) .cb-08__thumb{ translate:200% 0; }

Focus is drawn on the label via :has(input:focus-visible), so the ring appears exactly where the visual control is even though the focused element is a hidden input. The thumb rides a spring easing built with linear(), which gives real overshoot that a cubic-bezier cannot.

Make it yours

  • Change the number of segments: update --n, add the label, add one :has() rule. Nothing else moves.
  • Swap the thumb for an underline (tabs) by setting its height:2px; top:auto; bottom:0; border-radius:0.
  • Use --thumb and --ink-on for brand colour; the inactive labels stay on --muted for hierarchy.
  • Set flex-direction:column on the group for a vertical filter list — change translate:100% 0 to 0 100%.
  • For icon + label segments, put both inside the <span>; the thumb sizing is fraction-based, not content-based.

Gotchas — read before shipping

  • Do not hide the radio with display:none or visibility:hidden — it leaves the accessibility tree and stops being focusable. Use the clip-path visually-hidden pattern.
  • A segmented control is a radio group, not a set of buttons. If you build it from <button>s you must add role="radiogroup", aria-checked and hand-roll arrow keys.
  • :has() with nth-child counts all children — if you add a thumb element inside the group, its index shifts the labels (this demo puts the thumb first and offsets accordingly, so read the selector before reordering markup).
  • Percentage translate resolves against the thumb's own size, so the thumb must be exactly 100% / n wide or the segments drift.
  • Give the group a fieldset/legend or role="group" with aria-label in production — a bare radio set has no announced purpose.

Browser support

ChromeSafariFirefoxEdge
111+16.2+121+111+

Floor set by :has(), oklch(), color-mix() as this demo is written. The core technique itself goes back further — Chrome 105+.

:has() needs Chrome 105 / Safari 15.4 / Firefox 121 — without it the checked label still inverts via :checked and only the sliding thumb is lost. linear() easing needs Chrome 113 / Safari 17.2 / Firefox 112 and falls back to the declared cubic-bezier.

Techniques used in this demo

Search CodeFronts

Loading…