Countdown
<x-wirekit:: shows the time remaining until an absolute deadline,
ticking down every second on the client — no wire:poll, no server round-trips.
It colors itself when the deadline is close (urgent) and again once it has passed
(overdue), so a running deadline reads at a glance instead of forcing the reader
to subtract a timestamp from the current time in their head.
Pass an absolute instant (a Carbon, an ISO-8601 string, or a unix timestamp) — never a duration. A duration drifts the moment the tab sleeps or the page is cached; an absolute instant is recomputed from the real clock on every tick.
Usage
The largest meaningful unit leads and shrinks down to the smallest — years
appear only once the remaining time reaches a year, so a far-off deadline reads
in years and days instead of tens of thousands of days. A year counts as 365
days, so a deadline years away shows one day more for each leap day in between;
leave years out of units when the count has to match the
calendar:
Urgent threshold
Set warn-threshold (in seconds) to switch the countdown to its urgent color
before the deadline slips. In an application the threshold is the last stretch
before the deadline, the final hour here:
<x-wirekit::countdown :until="$order->payment_due_at" :warn-threshold="3600" />
The preview counts down to a deadline decades away, so its threshold is set wider than the time left, and the countdown stands in its urgent color:
Overdue
Once the deadline has passed, the countdown shows its overdue text in the danger
color. Provide your own copy with expired-text:
Without seconds
For a long deadline, drop the churning seconds with :show-seconds="false". The
other units stay as auto picks them, down to the minutes:
Choose your units
Pass an explicit ordered subset to units — any combination of years, days,
hours, minutes, seconds. The largest unit you list carries all the overflow
above it (so units="hours minutes" shows the total hours), and the smallest
truncates. Large values get locale-aware thousands separators (like
price); pass locale to override, or :separators="false"
to turn them off:
Segments variant
variant="segments" renders each unit as its own boxed block with a label — the
classic dashboard countdown look. When a value changes, it animates (the default
box pulse — see Change animation for the styles):
Change animation
The segments variant animates each unit as its value changes, in one of two
styles set with animate. It plays for the first seconds after the countdown
appears, most visibly on the seconds box, and then stops while the value keeps
ticking, so the countdown never blinks for longer than the five seconds
WCAG 2.2.2
allows without a control to stop it. Both styles honor prefers-reduced-motion
(an instant, motionless update for users who ask for less motion).
animate="box" (the default) pulses the whole box — border and background
flash the accent color with a small scale pop:
animate="text" flashes only the changing number's color (to the text tone of
your theme's accent, which stays readable on the page) — the box stays still. It is
the understated alternative to the box pulse; it reads strongest on a theme with a
colored accent:
Turn motion off entirely with :animate="false":
Stopping the clock
A countdown updates itself. Where it stands beside other content and its ticking is not essential to the task, the end of a sale under a price for one, WCAG 2.2.2 asks for a way to stop it, and two props give one.
pausable puts a button after the time that stops the clock where it stands and starts it
again from the time it is now. Its name says what a press does, "Pause countdown" or "Resume
countdown", and the keyboard reaches it as it reaches any button:
static works the remaining time out once, on the reader's clock as the page loads, and leaves
it standing. It suits a page served from a cache, which cannot work the time out on the server:
Either way the countdown turns to its expired text at the deadline, once, and fires
wirekit-countdown-expired. The button of pausable goes with the clock, as past the deadline
there is nothing left to stop. When the button has the focus at that moment, the focus moves on
to the next control after the countdown, or to the last one before it, so the next Tab goes on
from where the reader was. A headless countdown
that draws its own control reads paused and calls togglePause(), which leaves paused as it
is past the deadline: there is no clock left to stop or start.
Before the script runs
The server writes the countdown as it stands when the page is made: the units, the color of an urgent or passed deadline, the expired text past it, and the sentence a screen reader reads. A page that loads no script, or a reader who has turned scripts off, sees the time left at that moment, and the script takes over on the reader's clock when it starts. A deadline a page has to name stays on the page either way.
A page served from a cache shows the time left when the copy was made, until the script starts. A headless countdown shows what its own markup writes on the server.
Livewire
The countdown ticks entirely on the client, so it never triggers a Livewire round-trip. Bind the deadline itself as a normal prop:
<x-wirekit::countdown :until="$order->payment_due_at" :warn-threshold="600" />
Completion events. The countdown is more than display — it notifies when the deadline passes, so a sibling control can react (re-enable a button, refetch, show a retry form):
wirekit-countdown-expired— a bubbling event dispatched once the moment the deadline is reached (or immediately for an already-past deadline).x-modelable="done"— a writable boolean that flips totrueat expiry, so you can observe completion withx-model.
{{-- Re-enable "Resend code" only after the retry window elapses --}}
<div x-data="{ ready: false }">
<x-wirekit::countdown :until="now()->addSeconds($retryAfter)" x-model="ready" />
<x-wirekit::button x-bind:disabled="!ready" wire:click="resend">Resend code</x-wirekit::button>
</div>
The retry-timer pattern pairs naturally with a rate limiter — feed it
RateLimiter:: via :until="now()->add.
Headless: your own copy around the number
Sometimes you want the countdown's clock — the client tick, the deadline recompute on wake, the completion event — but your own wording around the number ("Resend available in 45 seconds", with your locale's pluralization). Pass a slot and the countdown becomes headless: it renders your markup instead of the default units, and your Alpine expressions resolve against its live state.
<x-wirekit::countdown :until="now()->addSeconds($retryAfter)">
{{-- `remaining` is the full breakdown plus totals; `expired` / `urgent` /
`done` are the same states the default display uses. --}}
<span x-show="!expired">Resend available in <span x-text="remaining.totalSeconds"></span> seconds</span>
<span x-show="expired">You can resend now.</span>
</x-wirekit::countdown>
The example writes its words in the markup and binds only the number. That form also works under a
Content-Security-Policy build, WireKit's CSP bundle or Livewire's csp_safe
(Content Security Policy): its parser
reads no template literal, and the countdown's own scope needs no factory of yours.
The reactive state available inside the slot:
| Expression | What it gives you |
|---|---|
remaining |
{ years, days, hours, minutes, seconds, totalSeconds, totalMs } — the complete canonical ladder plus totals, independent of the units / variant props. |
expired |
true once the deadline has passed. |
urgent |
true inside the warn-threshold window. |
done |
The writable completion boolean (also x-modelable). |
paused |
true while the reader has stopped the clock. |
togglePause() |
Stops the clock where it stands, or starts it again from the time it is now. Bind it to a control of your own. |
In headless mode you own the accessible text too — the default screen-reader
<time> is not rendered, so add your own (for example a one-time role="status"
announcement at zero) to match your app's pattern.
The countdown roots in a <span>, so it can stand in a sentence, with or without a
slot: a <div> inside a paragraph would end the paragraph. A slot that holds block
content, such as a card or a list, takes as="div".
Props
| Prop | Type | Default | Description |
|---|---|---|---|
until |
DateTimeInterface|string|int |
null |
The absolute target instant: a date object of any class (Carbon, CarbonImmutable, DateTime), an ISO-8601 string or a Unix timestamp. A date object counts to the instant it holds in its own zone, so a model attribute counts the same whether your application keeps the default dates or has called Date::use(CarbonImmutable::class). A null value renders as immediately overdue. |
expiredText |
string|null |
null |
Text shown once the deadline has passed. Defaults to a translatable "Overdue". |
warnThreshold |
int|null |
null |
Seconds-remaining threshold below which the countdown turns urgent (warning color). Omit for no urgent state. |
units |
string |
'auto' |
'auto' shows years→seconds and drops leading zero-units, or an explicit ordered subset like "days hours minutes". The largest listed unit carries the overflow. A year counts as 365 days. |
showSeconds |
bool |
true |
Include seconds in 'auto' mode (ignored when units is an explicit list). |
variant |
string |
'inline' |
'inline' (e.g. 73y 190d 12h) or 'segments' (boxed blocks with labels). |
separators |
bool |
true |
Locale-aware thousands separators on large unit values. |
locale |
string|null |
null |
BCP-47 locale for the separators. Defaults to the app locale. |
timezone |
string|DateTimeZone|null |
null |
The zone the deadline is written in for the reader, such as Europe/Berlin: the deadline in the accessible name and the machine-readable time. Defaults to the zone of the value; a Unix timestamp, like a string without a zone, is in the application's zone. The countdown counts to the same instant either way. |
animate |
bool|string |
true |
Change animation. For segments: "box" (default — the whole box pulses with a border + accent flash + scale pop) or "text" (only the changing number flashes color). false / "none" turns it off. It plays for the first seconds after the countdown appears, then stops. The inline variant changes its value without animation. Honors prefers-reduced-motion. |
pausable |
bool |
false |
A button after the time that stops the clock and starts it again, for WCAG 2.2.2. Ignored with static. |
static |
bool |
false |
Works the remaining time out once, as the page loads, and leaves it standing. It still turns to its expired text at the deadline. |
as |
string |
'span' |
The element the countdown roots in. Everything it renders is text-level, so the default span can stand in a sentence. Set as="div" for a headless slot that holds block content. |
scope |
string|null |
null |
Scoped personalization key. |
Accessibility
- The root carries
role="timer", which is a live region set to off — so the ticking value is not announced every second. - The accessible name is the absolute deadline (
aria-label), a stable value a screen reader reads on navigation. - A visually hidden
<time datetime>holds a coarse "time remaining" phrase in the active units (e.g. "2 days, 5 hours"), so assistive tech can read the current remaining time on demand without per-second spam. The server writes it as the page loads, so it is there before the script runs. - The visible ticking units are
aria-hidden— a decorative convenience over the semantic time. - The change animation of the
segmentsvariant stops a few seconds after the countdown appears. The value itself keeps updating: where the countdown stands beside other content and its ticking is not essential to the task, give the reader a way to stop it withpausableorstatic. A unit list withoutsecondsonly makes it change less often. - The button of
pausableis named for what a press does, "Pause countdown" or "Resume countdown", rather than carrying a pressed state that would say it twice.
Keyboard Interaction
Without pausable the countdown is purely presentational and takes no keyboard input.
| Key | Action |
|---|---|
| Tab | Move to the button of pausable. |
| Enter / Space | Stop the clock, or start it again. |
Design Tokens
| Element | Token |
|---|---|
| Time, running | --color-wk-text |
Time, inside warn-threshold |
--color-wk-warning-text |
| Expired text | --color-wk-danger-text |
| Font | --font-wk-sans, --text-wk-md |
| Segment box | --color-wk-bg-elevated, --color-wk-border, --border-wk-width, --radius-wk-md |
| Segment padding | --padding-wk-x-sm / --padding-wk-y-sm |
| Segment value | --text-wk-2xl, --font-wk-heading-weight |
| Segment label | --text-wk-xs, --color-wk-text-muted |
| Gap between units and segments | --space-wk-xs / --space-wk-sm |
Change animation, box |
--color-wk-accent |
Change animation, text |
--color-wk-accent-text |
| Pause button | --size-wk-target-min, --color-wk-bg-elevated, --color-wk-bg-hover, --color-wk-border |
| Pause button focus ring | --color-wk-ring, --ring-wk-width |