Like burst
NewA like button whose heart fills inside a spinning ring of sparks, which throws sparks off as it turns and closes over the heart.
like-burst/like-burst.tsxThe live component, numbered part by part. Every measurement is read from it as it is drawn. Point at a row to outline its part, or at a part to find its row.
The choices it offers, each value drawn live and the default marked, with how to pick one.
When to use
- The like on a post, a photo or a comment in a feed: one tap that says “I liked this”, with a count beside it.
- A favourite or a save that should feel rewarding the first time, and is cheap to undo.
- A product with a dark interface or a playful voice, where a short burst of light suits the moment.
When not to use
- A rating. One heart is on or off; use stars or a scale to say how much.
- Anything with a consequence, such as following, buying or sending. A celebration there reads as pressure; use a plain button.
- Long lists where many hearts can be pressed in a row, such as selecting items. Use checkboxes: a burst on each is noise.
- A tight row with no room around the heart. The burst draws 1.5 heart sizes out from its centre, over its neighbours.
The sequence
- 0 s: the outline leaves in 0.12 s, a small fill appears, and a ring of fire opens around it in 0.22 s, already spinning.
- 0.06 s: sparks start to fly off the ring along the turn and fall, each living about a third of a second.
- 0.72 s: the ring slows and closes over the heart, throwing a last ring of faster sparks, as the heart grows to 116%.
- 1.1 s: the heart settles at its size; at 1.2 s the canvas is clear.
- Unlike: the fill shrinks and fades in 0.18 s while the outline springs back. No burst.
Counting
- Pass the others’ likes:
countleaves the reader’s own like out, so liking and unliking never need a round trip to show the right number. - Save it in the background: call your API from
onLikedChangeand, if it fails, setlikedback.
Each one drawn with the component itself, used well or badly.
The only words are its name and its number.
- The name is the action, the same liked or not:
Like.aria-pressedsays which. - The number is the full count with separators:
1,284, not1.2K.
You can add this component with the shadcn CLI or by hand:
Into components/like-burst of any React project, with no setup:
npx shadcn@latest add https://brunodelorence.com/r/like-burst.json- Copy the component files
Copy these files into one folder of your project, keeping their relative imports together, or download them as a ZIP:
- Import it
As shown under Usage, below.
Either way it needs React 19.2 and a bundler that supports CSS Modules, such as Next.js or Vite. It has a dark colour scheme: it follows your page’s color-scheme, light unless the page sets one, or its colorScheme prop, with nothing to configure. Browsers without light-dark() show it light.
Usage
import { useState } from 'react';import { LikeButton } from './like-burst';export function PostActions({ post }: { post: { id: string; likes: number; liked: boolean } }) { const [liked, setLiked] = useState(post.liked); return ( <LikeButton liked={liked} // Everyone else's likes: the button adds one while it is liked. count={post.likes - (post.liked ? 1 : 0)} onLikedChange={(next) => { setLiked(next); fetch(`/api/posts/${post.id}/like`, { method: next ? 'PUT' : 'DELETE' }); }} /> );}Each state below is a live instance, locked so you can study it.
The pieces it is built from, each with its measurements read live.
A heart button with a count, at any size. Liked, the outline gives way to a small pink heart and a ring of fire opens around it: a white-hot line under a hundred and fifty short arcs racing round, with an orange glow on both sides and an edge that flickers. As it spins, sparks fly off it along the turn and fall away, cooling from white to red. Then the ring closes over the heart, throwing a last ring of faster sparks, and the heart grows past its size and settles. Unliked, it only fades back to the outline. The whole burst takes 1.2 s and is drawn on a canvas over the button, so it takes no room in the layout.
- The heart is two SVGs over each other, an outline 2/24 of it thick and a fill; which one shows is plain CSS from data-liked, so a liked button rendered on the server is already right.
- One clock from the press: the outline leaves in 0.12 s, the fill appears at 56% of its size and holds at about 60% while the ring spins, grows to 116% as the ring closes at 0.88 s, and settles at 100% by 1.1 s. Its keyframes are one Web Animations API call.
- The burst is a pure function of the time since the press, in burst.ts: the canvas is redrawn each frame for 1.2 s, then cleared. Every length is a share of the heart’s size, so it scales with the button, and the same function draws any single frame as a still (freezeAt).
- The ring opens from 0.3 to 0.8 heart sizes in 0.22 s with a small overshoot, spins at 10 radians a second (about 1.6 turns), and from 0.72 s closes to 0.3 as it slows.
- It is drawn in three layers: a radial glow on both sides of the ring, a thin white-hot core line, and 150 short arcs from a seeded generator, hottest at their heads, each drifting a little ahead of or behind the ring and wavering on its radius. Two slow sine waves make the whole ring flicker.
- The sparks are a particle system with no state: 320 are born while the ring spins and 64 more as it closes, each at a set time and angle. Where one is at any moment is worked out from its launch, along the spin and slightly outward, and gravity, so a still shows exactly the frame the animation does. Each is drawn as a streak from where it was 70 ms before, cooling from white to orange to red as it fades.
- On a dark page the fire adds light (globalCompositeOperation lighter); on a light one it is painted over in deeper oranges, and every gradient fades to the fire’s own colour at no opacity, so nothing greys. The script tells the schemes apart from the canvas’s colour, a light-dark() token that is white in the dark scheme.
- The count is everyone else’s likes, plus one while liked; it rolls up or down by its own height on a change. The demo’s pointer likes, waits, unlikes and likes again while nobody touches the stage.
| Prop | Type | Default | Description |
|---|---|---|---|
liked | boolean | — | Whether it is liked, if you hold it; pair it with onLikedChange. |
defaultLiked | boolean | false | Whether it starts liked, when it holds it itself. |
onLikedChange | (liked: boolean) => void | — | Called with the new value on every press. |
count | number | — | Everyone else’s likes: the number shown is this, plus one while it is liked. Left out, no number shows. |
size | number | 24 (88 in LikeBurst) | The heart’s width in px; the burst reaches 1.5 times it out from the heart’s centre. |
label | string | 'Like' | The button’s accessible name; the count is read after it. |
burst | boolean | true | false keeps the pop of the heart and leaves out the ring and the dashes. |
freezeAt | number | — | Holds a like’s animation still at this many ms, from 0 to 1200, for stills and docs. |
autoplay | boolean | true | LikeBurst only: while on screen and untouched, a pointer likes and unlikes it; never under reduced motion. |
colorScheme | 'light' | 'dark' | 'system' | — | Forces a scheme. Left out, it follows the page. |
className | string | — | Added to the button (or the stage). |
Focus and keyboard
- It is one button: Tab reaches it, Space and Enter press it.
- The focus ring is a 2 px blue outline 4 px off the button.
Screen readers
- It is read as a toggle with its count, such as “Like, 1,284, toggle button, pressed”.
- The heart, the canvas and the demo pointer are hidden.
Motion
With reduced motion there is no burst, pop or roll: the fill fades in over 0.16 s, and the demo does not play.
In this build
- A real button with aria-pressed, so it is read as a toggle: “Like, 1,284, toggle button, pressed”. Space and Enter press it.
- The heart and the canvas are hidden from screen readers; the count is plain text inside the button, read after its name.
- The focus ring is a 2 px outline 4 px off the button. The hover tint and colour need a pointer that hovers.
- Under reduced motion there is no burst, pop or roll: the fill fades in over 0.16 s, and the demo does not play.
The complete source behind this demo. Open source under the MIT license, © 2026 Bruno Delorence: copy it, change it, ship it.
// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import { useCallback, useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type Ref,} from 'react';import { BURST_MS, DARK, LIGHT, REACH, drawBurst } from './burst';import { DemoPointer, runDemo } from './demo-pointer';import styles from './like-burst.module.css';import { useAutoplay } from './use-autoplay';/* * A like button whose heart, when liked, fills inside a spinning ring of sparks that throws * sparks off as it turns and closes over the heart. LikeButton is the button, at any size; * LikeBurst is the demo: one large button on a stage, which a pointer likes and unlikes while * nobody touches it. */* Like burst (like-burst.tsx): a heart button. The heart is --size wide; the outline is drawn 2/24 of it thick, and the burst's canvas reaches --reach heart sizes out from its centre, over whatever surrounds the button, without taking any room in the layout. The stage is the demo's: a dark page, as on a social app at night, or a pale one by day. */.button,.stage { --stage: #f6f7f8; --idle: #6e7a86; --idle-hover: #c92a6b; --liked: #e0245e; --tint: rgb(224 36 94 / 0.1); --count: #56606b; --count-liked: #c4204f; --focus: #1d9bf0; /* Read by the script: white in the dark scheme, black in the light one. */ --probe: #000;}.button { position: relative; display: inline-flex; align-items: center;// Copyright (c) 2026 Bruno Delorence. MIT License./* * The burst around a heart that has just been liked: a spinning ring of sparks, drawn on a canvas * as a pure function of the time since the press. `drawBurst(ctx, t, size, palette)` paints the * frame at `t` ms, so the component can play it frame by frame or hold any single frame still * (freezeAt). Every length is a share of the heart's size `s`, so it scales with the button. * * 0–220 ms the ring opens around the heart, from 0.3 to 0.8 heart sizes, overshooting a * little, already turning fast (about 1.6 turns a second). * 220–720 ms it spins in place: a white-hot core line under 150 short arcs of fire that race * round it, its edge flickering, while sparks fly off it along the spin and fall. * 720–960 ms it closes over the heart and throws a last ring of faster sparks; the sparks * still in the air finish their fall by 1.2 s. * * The sparks are a particle system with no state: each is born at a set time and angle from a * seeded generator, and its place at any moment is worked out from its launch (along the spin, * slightly outward) and gravity. So a still at 0.5 s is exactly the frame the animation shows. *//** How long the whole burst lasts, in ms. */export const BURST_MS = 1200;/** When the ring starts to close, in ms: the heart grows as it does. */// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import type { CSSProperties, Ref } from 'react';/* * The demo's pointer, and the steps that move it. A demo is a script of awaited steps: wait, or * glide the pointer somewhere. Stopping the demo (the reader takes over, or it scrolls away) ends * the step in progress at once: its promise rejects, which ends the script right there, and the * pointer fades out. * * Each glide is a curved flight played by the Web Animations API, so nothing runs frame by frame. * The points of the flight are handed to whoever wants to move along with it (nothing here uses * them yet). The arrow and the text cursor are HTML boxes * that swap by their visibility: a change of style inside an SVG would lay the SVG out again. */export type Point = { x: number; y: number };/** A glide's path and timing, for an animation that plays along with it. */export type Flight = { points: Point[]; timing: KeyframeAnimationOptions };export type Demo = {// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import { useCallback, useEffect, useRef, useState } from 'react';/* * When a demo may play on its own: while part of it is on screen and the tab is visible, never * under reduced motion, and never again once the reader has used it: `take()` hands it to the * reader for good (until the component mounts again), so it can't come back on its own. */export function useAutoplay<T extends HTMLElement>() { const ref = useRef<T>(null); const [visible, setVisible] = useState(false); const [reduced, setReduced] = useState(true); const [taken, setTaken] = useState(false); useEffect(() => { const element = ref.current; if (!element) return; let onScreen = false; const update = () => setVisible(onScreen && !document.hidden); const observer = new IntersectionObserver( ([entry]) => {