Skip to content

Countdown

High-performance countdown component supporting target time/duration modes, pause/resume, warning state, flip animation, server time calibration, and more. Uses requestAnimationFrame for precise timing.

Basic Usage

Set value to a target timestamp or Date object. The component automatically calculates remaining time and counts down.

01:59:59
Basic Usage

Duration Mode

When passing milliseconds (less than 978307200000, i.e., 2001-01-01), it is treated as duration mode.

01:00
05 min 00 sec
Duration Mode

Custom Format & Text

Customize the display format via the format prop. Supports DD, HH, mm, ss, SSS placeholders. Also supports title and suffix.

01 days 01:01:01
01:01.500
Remaining:
01:00:00
(estimated)
Custom Format

Flip Animation

Set flip-animation to enable flip-card style. Combine with labels to add labels for each time unit.

01
h
:
01
m
:
01
s
Flip Animation

Control Countdown

Get the component instance via ref to manually control the countdown lifecycle.

00:01:00
Control Countdown

Warning State

Set a warning threshold via warning-threshold. When the countdown enters this range, is-warning class is added for style customization.

00:00:15
Warning State

Fully Custom

Use the default slot to fully take over rendering. The slot scope exposes the complete current format object and state flags.

01:00:00
Fully Custom

Scenario: Flash Sale

Combines flip animation, labels, and warning state to create an urgent e-commerce countdown.

Flash Sale
00
h
:
59
m
:
59
s
Flash Sale

Server Time Calibration

Handles client clock deviations caused by manual adjustments or system delays.

01:00:00
Server Time Calibration

Real-World: Dialog Sync

In complex SPA applications, the same timer task may appear in multiple places (e.g., product detail page and purchase popup). The component ensures through internal time alignment that the time display stays absolutely consistent when dialogs are frequently opened/closed.

Page countdown:
00:09:59
Dialog Sync

Real-World: Flash Sale List

High-performance requestAnimationFrame driven — even in waterfall lists and high-frequency refresh scenarios, it maintains extremely low CPU usage and smooth UI interactions, with each timer running independently.

Smart Watch Pro$199
Ends in
00:59:59
ANC Headphones Max$289
Ends in
01:59:59
Mechanical Keyboard G9$89
Ends in
00:29:59
Flash Sale List

Use in Nuxt

The Countdown component fully supports SSR rendering in Nuxt 3/4. Components are auto-imported in Nuxt projects.

01:59:59
Use in Nuxt

SSR Notes:

  • ✅ Component initial rendering fully supports SSR
  • ✅ Time calculation and formatting completed on server
  • ✅ Excellent Hydration performance with no first-load jitter
  • ✅ Auto-detects client mount and starts timing
  • 💡 Recommended to use with server-time-offset for absolute cross-device time consistency

SSR Performance

Countdown uses requestAnimationFrame internally for timing, which only executes on the client and consumes zero server resources. During initial render, remaining values are pre-calculated based on the current server time, ensuring consistent full-pipeline experience.

API

Props

PropDescriptionTypeDefault
valueTarget time (Date/timestamp) or duration (ms)Date | number
formatFormat template or functionstring | (ctx) => string'HH:mm:ss'
auto-startWhether to auto-startbooleantrue
intervalRefresh interval (ms)number1000
precisionTiming precision (ms)1000 | 100 | 101000
titleTitle/prefix textstring
suffixSuffix textstring
use-monospace-fontUse monospace font to prevent digit jumpingbooleantrue
flip-animationEnable flip animation modebooleanfalse
value-styleCountdown digit inline styleCSSProperties | string
separatorSeparator between time unitsstring':'
show-daysShow days ('auto' shows when >= 24h)boolean | 'auto''auto'
show-hoursWhether to show hoursbooleantrue
show-minutesWhether to show minutesbooleantrue
show-secondsWhether to show secondsbooleantrue
show-millisecondsWhether to show millisecondsbooleanfalse
labelsLabel template for time unitsobject
keep-alive-on-finishWhether to keep at 00:00:00 when finishedbooleantrue
warning-thresholdWarning threshold (ms)number
timezone-offsetTimezone offset (minutes) for multi-device calibrationnumber
server-time-offsetServer-local time difference (ms)number0

Events

Event NameDescriptionParameters
changeTriggered on countdown update(ctx: CountdownFormatContext) => void
finishTriggered when countdown ends() => void
startTriggered when countdown starts() => void
pauseTriggered on pause() => void
resumeTriggered on resume() => void
resetTriggered on reset() => void
warningTriggered when entering warning range(ctx: CountdownFormatContext) => void
status-changeTriggered on status change(status: CountdownStatus) => void

Slots

Slot NameDescriptionParameters
defaultFully custom rendering{ current, remaining, formatted, status, isWarning, isFinished }
prefixPrefix placeholder
suffixSuffix placeholder
valueCustom digit display{ text: string }
separatorCustom unit separator
[key]-cellCustom specific cell (e.g., seconds-cell){ value: string }

Methods (via ref)

MethodDescriptionParametersReturn
startStart timingvoid
pausePause timingvoid
resumeResume timingvoid
resetReset timingvoid
getRemainGet current remaining msnumber
getStatusGet current timing statusCountdownStatus

Type Definitions

typescript
type CountdownStatus = 'pending' | 'running' | 'paused' | 'finished'

interface CountdownFormatContext {
  total: number // Total remaining ms
  days: number
  hours: number
  minutes: number
  seconds: number
  milliseconds: number
  DD: string // Two-digit days
  HH: string
  mm: string
  ss: string
  SSS: string
  SS: string // First two digits of ms
  S: string // First digit of ms
}

Theme Variables

The Countdown component supports customizing styles by overriding the following CSS variables. All color variables integrate with the global theme system, automatically supporting dark mode:

VariableDescriptionDefault
--yh-countdown-font-sizeDigit font size24px
--yh-countdown-value-colorDigit colorvar(--yh-text-color-primary)
--yh-countdown-label-colorLabel colorvar(--yh-text-color-secondary)
--yh-countdown-separator-colorSeparator colorvar(--yh-text-color-placeholder)
--yh-countdown-warning-colorWarning state colorvar(--yh-color-danger)
--yh-countdown-finished-colorFinished state colorvar(--yh-color-success)
--yh-countdown-bgComponent root backgroundtransparent
--yh-countdown-block-bgFlip block backgroundvar(--yh-fill-color-light)
--yh-countdown-block-shadowFlip block shadowvar(--yh-shadow-sm)
--yh-countdown-block-radiusFlip block border radiusvar(--yh-radius-md)
--yh-countdown-block-paddingFlip block padding12px 16px
--yh-countdown-gapInternal element gap8px
--yh-countdown-font-familyDefault font familyvar(--yh-font-family)
--yh-countdown-monospace-fontMonospace font (anti-jitter)JetBrains Mono, SF Mono...

Released under the MIT License.