Data display
Countdown
Free11.8 KB gzippedA live countdown to a moment: the end of a sale, the start of an event, tip-off. Updates every second (or every minute without seconds), shows the time in tiles or inline text, and calls onComplete at zero.
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · No keyboard interaction of its own · Full report
Import
import { Countdown } from "@vjdesigns/vjdesigns-ui";
Importing only Countdown adds about 11.8 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Basic
to takes an ISO 8601 date-time or milliseconds since the epoch. Include the offset (Z or -05:00) so everyone counts down to the same moment.
import { useState } from "react";
import { Countdown } from "@vjdesigns/vjdesigns-ui";
const SECOND = 1000;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const DAY = 24 * HOUR;
export function Basic() {
const [to] = useState(() => Date.now() + 2 * DAY + 4 * HOUR + 30 * MINUTE);
return <Countdown to={to} aria-label="Registration closes in" />;
}
Variants
Four tile styles: solid (the default), soft, outline and plain.
import { useState } from "react";
import { Countdown, Stack } from "@vjdesigns/vjdesigns-ui";
const SECOND = 1000;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const DAY = 24 * HOUR;
export function Variants() {
const [to] = useState(() => Date.now() + 3 * DAY + 8 * HOUR);
return (
<Stack gap={4}>
<Countdown to={to} variant="solid" tone="primary" />
<Countdown to={to} variant="soft" tone="primary" />
<Countdown to={to} variant="outline" tone="primary" />
<Countdown to={to} variant="plain" />
</Stack>
);
}
Tones
tone colors the solid, soft and outline tiles.
import { useState } from "react";
import { Countdown, Stack } from "@vjdesigns/vjdesigns-ui";
const SECOND = 1000;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const DAY = 24 * HOUR;
export function Tones() {
const [to] = useState(() => Date.now() + 5 * HOUR);
return (
<Stack gap={4}>
<Countdown to={to} units={["hours", "minutes", "seconds"]} tone="neutral" />
<Countdown to={to} units={["hours", "minutes", "seconds"]} tone="accent" />
<Countdown to={to} units={["hours", "minutes", "seconds"]} tone="success" />
<Countdown to={to} units={["hours", "minutes", "seconds"]} tone="danger" variant="soft" />
</Stack>
);
}
Sizes
import { useState } from "react";
import { Countdown, Stack } from "@vjdesigns/vjdesigns-ui";
const SECOND = 1000;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const DAY = 24 * HOUR;
export function Sizes() {
const [to] = useState(() => Date.now() + 5 * DAY + 12 * HOUR);
return (
<Stack gap={4}>
<Countdown to={to} size="sm" tone="accent" />
<Countdown to={to} size="md" tone="accent" />
<Countdown to={to} size="lg" tone="accent" />
</Stack>
);
}
Inline
layout="inline" is one line of text in the surrounding color, for a sentence, a Banner or a Button. Leading zero units are dropped.
Early-bird pricing ends in
Black Friday
import { useState } from "react";
import { Banner, Countdown, Stack, Text } from "@vjdesigns/vjdesigns-ui";
const SECOND = 1000;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const DAY = 24 * HOUR;
export function Inline() {
const [earlyBird] = useState(() => Date.now() + 2 * DAY + 4 * HOUR);
const [sale] = useState(() => Date.now() + 14 * HOUR + 20 * MINUTE);
return (
<Stack gap={4}>
<Text>
Early-bird pricing ends in <Countdown to={earlyBird} layout="inline" aria-label="Early-bird pricing ends in" />.
</Text>
<Banner tone="primary" variant="solid" title="Black Friday">
Everything is 40% off for{" "}
<Countdown to={sale} layout="inline" units={["hours", "minutes", "seconds"]} aria-label="Black Friday sale time left" />.
</Banner>
</Stack>
);
}
Units
units picks what to show. The largest unit takes everything above it, so 2 days show as 50 hours here, and the time rounds up to the smallest unit.
import { useState } from "react";
import { Countdown, Stack } from "@vjdesigns/vjdesigns-ui";
const SECOND = 1000;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const DAY = 24 * HOUR;
export function Units() {
const [to] = useState(() => Date.now() + 50 * HOUR + 30 * MINUTE);
return (
<Stack gap={4}>
<Countdown to={to} units={["hours", "minutes"]} />
<Countdown to={to} units={["days"]} tone="primary" />
</Stack>
);
}
Reaches zero
At zero, onComplete runs once, completedContent replaces the timer, and screen readers hear completedLabel. Without completedContent, the timer stays on screen at zero.
onComplete has run 0 times.
import { useState } from "react";
import {
Button,
Countdown,
Heading,
Stack,
Text,
} from "@vjdesigns/vjdesigns-ui";
const SECOND = 1000;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const DAY = 24 * HOUR;
export function ReachesZero() {
const [to, setTo] = useState(() => Date.now() + 5 * SECOND);
const [ended, setEnded] = useState(0);
return (
<Stack gap={4}>
<Countdown
to={to}
units={["minutes", "seconds"]}
tone="accent"
completedContent={<Heading level={3}>Doors are open</Heading>}
completedLabel="Doors are open"
onComplete={() => setEnded((n) => n + 1)}
/>
<Text size="sm" tone="muted">
onComplete has run {ended} {ended === 1 ? "time" : "times"}.
</Text>
<div>
<Button variant="outline" onClick={() => setTo(Date.now() + 5 * SECOND)}>
Restart
</Button>
</div>
</Stack>
);
}
Already ended
An end time that has already passed shows completedContent right away.
This sale has ended.
import { Countdown, Text } from "@vjdesigns/vjdesigns-ui";
export function AlreadyEnded() {
return <Countdown to="2020-01-01T00:00:00Z" completedContent={<Text tone="muted">This sale has ended.</Text>} />;
}
Alignment
The tiles fill their container's width and align places them in it (start and end flip in right-to-left). In a narrow container they wrap to two columns.
import { useState } from "react";
import { Countdown, Stack } from "@vjdesigns/vjdesigns-ui";
const SECOND = 1000;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const DAY = 24 * HOUR;
export function Alignment() {
const [to] = useState(() => Date.now() + DAY + 2 * HOUR);
return (
<Stack gap={4}>
<Countdown to={to} align="start" size="sm" tone="primary" />
<Countdown to={to} align="center" size="sm" tone="primary" />
<Countdown to={to} align="end" size="sm" tone="primary" />
</Stack>
);
}
Localized
Unit names, numbers and list wording follow the locale, and the tiles mirror in right-to-left languages.
import { useState } from "react";
import { Countdown, LocaleProvider, Stack } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
import de from "@vjdesigns/vjdesigns-ui/locales/de";
const SECOND = 1000;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const DAY = 24 * HOUR;
export function Localized() {
const [to] = useState(() => Date.now() + 2 * DAY + 4 * HOUR + 30 * MINUTE);
return (
<Stack gap={4}>
<LocaleProvider locale="de" messages={de}>
<Countdown to={to} tone="primary" />
</LocaleProvider>
<LocaleProvider locale="ar" messages={ar}>
<Countdown to={to} tone="primary" />
</LocaleProvider>
</Stack>
);
}
Accessibility
Name the timer with aria-label, or with aria-labelledby pointing at a visible heading as here. Screen readers read the whole time as one phrase ("1 day, 5 hours, 12 minutes") without being interrupted every second.
30% off all team kits ends in
import { useState } from "react";
import {
Badge,
Button,
Card,
Countdown,
Heading,
Stack,
} from "@vjdesigns/vjdesigns-ui";
const SECOND = 1000;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const DAY = 24 * HOUR;
export function Accessibility() {
const [to] = useState(() => Date.now() + DAY + 5 * HOUR + 12 * MINUTE);
return (
<Card style={{ maxInlineSize: "26rem" }}>
<Card.Body>
<Stack gap={4}>
<div>
<Badge tone="accent">Flash sale</Badge>
</div>
<Heading level={3} id="countdown-sale-heading">
30% off all team kits ends in
</Heading>
<Countdown to={to} aria-labelledby="countdown-sale-heading" tone="primary" />
</Stack>
</Card.Body>
<Card.Footer>
<Button>Shop the sale</Button>
</Card.Footer>
</Card>
);
}
Usage notes
Semantics: role="timer", named by aria-label (default "Time remaining") or aria-labelledby. Screen readers read the whole time as one phrase ("4 hours, 12 minutes, 9 seconds") when they reach it, without being interrupted every second; reaching zero is announced once. Numbers and unit names are formatted for the current locale. Rendered on the server, the digits show as "--" until hydration, so the markup always matches.
API reference
Countdown
New in 3.2.0| Prop | Type | Default |
|---|---|---|
toRequiredWhen the countdown ends: an ISO 8601 date-time, or milliseconds since the epoch. Include the offset ( | string | number | — |
unitsUnits to show, largest first whatever the order given. The largest takes everything above it ( | CountdownUnit[] | ["days", "hours", "minutes", "seconds"] |
layoutTiles (a box per unit) or one line of text. | "tiles""inline" | "tiles" |
alignWhere the tiles sit. The | "start""center""end" | "start" |
variantTile style, for the | "solid""soft""outline""plain" | "solid" |
toneTile color, for the | "neutral""primary""accent""success""warning""danger""info" | "neutral" |
sizeType and tile size. | "sm""md""lg" | "md" |
completedContentShown in place of the timer once it reaches zero, e.g. "This sale has ended". Without it, the timer stays on screen at zero. | ReactNode | — |
completedLabelAnnounced to screen readers when the countdown reaches zero while on screen. Match it to | string | "Time's up" |
onCompleteCalled once when the countdown reaches zero, including when | () => void | — |
aria-labelThe timer's accessible name, e.g. | string | "Time remaining" |
Also accepts native <div> attributes, plus className, style and ref.
See what changed in each version in the Changelog.
Accessibility report
Countdown targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Dark mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
Not focusable, so there's no keyboard interaction of its own.
Not focusable. The digits update every second (every minute without seconds) but are hidden from screen readers; hidden text gives the whole time as one phrase that's read when the user reaches it, never interrupting them. Before hydration the digits show "--".
Roles and states
| Element | Role | States and properties |
|---|---|---|
| Timer | timer | aria-label ("Time remaining"), or your aria-label / aria-labelledby |
| Tiles / inline text | none | aria-hidden="true" |
| Spoken time | none | Visually hidden text in locale wording ("2 days, 4 hours, 30 minutes") |
| Reaching zero | status | Shared aria-live="polite" region announces completedLabel ("Time's up") once, only if the user saw it running |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |