Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Data display

Countdown

Free11.8 KB gzipped

A 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

tsx
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.

tsx
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.

tsx
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.

tsx
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

tsx
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

Everything is 40% off for
.
tsx
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.

tsx
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.

tsx
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.

tsx
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.

tsx
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.

tsx
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.

Flash sale

30% off all team kits ends in

tsx
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
Countdown props
PropTypeDefault
toRequired

When the countdown ends: an ISO 8601 date-time, or milliseconds since the epoch. Include the offset ("2026-12-01T09:00:00-05:00" or a trailing Z) so everyone counts down to the same moment; a date-time without one is read in each viewer's own time zone.

string | number—
units

Units to show, largest first whatever the order given. The largest takes everything above it (["hours", "minutes"] shows 2 days as 48 hours), and the time is rounded up to the smallest, so the count reaches 0 exactly at to.

CountdownUnit[]["days", "hours", "minutes", "seconds"]
layout

Tiles (a box per unit) or one line of text.

"tiles""inline""tiles"
align

Where the tiles sit. The tiles layout fills its container's width (and wraps to two columns when that's too narrow for one row); inline ignores it.

"start""center""end""start"
variant

Tile style, for the tiles layout. inline takes the surrounding text color.

"solid""soft""outline""plain""solid"
tone

Tile color, for the solid, soft, and outline variants.

"neutral""primary""accent""success""warning""danger""info""neutral"
size

Type and tile size.

"sm""md""lg""md"
completedContent

Shown 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—
completedLabel

Announced to screen readers when the countdown reaches zero while on screen. Match it to completedContent when you set one.

string"Time's up"
onComplete

Called once when the countdown reaches zero, including when to has already passed when it first renders (after hydration). Called again only if to changes.

() => void—
aria-label

The timer's accessible name, e.g. "Sale ends in". Use it (or aria-labelledby pointing at a visible heading) to say what the time is for.

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)

Running accessibility audit

Checking the examples above…

Lighthouse audit

Light mode

Score 100

35 passed · 0 failed · 30 not applicable · 10 to check by hand

Dark mode

Score 100

35 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

Roles and states
ElementRoleStates and properties
Timertimeraria-label ("Time remaining"), or your aria-label / aria-labelledby
Tiles / inline textnonearia-hidden="true"
Spoken timenoneVisually hidden text in locale wording ("2 days, 4 hours, 30 minutes")
Reaching zerostatusShared 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.

Manual accessibility checks
CheckWhat to testWCAG 2.2
KeyboardEvery 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)
FocusFocus 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 readersNames, 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)
ColorMeaning 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 reflowAt 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 targetsClick 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)
MotionAnimations respect the reduced-motion setting.2.3.3 (AAA)