Time left to an absolute instant in tiles of tabular digits; the colon's ball carries each borrow and spent units fold away until a pill says it is time.
Order within000201040003for delivery before the 24th
Winter gift shop
Wrapping is free on every order until Christmas Eve.
Larchwood Supply
Christmas Day in
0203Days0105Hours0000Minutes0000Seconds
countdown · , lively
countdown-demo.tsx
When to use
Use it for an absolute deadline people act on. One countdown per screen is enough. Server rendering is safe: pass the server's time as now so the first render matches.
When not to use
For a date that is days away and changes no decision, write the date. For one door per day use Advent Calendar.
Use it for a real deadline people act on: the last order for Christmas delivery, sale prices held
until Sunday night, a code freeze that lifts at midnight on New Year's Eve. One countdown per
screen is enough. For a date that is days away and does not change a decision, write the date
instead.
import { Countdown } from "@/components/ui/countdown"export function SaleEnds() { return <Countdown target="2026-12-24T23:59:00+01:00" completeContent="Sale ended" />}
Only the digit that changes moves: the old one sinks 2 px, the new one drops into the tile and
squashes on its floor. When a unit rolls over (the seconds go from 00 to 59), the ball at the
top of the colon hops onto the tile on its left and knocks it: it carries the borrow, once a
minute, never every second. Leading units that run out fold into their neighbour (shed, on by
default) until one tile is left; at zero it stretches into a pill holding completeContent, and
onComplete runs once.
temperament="calm" keeps every beat with no bounce: use it in a checkout.
target is an absolute instant: a Date, epoch milliseconds, or an ISO string with an
offset. The same instant is the same moment everywhere, so the component never guesses a time
zone. Two recipes:
// One moment for everyone: the sale ends at 23:59 in Rome.;<Countdown target="2026-12-27T23:59:00+01:00" />// Midnight where the visitor is: compute it on the client, after mount.const [target, setTarget] = useState<number | null>(null)useEffect(() => { const now = new Date() setTarget(new Date(now.getFullYear() + 1, 0, 1).getTime())}, [])
Say whose clock it is next to the countdown. Intl gives the zone's short name on the client:
const zone = new Intl.DateTimeFormat("en-GB", { timeZoneName: "short" }) .formatToParts(new Date("2026-12-27T23:59:00+01:00")) .find((part) => part.type === "timeZoneName")?.value// "Ends 23:59 CET"
No clock is read during render. Pass now, the server's clock for this request, and the server
and the first client render show the same digits: no hydration mismatch, no flash. Ticking starts
after mount and, if the device clock is off by more than five seconds, follows the server's. Read
now per request (in Next.js, after await connection()), never from a cached page.
import { connection } from "next/server"export default async function Banner() { await connection() return <Countdown target="2026-12-24T00:00:00+01:00" now={Date.now()} />}
Without now, the first render shows dashes in the reserved space and the digits appear on the
first tick. Each tick recomputes the time left from the clock (it never decrements a counter),
lands on second boundaries, stops in hidden tabs and off screen, and resyncs on return. The end
still arrives on time while hidden.
The group has role="timer" and an accessible name (labels.timer, default "Time left"); give
it one that says what ends.
A <time dateTime> carries the target instant and reads the time left in words to the minute,
for anyone who browses to it.
One visually hidden aria-live="polite" line speaks full sentences at thresholds only: each day,
each hour of the last day, 10, 5 and 1 minute, and the end. Never every second.
The animated digits, captions and colon balls are aria-hidden; the balls take no pointer.
Every caption and sentence is in labels for localisation (remaining builds the sentence).
Text keeps AA contrast in both themes. The last minute changes weight and turns primary; it
never dims.
Digits swap with a 120 ms fade, spent units disappear without travel, the colon ball stays still
and the pill appears with a fade. The time keeps ticking: it is information, not decoration.
One timer, aligned to second boundaries, and only while the countdown is on screen in a visible
tab; otherwise a single timer to the end. React re-renders once a second, and only the changed
digit animates (transform and opacity).
Width is reserved per unit with tabular figures, so a rollover never moves the layout; shedding
is the one planned change and runs on the calm spring.
Motion only, no canvas. Free dependencies: ball, motion-kit.
Technical sheet
Motion
calm
260 ms · bounce 0
lively
400 ms · bounce 0.3
playful
540 ms · bounce 0.45
Main spring of each temperament. Set it with the temperament prop or MotionKitProvider; the default is lively.
Size
Not measured yet · budget 6.0 kB gzip
Component and MotionKit helpers; excludes react, react-dom, motion.
Dependencies
motion · peer
Triggers
a value change, entering the viewport
Reduced motion
Digits swap with a 120 ms fade, spent units disappear without travel and the colon ball stays put; the time keeps ticking.
Keyboard
No keyboard interaction of its own.
Browsers
Last 2 versions of Chrome, Edge, Firefox and Safari (iOS 16.4+)