51 Tailwind CSS Buttons
11 / 51

All 51 in 51 Tailwind CSS Buttons

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

Tailwind Like Heart Button

A like button with a springy heart pop, eight radial sparks and a count that rolls over — no JavaScript. State lives in a checkbox, and has-checked: turns every downstream reaction into a variant on the element that reacts.

Live Demo
Plain CSSTailwind v4
Try it

Untitled UI Pro: 5,000+ React + Tailwind CSS v4 components · from $349 one-time

Untitled UI React · Affiliate link

Get Untitled UI Pro

The code

<div class="tb-11 w-full min-h-svh grid place-items-center bg-tb11-bg text-tb11-text font-tb11-sans antialiased p-[clamp(1.5rem,6vw,4rem)]">
  <label class="group relative cursor-pointer inline-flex items-center gap-2 min-h-12 pl-3.5 pr-4 rounded-full bg-tb11-surface border border-tb11-line text-[0.9375rem] font-bold tabular-nums text-tb11-muted shadow-[0_8px_20px_-16px_var(--color-tb11-shadow)] transition-[border-color,color,scale,background-color] duration-250 ease-tb11-out [-webkit-tap-highlight-color:transparent] hover:border-tb11-like-line hover:text-tb11-text hover:scale-[1.02] active:scale-[0.97] has-focus-visible:outline-2 has-focus-visible:outline-offset-[3px] has-focus-visible:outline-tb11-like has-checked:text-tb11-like has-checked:border-tb11-like-line has-checked:bg-tb11-like-tint motion-reduce:transition-none motion-reduce:hover:scale-100">
    <input type="checkbox" aria-label="Like this post" class="sr-only">
    <span aria-hidden="true" class="relative grid place-items-center size-7 text-tb11-muted group-hover:text-tb11-like group-has-checked:text-tb11-like">
      <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" class="size-6 transition-[scale,color,fill] duration-350 ease-tb11-out group-has-checked:fill-tb11-like group-has-checked:animate-tb11-pop motion-reduce:transition-none motion-reduce:group-has-checked:animate-none"><path d="M12 20.2s-7.4-4.3-7.4-9.4A4.3 4.3 0 0 1 12 8.1a4.3 4.3 0 0 1 7.4 2.7c0 5.1-7.4 9.4-7.4 9.4z"/></svg>
      <span class="absolute inset-0 pointer-events-none motion-reduce:hidden">
        <span class="absolute top-1/2 left-1/2 size-[0.28rem] -mt-[0.14rem] -ml-[0.14rem] rounded-full bg-tb11-like opacity-0 rotate-0 group-has-checked:animate-tb11-spark"></span>
        <span class="absolute top-1/2 left-1/2 size-[0.28rem] -mt-[0.14rem] -ml-[0.14rem] rounded-full bg-tb11-spark-warm opacity-0 rotate-45 group-has-checked:animate-tb11-spark"></span>
        <span class="absolute top-1/2 left-1/2 size-[0.28rem] -mt-[0.14rem] -ml-[0.14rem] rounded-full bg-tb11-like opacity-0 rotate-90 group-has-checked:animate-tb11-spark"></span>
        <span class="absolute top-1/2 left-1/2 size-[0.28rem] -mt-[0.14rem] -ml-[0.14rem] rounded-full bg-tb11-spark-warm opacity-0 rotate-[135deg] group-has-checked:animate-tb11-spark"></span>
        <span class="absolute top-1/2 left-1/2 size-[0.28rem] -mt-[0.14rem] -ml-[0.14rem] rounded-full bg-tb11-like opacity-0 rotate-180 group-has-checked:animate-tb11-spark"></span>
        <span class="absolute top-1/2 left-1/2 size-[0.28rem] -mt-[0.14rem] -ml-[0.14rem] rounded-full bg-tb11-spark-cool opacity-0 rotate-[225deg] group-has-checked:animate-tb11-spark"></span>
        <span class="absolute top-1/2 left-1/2 size-[0.28rem] -mt-[0.14rem] -ml-[0.14rem] rounded-full bg-tb11-like opacity-0 rotate-[270deg] group-has-checked:animate-tb11-spark"></span>
        <span class="absolute top-1/2 left-1/2 size-[0.28rem] -mt-[0.14rem] -ml-[0.14rem] rounded-full bg-tb11-spark-cool opacity-0 rotate-[315deg] group-has-checked:animate-tb11-spark"></span>
      </span>
    </span>
    <span aria-hidden="true" class="block h-5 overflow-hidden">
      <span class="tb-11__roll grid transition-[translate] duration-[550ms] ease-tb11-spring group-has-checked:-translate-y-5 motion-reduce:transition-none">
        <span class="block h-5 leading-5">2,417</span>
        <span class="block h-5 leading-5">2,418</span>
      </span>
    </span>
  </label>
