Components

Countdown

An animated countdown timer for React: days, hours, minutes and seconds to any date, with digits that roll or flip as they change. Includes a compact inline variant, an onComplete callback and screen reader announcements throttled to once a minute. Hydration-safe for Next.js.

  • Roll & flip digits
  • Compact variant
  • onComplete
  • Hydration-safe
  • Throttled announcements
  • Reduced-motion safe

Dusk 2.0 goes live in

Installation

$ npx shadcn@latest add https://duskui.com/r/countdown.json

The server never knows the visitor's clock, so the server render shows dashes and the digits start ticking right after hydration. Pass a fixed date (an ISO string with a timezone offset is safest), or pass null while you compute one in an effect.

Usage

launch.tsx
import { Countdown } from "@/components/dusk/countdown/countdown"

export function Launch() {
  return <Countdown target="2027-01-01T00:00:00Z" label="Time until launch" />
}

Examples

Flip animation

animation="flip" turns each digit over like a drum. units picks what to show; the largest unit absorbs the rest, so hours can go past 24 here.

Until the stream starts

Compact

variant="compact" fits on one line, in banners and buttons. Short labels (d, h, m, s) are the default; override them with labels.

Spring sale: 40% off annual plansends in

Completion

onComplete fires once when the timer hits zero, and completed replaces the digits. Changing target to a future time starts it again.

onComplete fired 0×

API Reference

Any other div prop is passed to the root. Every countdown on the page shares one timer aligned to the second, so many timers stay in sync and cost almost nothing.

PropTypeDefaultDescription
targetDate | number | string | null—When it ends. null keeps the placeholders.
units("days" | "hours" | "minutes" | "seconds")[]all fourUnits to show; the largest absorbs the rest.
labelsPartial<Record<Unit, string>>—Text per unit. Defaults to Days/Hours… or d/h… when compact.
variant"default" | "compact""default"Boxed digits with labels, or one inline line.
animation"roll" | "flip""roll"How a digit changes.
onComplete() => void—Called once at zero (also on mount if the target has passed).
completedReactNode—Rendered instead of the digits when it's over.
labelstring"Countdown"Accessible name of the timer.
completeTextstring"Countdown finished"Announced when it ends.
unitClassNamestring—Classes for each unit's box.

Accessibility

  • The ticking digits are hidden from screen readers; a polite live region reads the time left instead.
  • That announcement is rounded to the minute ("2 days, 3 hours, 12 minutes remaining"), so it changes at most once a minute instead of every second.
  • The group has an accessible name via label, and completeText is announced when it ends.
  • With prefers-reduced-motion digits crossfade instead of rolling or flipping.
  • Digits sit in fixed-width tabular slots, so nothing around the timer shifts as it counts.