51 CSS Buttons
02 / 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 Primary and Secondary Button Pair

One shared button recipe, two visual weights, and a container that stacks them on a phone without a media query — hierarchy done the way a design system does it: the variant classes override only three tokens each, so every state, size and focus behaviour is written once.

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-02">
  <div class="cb-02__stage">
    <div class="cb-02__pair">
      <button class="cb-02__btn cb-02__btn--primary" type="button">Start free trial</button>
      <button class="cb-02__btn cb-02__btn--secondary" type="button">Book a demo</button>
    </div>
  </div>
</div>
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

.cb-02 {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --text: #141416;
  --muted: #5f5f68;
  --line: #dcdcd6;
  --accent: #4f39f6;
  --on-accent: #ffffff;
  --radius: .75rem;
  --sans: "Plus Jakarta Sans",ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif;
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
  display: block;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

@supports (color: oklch(50% 0 0)) {
  .cb-02 {
    --bg: oklch(97% .003 90);
    --accent: oklch(51% .23 279);
    --text: oklch(16% .01 285);
    --line: oklch(89% .008 90);
  }
}

@media (prefers-color-scheme: dark) {
  .cb-02:not([data-theme="light"]) {
    --bg: #0c0c0f;
    --surface: #17171c;
    --text: #f4f4f7;
    --muted: #a1a1ad;
    --line: #2c2c35;
    --accent: #8b7cff;
    --on-accent: #0b0a1a;
  }
}

.cb-02[data-theme="dark"] {
  --bg: #0c0c0f;
  --surface: #17171c;
  --text: #f4f4f7;
  --muted: #a1a1ad;
  --line: #2c2c35;
  --accent: #8b7cff;
  --on-accent: #0b0a1a;
}

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

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

.cb-02__pair {
  container-type: inline-size;
  width: min(100%,26rem);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .75rem;
}

.cb-02__btn {
  --ring: transparent;
  --ring-w: 0px;
  cursor: pointer;
  display: grid;
  place-items: center;
  min-height: 3rem;
  padding: 0 1.5rem;
  border: 0;
  border-radius: var(--radius);
  font: inherit;
  font-size: .9375rem;
  font-weight: 600;
  letter-spacing: -.01em;
  background: var(--fill);
  color: var(--ink);
  box-shadow: inset 0 0 0 var(--ring-w) var(--ring);
  transition: translate .2s cubic-bezier(.16,1,.3,1), background-color .2s ease, box-shadow .2s ease;
}

.cb-02__btn--primary {
  --fill: var(--accent);
  --ink: var(--on-accent);
  box-shadow: 0 8px 20px -10px color-mix(in oklab,var(--accent) 80%,transparent);
}

.cb-02__btn--secondary {
  --fill: var(--surface);
  --ink: var(--text);
  --ring: var(--line);
  --ring-w: 1px;
}

.cb-02__btn:hover {
  translate: 0 -1px;
}

.cb-02__btn--primary:hover {
  --fill: color-mix(in oklab,var(--accent) 88%,black);
}

.cb-02__btn--secondary:hover {
  --fill: color-mix(in oklab,var(--text) 5%,var(--surface));
  --ring: color-mix(in oklab,var(--text) 22%,var(--line));
}

.cb-02__btn:active {
  translate: 0 1px;
}

.cb-02__btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.cb-02__btn:disabled {
  cursor: not-allowed;
  opacity: .45;
  translate: 0;
}

@container (max-width: 22rem) {
  .cb-02__btn {
    flex: 1 1 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cb-02__btn {
    transition: none;
  }
}

@media (forced-colors: active) {
  .cb-02__btn {
    background: ButtonFace;
    color: ButtonText;
    border: 1px solid ButtonText;
    box-shadow: none;
  }

  .cb-02__btn--primary {
    background: Highlight;
    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 Primary and Secondary Button Pair
Source: https://codefronts.com/components/css-buttons/css-primary-and-secondary-button-pair/

One shared button recipe, two visual weights, and a container that stacks them on a phone without a media query — hierarchy done the way a design system does it: the variant classes override only three tokens each, so every state, size and focus behaviour is written once.
## HTML
```html
<div class="cb-02">
  <div class="cb-02__stage">
    <div class="cb-02__pair">
      <button class="cb-02__btn cb-02__btn--primary" type="button">Start free trial</button>
      <button class="cb-02__btn cb-02__btn--secondary" type="button">Book a demo</button>
    </div>
  </div>
</div>
```
## CSS
```css
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

.cb-02 {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --text: #141416;
  --muted: #5f5f68;
  --line: #dcdcd6;
  --accent: #4f39f6;
  --on-accent: #ffffff;
  --radius: .75rem;
  --sans: "Plus Jakarta Sans",ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif;
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
  display: block;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

@supports (color: oklch(50% 0 0)) {
  .cb-02 {
    --bg: oklch(97% .003 90);
    --accent: oklch(51% .23 279);
    --text: oklch(16% .01 285);
    --line: oklch(89% .008 90);
  }
}

@media (prefers-color-scheme: dark) {
  .cb-02:not([data-theme="light"]) {
    --bg: #0c0c0f;
    --surface: #17171c;
    --text: #f4f4f7;
    --muted: #a1a1ad;
    --line: #2c2c35;
    --accent: #8b7cff;
    --on-accent: #0b0a1a;
  }
}

.cb-02[data-theme="dark"] {
  --bg: #0c0c0f;
  --surface: #17171c;
  --text: #f4f4f7;
  --muted: #a1a1ad;
  --line: #2c2c35;
  --accent: #8b7cff;
  --on-accent: #0b0a1a;
}

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

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

.cb-02__pair {
  container-type: inline-size;
  width: min(100%,26rem);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .75rem;
}

.cb-02__btn {
  --ring: transparent;
  --ring-w: 0px;
  cursor: pointer;
  display: grid;
  place-items: center;
  min-height: 3rem;
  padding: 0 1.5rem;
  border: 0;
  border-radius: var(--radius);
  font: inherit;
  font-size: .9375rem;
  font-weight: 600;
  letter-spacing: -.01em;
  background: var(--fill);
  color: var(--ink);
  box-shadow: inset 0 0 0 var(--ring-w) var(--ring);
  transition: translate .2s cubic-bezier(.16,1,.3,1), background-color .2s ease, box-shadow .2s ease;
}

.cb-02__btn--primary {
  --fill: var(--accent);
  --ink: var(--on-accent);
  box-shadow: 0 8px 20px -10px color-mix(in oklab,var(--accent) 80%,transparent);
}

.cb-02__btn--secondary {
  --fill: var(--surface);
  --ink: var(--text);
  --ring: var(--line);
  --ring-w: 1px;
}

.cb-02__btn:hover {
  translate: 0 -1px;
}

.cb-02__btn--primary:hover {
  --fill: color-mix(in oklab,var(--accent) 88%,black);
}

.cb-02__btn--secondary:hover {
  --fill: color-mix(in oklab,var(--text) 5%,var(--surface));
  --ring: color-mix(in oklab,var(--text) 22%,var(--line));
}

.cb-02__btn:active {
  translate: 0 1px;
}

.cb-02__btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.cb-02__btn:disabled {
  cursor: not-allowed;
  opacity: .45;
  translate: 0;
}

@container (max-width: 22rem) {
  .cb-02__btn {
    flex: 1 1 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cb-02__btn {
    transition: none;
  }
}

@media (forced-colors: active) {
  .cb-02__btn {
    background: ButtonFace;
    color: ButtonText;
    border: 1px solid ButtonText;
    box-shadow: none;
  }

  .cb-02__btn--primary {
    background: Highlight;
    color: HighlightText;
  }
}
```

How this works

Both buttons share a single base rule and read their look from three tokens. The variants are pure token swaps, which is why they can never drift apart:

.cb-02__btn{
  background:var(--fill); color:var(--ink);
  box-shadow:inset 0 0 0 var(--ring-w) var(--ring);
}
.cb-02__btn--primary{ --fill:var(--accent); --ink:var(--on-accent); --ring-w:0px; }
.cb-02__btn--secondary{ --fill:var(--surface); --ink:var(--text); --ring:var(--line); --ring-w:1px; }

The pair wraps with flex-wrap, and a container query — not a viewport query — makes them go full-width when the slot is narrow, so the component behaves correctly inside a sidebar as well as a hero:

.cb-02__pair{ container-type:inline-size; display:flex; flex-wrap:wrap; gap:.75rem; }
@container (max-width: 22rem){
  .cb-02__btn{ flex:1 1 100%; }
}

Order matters for accessibility: the primary comes first in the DOM so screen-reader and keyboard order matches importance, and on mobile CSS keeps it visually first too.

Make it yours

  • Add a third weight (tertiary/quiet) in four lines: --fill:transparent; --ink:var(--muted); --ring-w:0px; plus a hover tint.
  • Flip the container breakpoint value to control when the pair stacks — it is measured on the wrapper, so nest it anywhere.
  • For a destructive pair, set --accent to your danger colour on the wrapper; both buttons re-derive automatically.
  • Match your form controls by aligning --radius and min-height with your inputs — 3rem / .75rem is a safe pairing.
  • Reverse visual order for right-to-left or cancel-first platforms with flex-direction:row-reverse and no markup change.

Gotchas — read before shipping

  • A secondary button must still pass 4.5:1 text contrast — grey-on-grey is the most common accessibility failure in button pairs. Test the label, not the border.
  • Container queries require container-type on the wrapper, which creates a containment context; absolutely-positioned children inside it now resolve against the wrapper.
  • Don't build the secondary with border if the primary has none — the extra 2px changes the height. Use an inset box-shadow ring so both variants measure identically.
  • Two visually equal buttons is not hierarchy; if both look primary, users hesitate measurably longer. One decision per screen.
  • gap on a wrapping flex row applies to both axes, so the stacked layout gets its spacing free — margins would double up.

Browser support

ChromeSafariFirefoxEdge
111+16.2+113+111+

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

Container queries need Chrome 105 / Safari 16 / Firefox 110; without them the pair still wraps via flex-wrap and simply doesn't go full-width. Everything else is baseline CSS.

Techniques used in this demo

Search CodeFronts

Loading…