</div>
@import "tailwindcss";

@theme {
  --color-tb11-bg: #fbf7f7;
  --color-tb11-bg: oklch(0.976 0.006 15);
  --color-tb11-surface: #ffffff;
  --color-tb11-line: #eadfe0;
  --color-tb11-line: oklch(0.91 0.014 15);
  --color-tb11-text: #241a1c;
  --color-tb11-text: oklch(0.24 0.015 15);
  --color-tb11-muted: #6f6266;
  --color-tb11-muted: oklch(0.48 0.015 15);
  --color-tb11-like: #e11d48;
  --color-tb11-like: oklch(0.56 0.22 12);
  --color-tb11-like-line: #e11d4894;
  --color-tb11-like-line: oklch(0.56 0.22 12 / 0.55);
  --color-tb11-like-tint: #e11d4812;
  --color-tb11-like-tint: oklch(0.56 0.22 12 / 0.07);
  --color-tb11-spark-warm: #ef6a2a;
  --color-tb11-spark-warm: oklch(0.67 0.19 42);
  --color-tb11-spark-cool: #b13ba5;
  --color-tb11-spark-cool: oklch(0.55 0.21 330);
  --color-tb11-shadow: #241a1c99;
  --color-tb11-shadow: oklch(0.24 0.015 15 / 0.6);
  --font-tb11-sans: "Manrope", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease-tb11-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-tb11-spring: cubic-bezier(0.16, 1, 0.3, 1);
  --animate-tb11-pop: tb-11-pop 0.6s var(--ease-tb11-spring);
  --animate-tb11-spark: tb-11-spark 0.62s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@supports (transition-timing-function: linear(0, 1)) {
  @theme {
    --ease-tb11-spring: linear(0, 0.45 7%, 0.85 15%, 1.12 23%, 1.18 28%, 1.1 36%, 1 50%, 1);
  }
}

@keyframes tb-11-pop {
  0% {
    scale: 1;
  }

  22% {
    scale: 0.75;
  }

  55% {
    scale: 1.28;
  }

  100% {
    scale: 1;
  }
}

@keyframes tb-11-spark {
  0% {
    opacity: 0;
    scale: 0.3;
    translate: 0 0;
  }

  25% {
    opacity: 1;
    scale: 1.1;
  }

  100% {
    opacity: 0;
    scale: 0.5;
    translate: 0 -1.55rem;
  }
}

.tb-11 {
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
}

@media (prefers-color-scheme: dark) {
  .tb-11:not([data-theme="light"]) {
    --color-tb11-bg: oklch(0.13 0.01 15);
    --color-tb11-surface: oklch(0.18 0.012 15);
    --color-tb11-line: oklch(0.28 0.015 15);
    --color-tb11-text: oklch(0.95 0.008 15);
    --color-tb11-muted: oklch(0.74 0.015 15);
    --color-tb11-like: oklch(0.72 0.17 12);
  }
}

.tb-11[data-theme="dark"] {
  --color-tb11-bg: oklch(0.13 0.01 15);
  --color-tb11-surface: oklch(0.18 0.012 15);
  --color-tb11-line: oklch(0.28 0.015 15);
  --color-tb11-text: oklch(0.95 0.008 15);
  --color-tb11-muted: oklch(0.74 0.015 15);
  --color-tb11-like: oklch(0.72 0.17 12);
}

@media (forced-colors: active) {
  .tb-11 label {
    border: 1px solid ButtonText;
    background: ButtonFace;
    color: ButtonText;
  }

  .tb-11 label:has(input:checked) {
    background: Highlight;
    color: HighlightText;
  }

  .tb-11 label span span span {
    display: none;
  }
}

Setup — do this once per project

Skip this if your project already runs Tailwind v4.

1Load Tailwind
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

Compiles in the browser — perfect for a CodePen or a quick test, not for production.

2Add the stylesheetRequiredthe @theme block is what makes the custom utilities exist
@import "tailwindcss";

@theme {
  --color-tb11-bg: #fbf7f7;
  --color-tb11-bg: oklch(0.976 0.006 15);
  --color-tb11-surface: #ffffff;
  --color-tb11-line: #eadfe0;
  --color-tb11-line: oklch(0.91 0.014 15);
  --color-tb11-text: #241a1c;
  --color-tb11-text: oklch(0.24 0.015 15);
  --color-tb11-muted: #6f6266;
  --color-tb11-muted: oklch(0.48 0.015 15);
  --color-tb11-like: #e11d48;
  --color-tb11-like: oklch(0.56 0.22 12);
  --color-tb11-like-line: #e11d4894;
  --color-tb11-like-line: oklch(0.56 0.22 12 / 0.55);
  --color-tb11-like-tint: #e11d4812;
  --color-tb11-like-tint: oklch(0.56 0.22 12 / 0.07);
  --color-tb11-spark-warm: #ef6a2a;
  --color-tb11-spark-warm: oklch(0.67 0.19 42);
  --color-tb11-spark-cool: #b13ba5;
  --color-tb11-spark-cool: oklch(0.55 0.21 330);
  --color-tb11-shadow: #241a1c99;
  --color-tb11-shadow: oklch(0.24 0.015 15 / 0.6);
  --font-tb11-sans: "Manrope", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease-tb11-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-tb11-spring: cubic-bezier(0.16, 1, 0.3, 1);
  --animate-tb11-pop: tb-11-pop 0.6s var(--ease-tb11-spring);
  --animate-tb11-spark: tb-11-spark 0.62s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@supports (transition-timing-function: linear(0, 1)) {
  @theme {
    --ease-tb11-spring: linear(0, 0.45 7%, 0.85 15%, 1.12 23%, 1.18 28%, 1.1 36%, 1 50%, 1);
  }
}

@keyframes tb-11-pop {
  0% {
    scale: 1;
  }

  22% {
    scale: 0.75;
  }

  55% {
    scale: 1.28;
  }

  100% {
    scale: 1;
  }
}

@keyframes tb-11-spark {
  0% {
    opacity: 0;
    scale: 0.3;
    translate: 0 0;
  }

  25% {
    opacity: 1;
    scale: 1.1;
  }

  100% {
    opacity: 0;
    scale: 0.5;
    translate: 0 -1.55rem;
  }
}

.tb-11 {
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
}

@media (prefers-color-scheme: dark) {
  .tb-11:not([data-theme="light"]) {
    --color-tb11-bg: oklch(0.13 0.01 15);
    --color-tb11-surface: oklch(0.18 0.012 15);
    --color-tb11-line: oklch(0.28 0.015 15);
    --color-tb11-text: oklch(0.95 0.008 15);
    --color-tb11-muted: oklch(0.74 0.015 15);
    --color-tb11-like: oklch(0.72 0.17 12);
  }
}

.tb-11[data-theme="dark"] {
  --color-tb11-bg: oklch(0.13 0.01 15);
  --color-tb11-surface: oklch(0.18 0.012 15);
  --color-tb11-line: oklch(0.28 0.015 15);
  --color-tb11-text: oklch(0.95 0.008 15);
  --color-tb11-muted: oklch(0.74 0.015 15);
  --color-tb11-like: oklch(0.72 0.17 12);
}

@media (forced-colors: active) {
  .tb-11 label {
    border: 1px solid ButtonText;
    background: ButtonFace;
    color: ButtonText;
  }

  .tb-11 label:has(input:checked) {
    background: Highlight;
    color: HighlightText;
  }

  .tb-11 label span span span {
    display: none;
  }
}
3Fonts used by this demooptional — skip if you have your own type stack
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Manrope:wght@500;600;700;800&display=swap">

What changed in the port

Which parts became utilities, which stayed CSS, and why.

  • Utilities: all of it except the keyframes — the label's checked styling, the heart's pop and fill, each spark's angle, the odometer slide and every reduced-motion fallback. CSS: two keyframe blocks and the linear() spring re-declaration.
  • Eight sparks means eight nearly-identical class lists where the CSS version had one rule plus eight one-line nth-child overrides. This is the port's honest cost, and it is still the right call: the angle is now visible on the element that flies at that angle.
  • The color-mix() spark tints became two named tokens (--color-tb11-spark-warm, --color-tb11-spark-cool). Naming them turned out to be a readability win — "warm" and "cool" say what the mix was for.
  • A11y fix from the CSS original: the resting count colour was oklch(0.48 ...) in light mode but #8a7a7d (≈3.6:1 on white) in the hex baseline. The port sets a single --color-tb11-muted at 4.9:1 in both branches.
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 demo 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: Tailwind Like Heart Button
Source: https://codefronts.com/components/tailwind-css-buttons/tailwind-like-heart-button/

A like button with a springy heart pop, eight radial sparks and a count that rolls over — no JavaScript. State lives in a checkbox, and has-checked: turns every downstream reaction into a variant on the element that reacts.
## HTML
```html
<div class="tb-11 w-full min-h-svh grid place-items-center bg-tb11-bg text-tb11-text font-tb11-sans antialiased p-[clamp(1.5rem,6vw,4rem)]">
  <label class="group relative cursor-pointer inline-flex items-center gap-2 min-h-12 pl-3.5 pr-4 rounded-full bg-tb11-surface border border-tb11-line text-[0.9375rem] font-bold tabular-nums text-tb11-muted shadow-[0_8px_20px_-16px_var(--color-tb11-shadow)] transition-[border-color,color,scale,background-color] duration-250 ease-tb11-out [-webkit-tap-highlight-color:transparent] hover:border-tb11-like-line hover:text-tb11-text hover:scale-[1.02] active:scale-[0.97] has-focus-visible:outline-2 has-focus-visible:outline-offset-[3px] has-focus-visible:outline-tb11-like has-checked:text-tb11-like has-checked:border-tb11-like-line has-checked:bg-tb11-like-tint motion-reduce:transition-none motion-reduce:hover:scale-100">
    <input type="checkbox" aria-label="Like this post" class="sr-only">
    <span aria-hidden="true" class="relative grid place-items-center size-7 text-tb11-muted group-hover:text-tb11-like group-has-checked:text-tb11-like">
      <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" class="size-6 transition-[scale,color,fill] duration-350 ease-tb11-out group-has-checked:fill-tb11-like group-has-checked:animate-tb11-pop motion-reduce:transition-none motion-reduce:group-has-checked:animate-none"><path d="M12 20.2s-7.4-4.3-7.4-9.4A4.3 4.3 0 0 1 12 8.1a4.3 4.3 0 0 1 7.4 2.7c0 5.1-7.4 9.4-7.4 9.4z"/></svg>
      <span class="absolute inset-0 pointer-events-none motion-reduce:hidden">
        <span class="absolute top-1/2 left-1/2 size-[0.28rem] -mt-[0.14rem] -ml-[0.14rem] rounded-full bg-tb11-like opacity-0 rotate-0 group-has-checked:animate-tb11-spark"></span>
        <span class="absolute top-1/2 left-1/2 size-[0.28rem] -mt-[0.14rem] -ml-[0.14rem] rounded-full bg-tb11-spark-warm opacity-0 rotate-45 group-has-checked:animate-tb11-spark"></span>
        <span class="absolute top-1/2 left-1/2 size-[0.28rem] -mt-[0.14rem] -ml-[0.14rem] rounded-full bg-tb11-like opacity-0 rotate-90 group-has-checked:animate-tb11-spark"></span>
        <span class="absolute top-1/2 left-1/2 size-[0.28rem] -mt-[0.14rem] -ml-[0.14rem] rounded-full bg-tb11-spark-warm opacity-0 rotate-[135deg] group-has-checked:animate-tb11-spark"></span>
        <span class="absolute top-1/2 left-1/2 size-[0.28rem] -mt-[0.14rem] -ml-[0.14rem] rounded-full bg-tb11-like opacity-0 rotate-180 group-has-checked:animate-tb11-spark"></span>
        <span class="absolute top-1/2 left-1/2 size-[0.28rem] -mt-[0.14rem] -ml-[0.14rem] rounded-full bg-tb11-spark-cool opacity-0 rotate-[225deg] group-has-checked:animate-tb11-spark"></span>
        <span class="absolute top-1/2 left-1/2 size-[0.28rem] -mt-[0.14rem] -ml-[0.14rem] rounded-full bg-tb11-like opacity-0 rotate-[270deg] group-has-checked:animate-tb11-spark"></span>
        <span class="absolute top-1/2 left-1/2 size-[0.28rem] -mt-[0.14rem] -ml-[0.14rem] rounded-full bg-tb11-spark-cool opacity-0 rotate-[315deg] group-has-checked:animate-tb11-spark"></span>
      </span>
    </span>
    <span aria-hidden="true" class="block h-5 overflow-hidden">
      <span class="tb-11__roll grid transition-[translate] duration-[550ms] ease-tb11-spring group-has-checked:-translate-y-5 motion-reduce:transition-none">
        <span class="block h-5 leading-5">2,417</span>
        <span class="block h-5 leading-5">2,418</span>
      </span>
    </span>
  </label>
</div>
```
## CSS
```css
@import "tailwindcss";

@theme {
  --color-tb11-bg: #fbf7f7;
  --color-tb11-bg: oklch(0.976 0.006 15);
  --color-tb11-surface: #ffffff;
  --color-tb11-line: #eadfe0;
  --color-tb11-line: oklch(0.91 0.014 15);
  --color-tb11-text: #241a1c;
  --color-tb11-text: oklch(0.24 0.015 15);
  --color-tb11-muted: #6f6266;
  --color-tb11-muted: oklch(0.48 0.015 15);
  --color-tb11-like: #e11d48;
  --color-tb11-like: oklch(0.56 0.22 12);
  --color-tb11-like-line: #e11d4894;
  --color-tb11-like-line: oklch(0.56 0.22 12 / 0.55);
  --color-tb11-like-tint: #e11d4812;
  --color-tb11-like-tint: oklch(0.56 0.22 12 / 0.07);
  --color-tb11-spark-warm: #ef6a2a;
  --color-tb11-spark-warm: oklch(0.67 0.19 42);
  --color-tb11-spark-cool: #b13ba5;
  --color-tb11-spark-cool: oklch(0.55 0.21 330);
  --color-tb11-shadow: #241a1c99;
  --color-tb11-shadow: oklch(0.24 0.015 15 / 0.6);
  --font-tb11-sans: "Manrope", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease-tb11-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-tb11-spring: cubic-bezier(0.16, 1, 0.3, 1);
  --animate-tb11-pop: tb-11-pop 0.6s var(--ease-tb11-spring);
  --animate-tb11-spark: tb-11-spark 0.62s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@supports (transition-timing-function: linear(0, 1)) {
  @theme {
    --ease-tb11-spring: linear(0, 0.45 7%, 0.85 15%, 1.12 23%, 1.18 28%, 1.1 36%, 1 50%, 1);
  }
}

@keyframes tb-11-pop {
  0% {
    scale: 1;
  }

  22% {
    scale: 0.75;
  }

  55% {
    scale: 1.28;
  }

  100% {
    scale: 1;
  }
}

@keyframes tb-11-spark {
  0% {
    opacity: 0;
    scale: 0.3;
    translate: 0 0;
  }

  25% {
    opacity: 1;
    scale: 1.1;
  }

  100% {
    opacity: 0;
    scale: 0.5;
    translate: 0 -1.55rem;
  }
}

.tb-11 {
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
}

@media (prefers-color-scheme: dark) {
  .tb-11:not([data-theme="light"]) {
    --color-tb11-bg: oklch(0.13 0.01 15);
    --color-tb11-surface: oklch(0.18 0.012 15);
    --color-tb11-line: oklch(0.28 0.015 15);
    --color-tb11-text: oklch(0.95 0.008 15);
    --color-tb11-muted: oklch(0.74 0.015 15);
    --color-tb11-like: oklch(0.72 0.17 12);
  }
}

.tb-11[data-theme="dark"] {
  --color-tb11-bg: oklch(0.13 0.01 15);
  --color-tb11-surface: oklch(0.18 0.012 15);
  --color-tb11-line: oklch(0.28 0.015 15);
  --color-tb11-text: oklch(0.95 0.008 15);
  --color-tb11-muted: oklch(0.74 0.015 15);
  --color-tb11-like: oklch(0.72 0.17 12);
}

@media (forced-colors: active) {
  .tb-11 label {
    border: 1px solid ButtonText;
    background: ButtonFace;
    color: ButtonText;
  }

  .tb-11 label:has(input:checked) {
    background: Highlight;
    color: HighlightText;
  }

  .tb-11 label span span span {
    display: none;
  }
}
```

How this works

Eight sparks, one keyframe. Each spark only declares its own angle as a rotate-* utility; the shared animation translates outward along the rotated axis, because individual transform properties compose without a single long transform string:

<span class="… rotate-45 group-has-checked:animate-tb11-spark"></span>

The count is a window, not a counter. Two stacked spans inside a fixed-height overflow-hidden box; checking the input slides the pair up one line. h-5 on both the window and each line is what keeps the landing exact.

The checkbox is real and stays real. sr-only, not hidden — it must remain focusable and announceable, so it reads as "Like this post, checkbox, checked" and toggles with Space. The heart fill and the count change are both visible without motion.

Make it yours

  • Add sparks by copying a span with a new rotate-* — the keyframe needs no change.
  • Bounciness lives in --ease-tb11-spring; more overshoot values equal a springier pop.
  • Recolour with --color-tb11-like: heart, sparks, tint and active count all derive from it.
  • Bookmark or upvote: swap the SVG path. Everything else is shape-agnostic.
  • Real counts: server-render the second roll span; CSS only slides the window.

Gotchas — read before shipping

  • The two stacked numbers must be exactly the window height or the roll lands off by a pixel. h-5 on both, same unit.
  • A checkbox-driven like button serialises in a form. Add form="" or switch to aria-pressed plus JS where that matters.
  • sr-only, never hidden — a hidden input is not focusable and leaves the accessibility tree.
  • Don't animate the sparks' size with w-*/h-*; eight simultaneous layout animations is the one thing here that will drop frames.
  • has-checked: reads any checked descendant. Fine with one input per label, wrong the moment there are two.

Browser support

ChromeSafariFirefoxEdge
113+17.2+128+113+

:has() (Chrome 105 / Safari 15.4 / Firefox 121) drives every has-checked: variant; linear() easing needs Chrome 113 / Safari 17.2 / Firefox 112 and falls back to the declared cubic-bezier.

Techniques used in this demo

Utilitiesfirst-class utility or variant

Search CodeFronts

Loading…