Web · Components
Countdown
Countdown or count-up: a sale ending, an event starting, exam time, a "resend code" wait, call duration.
Live example
Preview
Code
Events
- Events appear here when you interact with the preview.
Campaign card
Resend code (a component instead of useCountdown)
Import
Countdown or count-up: a sale ending, an event starting, exam time, a "resend code" wait, call duration.
- Three modes:
to(until a moment),duration(ms, a timer starting when rendered),from(time elapsed since that moment). - Appearance:
clock(03:04:05),text(3 hours 4 minutes) orboxes. Unit names are written per locale withIntl; no translation needed. - Efficient: renders only when the smallest visible unit changes; stops while the tab is hidden. Digits are fixed width, so the text doesn't jiggle.
- SSR safe: the server clock isn't trusted; a placeholder on the first render, the real value right after hydration.
- Accessibility:
role="timer"and<time dateTime="PT…">; not announced every second, "Time's up" is read once at the end.
For your own UI see useCountdown.
Examples
splitDuration
functionSplits a duration into the given units. The largest unit collects the overflow: with ["hours", "minutes"], 2 days 3 hours → 51 hours.
Examples
autoUnits
function"auto" units: from the largest non-zero unit of the duration down to seconds (3 hours → hours, minutes, seconds). Minutes and seconds always show, so the format does not jump when the time drops to 59 seconds.
isoDuration
functionISO 8601 duration string (for <time dateTime>): P1DT2H3M4S.
unitLabel
functionOnly the unit name, by language and number ("gün", "days", "day"). Uses Intl; no translation needed.
formatCountdown
functionTurns a duration into readable text: "2 days 3 hours 4 minutes". Zero units are skipped (the smallest unit is written when all are zero).
useCountdown
functionCountdown or count-up hook: for drawing your own UI.
- Efficient: wakes not every second but when the smallest visible unit changes (once a minute if only minutes are shown). The timer stops while the tab is hidden and is recomputed from the real clock on return; no drift.
- SSR: since server and client clocks differ, the first render returns
ready: false; the value arrives right after hydration.
Examples
CountdownVariant
typeCountdown appearance.
CountdownClassNames
interfaceClasses that can be given to the inner parts of Countdown.
| Name | Type | Description |
|---|---|---|
unit? | string | Unit box (boxes) or unit group. |
value? | string | Number. |
label? | string | Unit name. |
separator? | string | Separator (:). |
CountdownProps
interfaceProps of the Countdown component.
| Name | Type | Default | Description |
|---|---|---|---|
variant? | CountdownVariant | CustomVariant<"countdown"> | "clock" | Appearance: built-in or a custom style added with defineAppearance (its classes are added to the root; in the clock layout when extends is omitted). Defaults to UIProvider appearance.defaults.countdown.variant. See CountdownVariant. |
effect? | EffectProp | Effect or effects (e.g. "shine", ["lift", "beam"]). Applied to each unit box with the boxes appearance, otherwise to the counter itself. Defaults to UIProvider appearance.defaults.countdown.effect. See BuiltinEffect. | |
size? | "sm" | "md" | "lg" | "md" | Size. |
tone? | Tone | "neutral" | Color of the boxes with the boxes appearance. |
urgent? | number | When the remaining time drops below this (ms) it looks "urgent": red with a light pulse (no pulse with the reduced motion preference). Works for countdowns. | |
labels? | "long" | "short" | "narrow" | false | "long" | Unit names: full ("long": minutes), short ("short": min) or narrowest. |
completed? | ReactNode | Content shown when finished (e.g. "The sale has started!"). Zeros are shown when omitted. | |
placeholder? | ReactNode | "–"` (in each digit) | Placeholder until the numbers are first read (server render, hydration). |
label? | string | Screen reader name (e.g. "Time left until the sale ends"). The counter isn't announced every second; it is announced once at the end. | |
tooltip? | TooltipProp | Tooltip on hover. See TooltipProp. | |
className? | string | Classes added to the container. | |
classNames? | CountdownClassNames | Classes added to the inner parts. | |
to? | CountdownDate | Moment the countdown ends (a sale ending, an event starting). Server and client clocks look at the same moment; the time zone doesn't matter. | |
duration? | number | Duration (ms): a timer starting when the component first renders (or with reset). For exams, "resend code", payment time, etc. Ignored when to is given. | |
from? | CountdownDate | Count-up start: time elapsed since this moment is counted (call duration, live stream duration). Used when to and duration are omitted. | |
units? | readonly CountdownUnit[] | "auto" | "auto" | Units shown; the value updates only when the smallest one changes. "auto" picks by duration (days if any, otherwise hours…). See CountdownUnit. |
precise? | boolean | false | Update with millisecond precision (stopwatch, competition)? Renders every frame; turn it on only when needed. |
paused? | boolean | false | Paused? The remaining time is kept while paused. |
onComplete? | () => void | Called once when the countdown ends. | |
onTick? | (parts: CountdownParts) => void | Called whenever the visible value changes. |
CountdownDate
typeDate: Date, an ISO string ("2026-12-31T23:59:59+03:00") or milliseconds.
CountdownUnit
typeUnits that can be shown, largest to smallest.
CountdownParts
interfaceThe remaining (or elapsed) time split into units.
| Name | Type | Description |
|---|---|---|
total | number | Total time (ms); 0 when a countdown ends. |
days | number | Days. Added to hours when days are not shown. |
hours | number | Hours. |
minutes | number | Minutes. |
seconds | number | Seconds. |
milliseconds | number | Milliseconds (0–999). |
UseCountdownOptions
interfaceOptions of the useCountdown hook.
| Name | Type | Default | Description |
|---|---|---|---|
to? | CountdownDate | Moment the countdown ends (a sale ending, an event starting). Server and client clocks look at the same moment; the time zone doesn't matter. | |
duration? | number | Duration (ms): a timer starting when the component first renders (or with reset). For exams, "resend code", payment time, etc. Ignored when to is given. | |
from? | CountdownDate | Count-up start: time elapsed since this moment is counted (call duration, live stream duration). Used when to and duration are omitted. | |
units? | readonly CountdownUnit[] | "auto" | "auto" | Units shown; the value updates only when the smallest one changes. "auto" picks by duration (days if any, otherwise hours…). See CountdownUnit. |
precise? | boolean | false | Update with millisecond precision (stopwatch, competition)? Renders every frame; turn it on only when needed. |
paused? | boolean | false | Paused? The remaining time is kept while paused. |
onComplete? | () => void | Called once when the countdown ends. | |
onTick? | (parts: CountdownParts) => void | Called whenever the visible value changes. |
UseCountdownResult
interfaceValue returned by the useCountdown hook.
Extends: CountdownParts
| Name | Type | Description |
|---|---|---|
done | boolean | Has the countdown ended? Always false for a count-up. |
running | boolean | Counting (not paused and not finished)? |
ready | boolean | Has the clock been read on the client? false on the server and the first hydration; showing a placeholder instead of the value meanwhile prevents a hydration mismatch. |
units | readonly CountdownUnit[] | Units shown ("auto" resolved). |
direction | "down" | "up" | Counting direction: to/duration → "down", from → "up". |
pause | () => void | Pauses. Stable. |
resume | () => void | Resumes where it left off. Stable. |
reset | (duration?: number) => void | Starts over: in duration mode the duration restarts (a new duration can be given); for a count-up the elapsed time resets. Stable. |