Countdown Timer

Launch countdown with days, hours, minutes, seconds.

12

Days

:

08

Hours

:

45

Mins

:

30

Secs

Tailwind CSS
<div class="flex items-center justify-center gap-2 sm:gap-3 flex-wrap">
  <div class="w-16 sm:w-20 py-3 sm:py-4 rounded-2xl bg-slate-900 text-center">
    <p class="text-2xl sm:text-3xl font-black text-white tabular-nums">12</p>
    <p class="text-[10px] font-bold text-slate-400 uppercase tracking-widest mt-1">Days</p>
  </div>
  <span class="text-2xl font-black text-slate-300">:</span>
  <div class="w-16 sm:w-20 py-3 sm:py-4 rounded-2xl bg-slate-900 text-center">
    <p class="text-2xl sm:text-3xl font-black text-white tabular-nums">08</p>
    <p class="text-[10px] font-bold text-slate-400 uppercase tracking-widest mt-1">Hours</p>
  </div>
  <span class="text-2xl font-black text-slate-300">:</span>
  <div class="w-16 sm:w-20 py-3 sm:py-4 rounded-2xl bg-slate-900 text-center">
    <p class="text-2xl sm:text-3xl font-black text-white tabular-nums">45</p>
    <p class="text-[10px] font-bold text-slate-400 uppercase tracking-widest mt-1">Mins</p>
  </div>
  <span class="text-2xl font-black text-slate-300">:</span>
  <div class="w-16 sm:w-20 py-3 sm:py-4 rounded-2xl bg-indigo-600 text-center">
    <p class="text-2xl sm:text-3xl font-black text-white tabular-nums">30</p>
    <p class="text-[10px] font-bold text-indigo-200 uppercase tracking-widest mt-1">Secs</p>
  </div>
</div>
<script>
(function() {
  var target = new Date(); target.setDate(target.getDate() + 12);
  function tick() {
    var diff = Math.max(0, target - new Date());
    var d = Math.floor(diff / 864e5), h = Math.floor(diff / 36e5) % 24,
        m = Math.floor(diff / 6e4) % 60, s = Math.floor(diff / 1e3) % 60;
    var cells = document.currentScript.parentElement.querySelectorAll('.tabular-nums');
    if (cells.length >= 4) {
      cells[0].textContent = String(d).padStart(2, '0');
      cells[1].textContent = String(h).padStart(2, '0');
      cells[2].textContent = String(m).padStart(2, '0');
      cells[3].textContent = String(s).padStart(2, '0');
    }
    if (diff > 0) setTimeout(tick, 1000);
  }
  tick();
})();
</script>

Free to use in personal and commercial projects. No attribution required.

Variants

Same component, different looks. Preview each one live and copy the code you like.

Light

Light cards suit bright landing pages better than the dark default.

12

Days

:

08

Hours

:

45

Mins

:

30

Secs

Tailwind CSS

Minimal

Go minimal when the countdown is secondary, like in a blog sidebar.

12

Days

:

08

Hours

:

45

Mins

:

30

Secs

Tailwind CSS

Outline

Outline cards add brand color without the weight of solid fills.

12

Days

:

08

Hours

:

45

Mins

:

30

Secs

Tailwind CSS

About this countdown timer

Countdown timers manufacture urgency: product launches, sale endings, event registrations. The dark tiles with tabular numerals are the standard launch-page pattern. The seconds tile in brand color draws the eye to the moving number, which is what creates the urgency.

This countdown timer includes working JavaScript that ticks every second toward a target date. The tabular-nums class keeps digits from jumping as they change (1 is narrower than 8 in most fonts; tabular fixes the width).

Honest countdowns only. A fake timer that resets on refresh destroys trust when visitors notice. Use countdowns for real deadlines: launches, sales, registrations. Never for permanent 'offers'.

Sale ends soon is abstract and ignorable; 02:14:33 ticking down is concrete and urgent. Countdowns manufacture urgency by making time visible, which is why product launches, drops, and registration deadlines all use them. The moving seconds tile is the psychological engine: motion implies scarcity, and scarcity drives action.

Four tiles (w-16 sm:w-20 rounded-2xl bg-slate-900) hold text-2xl font-black tabular-nums numerals with tiny uppercase labels beneath. Tabular-nums is the key detail: it fixes every digit to the same width so the layout doesn't jitter as numbers change. A setInterval every 1000ms diffs the target Date against now and writes days, hours, minutes, and seconds into the tiles.

Tint the seconds tile with your brand color so the eye lands on the moving number first. For urgency that never expires, like a cart reservation window, start the clock at page load rather than anchoring to a fixed date. Always show all four units; 2 days without the hours feels vague. And sync to a server timestamp rather than trusting the visitor's clock.

The honesty mistake is the fake timer that resets on every visit or page refresh. Visitors notice, the urgency converts into distrust, and the brand takes the hit. Only count down to real deadlines: launches, sales, registrations. A countdown for a permanent offer is a lie with a clock on it.

Frequently asked questions

How do I make a countdown timer?

Calculate the difference between now and a target Date, split into days/hours/minutes/seconds, update the DOM every second with setInterval or recursive setTimeout.

Why do my countdown numbers jump?

Proportional fonts give digits different widths. Use tabular-nums (font-variant-numeric) to fix digit widths so the layout stays stable.

Are fake countdown timers okay?

No. Timers that reset or never expire destroy trust when discovered. Only count down to real deadlines.

How do I handle timezones in a countdown timer?

Define the target with an explicit timezone, ideally an ISO string ending in Z for UTC like "2026-12-31T23:59:59Z". Never parse ambiguous local date strings, which shift per visitor. Compute the difference against Date.now(), which is timezone independent, and the countdown stays correct worldwide.

What should a countdown show when it reaches zero?

Clear the interval first so the timer stops ticking, then swap the display to a terminal state like "Live now" or "Offer ended" instead of showing negative numbers. If the event has a next occurrence, you can roll the target forward. Always handle the zero case explicitly.

How do I add flip animation to countdown digits?

Split each unit into its own digit element and animate only the digit that changed, using a quick rotateX or slide keyframe on update. Simpler and more reliable: crossfade the whole number with an opacity transition. Full flip-clock mechanics need careful 3D layering, so start simple.

Where to use it

  • ✓ Product launches
  • ✓ Sale countdowns
  • ✓ Event registrations
  • ✓ Coming soon pages

Design notes

When to use

A countdown timer creates honest urgency for events with a real deadline: product launches, sale endings, or registration cutoffs. The four separate blocks for days, hours, minutes, and seconds let users parse the remaining time at a glance instead of doing mental math. Tabular numerals keep the digits from jittering as they change, which matters when seconds are ticking visibly.

What to avoid

Do not fake a countdown that resets on every visit, users notice and the urgency turns into distrust. Avoid tiny labels under the numbers, if users cannot tell whether 12 means hours or days the timer has failed. And do not run a countdown past zero into negative numbers, switch it to a started state instead.

Accessibility

A timer that updates every second will flood screen readers, so mark the ticking region aria-hidden and provide a static text alternative with the deadline. Do not convey the deadline only through the visual timer.

Customization tips

Set the target date in the script. For evergreen timers (cart expiry), count down from page load instead. Style the seconds tile in your brand color.