webdevpuneet.com

Like Burst Button — Free HTML CSS JS Heart Particle Snippet

Like Burst Button · Buttons · Plain HTML, CSS & JS · Live preview

CategoryButtons

Copy & paste

Source Code

<div class="lk-stage">
  <button type="button" class="lk-btn" id="lkBtn" aria-pressed="false">
    <span class="lk-heart" id="lkHeart">
      <svg viewBox="0 0 24 24"><path d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"/></svg>
    </span>
    <span class="lk-count" id="lkCount">128</span>
  </button>
</div>

Extend with AI

Take This Snippet Further With AI

The AI prompt for this one is for Patreon supporters ($3 a month, 7 days free), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.

· Become a supporter

What's included

Features

Spring heart pop
An overshooting scale brings it to life.
Radial particle burst
Evenly-angled dots spray outward.
WAAPI fire-and-forget
Particles self-remove on finish.
Organic dissipation
Randomized distance and duration.
Optimistic count
Updates instantly on toggle.
Like and unlike
Burst only celebrates the like.
aria-pressed toggle
Correct toggle-button semantics.
No accumulation
Particles clean themselves up.

About this UI Snippet

Like Burst Button — Heart Pop With a Radial Particle Burst

Screenshot of the Like Burst Button snippet rendered live

The like burst button is the satisfying social interaction — popularized by Twitter and Instagram — where tapping a heart makes it pop into color and spray a radial burst of colorful particles outward, with the count ticking up. This snippet builds it with plain HTML, CSS, and vanilla JavaScript using the Web Animations API for the particles.

The heart pop

The heart is an inline SVG that is gray at rest. On like, a .liked class fills it red and runs the lkPop keyframe, which scales it from 0 up past 1 to 1.25 and settles back to 1 on an overshooting cubic-bezier. That brief overshoot is the bounce that makes the heart feel like it springs to life rather than just recoloring. The count next to it also turns red, reinforcing the active state.

The radial particle burst

The burst is generated on each like: twelve small particle dots are created and appended over the heart, each assigned a color from a small palette. The key is the radial distribution — each particle is sent to an angle of (i / n) * 2π (evenly around the circle) with a little random jitter, at a random distance, computed with cos/sin. Animating each particle from the heart center out to its (cos·dist, sin·dist) offset while scaling to zero and fading produces the firework spray. The even angular spacing is what makes it read as a deliberate burst rather than random scatter.

Web Animations API for fire-and-forget particles

Each particle animates with element.animate(), which returns a handle with an onfinish callback used to remove the particle from the DOM when its animation completes (this.effect.target.remove()). This fire-and-forget pattern means particles clean themselves up and never accumulate, without managing CSS animation classes or animationend listeners across a dozen short-lived elements. Randomizing each particle duration slightly makes the burst dissipate organically rather than all at once.

Optimistic toggle and count

Clicking toggles the liked state and adjusts the count immediately (+1 on like, -1 on unlike) — an optimistic update that makes the UI feel instant. Unliking removes the red state without a burst, since bursts celebrate the positive action. In a real app you would fire the network request in the background and reconcile if it fails; the visual is decoupled from the round-trip.

Accessible state

The control is a real <button> with aria-pressed that flips between true and false, so assistive tech announces the like as a toggle button with its current state — the correct semantics for a like control, rather than a generic clickable element.

Customizing it

Change the particle count, colors, spread distance, and durations for a bigger or subtler burst, adjust the heart pop overshoot, recolor the liked state, or swap the heart for a star or thumbs-up. Wire the click to your real API. Pair it with a favorite button or an emoji reaction bar for a full reaction set.

Step by step

How to Use

  1. 1
    Paste HTML, CSS, and JSA like button shows a gray heart and a count.
  2. 2
    Click the heartIt pops red and sprays a burst of colorful particles.
  3. 3
    Watch the countIt ticks up immediately on like.
  4. 4
    Click againIt unlikes and the count drops, with no burst.
  5. 5
    Tune the burstChange particle count, colors, and spread.
  6. 6
    Wire your APIFire the real request in the click handler.

Real-world uses

Common Use Cases

Social feed posts
Like posts in a social post card, with a spring pop and a radial burst of evenly angled particles.
Reaction controls
Pair with an emoji reaction bar so people can choose between a quick like and a richer reaction.
Bookmarks and saves
Offer an alternative to a favorite button, with an optimistic count and a pressed state announced by aria-pressed.
Product wishlists
Heart items on a product card, where particles fire through the Web Animations API and remove themselves when done.
Comment upvotes and particle reference
Celebrate a voting buttons action for comment upvotes, and study randomised distance and duration for organic particle dissipation.
Related: Push Notification Subscription Toggle
See the Push Notification Subscription Toggle for a related buttons pattern worth pairing with this one.

Got questions?

Frequently Asked Questions

On each like, twelve particle dots are appended over the heart, each colored from a palette and sent to an angle of (i / n) times 2 pi — evenly around the circle — with slight random jitter and a random distance. Animating each from the center to its cos and sin offset while scaling to zero and fading produces the firework spray. The even angular spacing makes it read as a deliberate burst.

Each particle is animated with the Web Animations API, whose returned handle has an onfinish callback. That callback removes the particle when its animation completes, so they clean themselves up. This fire-and-forget pattern avoids managing CSS classes and animationend listeners across a dozen short-lived elements.

The lkPop keyframe scales the heart from 0 past 1 to 1.25 and settles back to 1 on an overshooting cubic-bezier. That brief overshoot is a spring bounce, so the heart appears to spring into existence rather than simply changing color. The count turning red at the same moment reinforces the active state.

It is an optimistic update: toggling adjusts the count immediately so the UI feels instant. In a real app you fire the like request in the background and reconcile if it fails. Decoupling the visual from the round-trip is what makes the interaction feel responsive even on a slow connection.

Keep liked and count in state and toggle them on click, calling your API in the background. Trigger the burst by appending particles to a ref and animating them with element.animate, cleaning up on finish — keep this out of the render path. Use aria-pressed bound to the liked state. The heart pop is pure CSS. In Tailwind, animate the pop with a keyframe and run the particles in the handler.