Skip to content

Countdown

A component that displays a countdown timer with days, hours, minutes, and seconds. The countdown can be set to a specific date or a duration in days, hours, minutes, and seconds.

See the Example by Serhii Pimenov on CodePen.

<div data-role="countdown"></div>
<div data-role="countdown" data-animate="slide"></div>
<div data-role="countdown" data-font-size="96"></div>
<div data-role="countdown" data-date="2025/05/15"></div>
<div data-role="countdown" data-days="2" data-hours="12" data-minutes="30" data-seconds="15"></div>
ParameterTypeDefaultDescription
countdownDeferrednumber0Deferred start of countdown in milliseconds
stopOnBlurbooleantrueStop countdown when window loses focus
animatestring”none”Animation type: “none”, “slide”, “fade”, “zoom”
easestring”linear”Animation easing function
durationnumber600Animation duration in milliseconds
inputFormatstringnullFormat for parsing the date string
daysnumber0Number of days for countdown
hoursnumber0Number of hours for countdown
minutesnumber0Number of minutes for countdown
secondsnumber0Number of seconds for countdown
datestringnullTarget date for countdown (e.g., “2025/05/15”)
startbooleantrueStart countdown automatically
fontSizenumber24Font size in pixels
clsCountdownstring""Additional CSS class for countdown element
clsPartstring""Additional CSS class for part elements
clsZerostring""Additional CSS class for zero value
clsAlarmstring""Additional CSS class for alarm state
clsDaysstring""Additional CSS class for days part
clsHoursstring""Additional CSS class for hours part
clsMinutesstring""Additional CSS class for minutes part
clsSecondsstring""Additional CSS class for seconds part
onAlarmfunctionMetro.noopCallback function when countdown reaches zero
onTickfunctionMetro.noopCallback function on each tick
onZerofunctionMetro.noopCallback function when a part reaches zero
onBlinkfunctionMetro.noopCallback function on blink
onCountdownCreatefunctionMetro.noopCallback function when countdown is created
  • start() - Start the countdown.
  • stop() - Stop the countdown and reset values to zero.
  • pause() - Pause the countdown.
  • resume() - Resume the countdown after pause.
  • reset() - Reset the countdown with the same parameters.
  • resetWith(val) - Reset the countdown with new parameters. val can be a date string or an object with days, hours, minutes, seconds.
  • togglePlay() - Toggle between play and pause states.
  • isPaused() - Check if the countdown is paused.
  • getBreakpoint(asDate) - Get the target time. If asDate is true, returns a Date object.
  • getLeft() - Get the remaining time in days, hours, minutes, and seconds.
  • blink() - Trigger the blink effect.
  • tick() - Manually trigger a tick.
const countdown = Metro.getPlugin('#myCountdown', 'countdown');
// Reset with a specific date
countdown.resetWith("2025/05/15");
// Reset with duration
countdown.resetWith({
days: 2,
hours: 12,
minutes: 30,
seconds: 15
});
// Pause the countdown
countdown.pause();
// Resume the countdown
countdown.resume();
EventDescription
onAlarmTriggered when countdown reaches zero
onTickTriggered on each tick (every second)
onZeroTriggered when a part (days, hours, minutes, seconds) reaches zero
onBlinkTriggered on blink effect
onCountdownCreateTriggered when countdown is created
VariableDescription
--border-colorColor for borders and dividers between parts
#myCountdown {
--border-color: #ff5722;
font-size: 48px;
}
  • .countdown - Main container class
  • .part - Container for each part of the countdown
  • .digit - Container for each digit
  • .digit-placeholder - Placeholder for the digit
  • .digit-value - Actual value of the digit
  • .days - Class for days part
  • .hours - Class for hours part
  • .minutes - Class for minutes part
  • .seconds - Class for seconds part
  • .blink - Class for blinking effect
  • .animate-slide - Class for slide animation
  • .animate-fade - Class for fade animation
  • .animate-zoom - Class for zoom animation
  • .no-divider - Removes the divider before a part
  • .d-none - Hides a part