UtilitiesPremium

Flash Sale Countdown

Flash sale countdown: six digits that flip every second and a bar that empties, for a duration given in hours and minutes in the HTML.

Vanilla JSCountdownUrgency

Updated

This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Utilities has 43 effects, including 3 free. Explore the category →

3 usage examples

Sticky strip — flash sale alert during browsing — Flash Sale Countdown example 1

① Sticky strip — flash sale alert during browsing

WhenA banner fixed at the bottom of the page (position: sticky; bottom: 0) shown on all pages of a shop during a flash event. It signals that the promotion ends soon without interrupting navigation; the user keeps scrolling the catalogue.
WhySet as a strip, the countdown becomes a quiet reminder: always visible, never blocking, it lets the visitor browse the catalogue. Cut down to one line, it keeps only the essentials: the title, the six cells and the button.
Settingsdata-hours="0" data-minutes="47". Banner turned into a row (display: flex) across the full width, cells reduced to 24 × 32 px, .fsc-lbl labels and .fsc-bar bar hidden, button without background.
Full-screen hero — launch prices of a collection, limited in time — Flash Sale Countdown example 2

② Full-screen hero — launch prices of a collection, limited in time

WhenThe hero section of a product or collection launch page: the countdown occupies the centre, flanked by the brand name, a headline and a product visual. The scene replaces a standard text description with an interface that creates urgency from the first scroll.
WhyUsed as the main element of a hero, the countdown transforms the page's first impression. It signals immediately that the offer is time-limited and prompts the visitor to act before exploring the rest of the site.
Settingsdata-hours="3" data-minutes="0". Banner widened to 420 px, .fsc-scene background removed, lightning bolt replaced by ✨ in .fsc-zap, title and sub-label rewritten for the launch.
Cart — urgency widget on the checkout page — Flash Sale Countdown example 3

③ Cart — urgency widget on the checkout page

WhenAn inset placed just above the "Complete order" button on a cart or checkout page. The countdown signals that the reduced price is only guaranteed for a short window; once it expires, the regular price applies.
WhyPlacing the countdown at the decision point — inside the cart — is the highest-leverage position. The urgency is genuine (price valid until the stated time) and the visitor is already in purchase intent.
Settingsdata-hours="0" data-minutes="15". Banner at 100% of its column, cells reduced to 32 × 44 px, shorter title and sub-label (“Price locked”, “until the counter reaches zero”), button relabelled “Complete order”.

How it works

The .fsc-banner carries the duration in two attributes, data-hours and data-minutes. On load, the script converts it to milliseconds and works out the end time from the visitor's clock. A one-second setInterval then recomputes what is left: the countdown does not drift if the tab is throttled, since it reads the time again on each pass instead of subtracting a second.

Each unit sits in two .fsc-digit cells. A cell is only touched if its digit changes: the script removes the fsc-flip class, forces a reflow (offsetWidth) and puts it back, which restarts the 0.4 s CSS animation (the cell swings in from −88° on its horizontal axis). On an ordinary second only the last cell flips; when a minute rolls over, three do.

The .fsc-bar-fill bar gets the share of time left as its width, from 100% to 0%, smoothed by a one-second transition. The same pass rewrites the clock's aria-label in full words, singular and plural included (“1 hour”, “2 hours”).

At zero, the interval is stopped, the digits stay on 00:00:00 and the banner fires the fsc-end event once, which bubbles up to the document: that is where your page decides what comes next (hide the offer, change the button). Each [data-fsc] banner has its own end time.

Accessibility

  • What a screen reader reads: the clock has role="timer" and an aria-label rewritten every second (“2 hours 44 minutes 59 seconds remaining”). A timer is not announced by itself at each change: the person hears the time left when reaching the clock, not a continuous stream.
  • Reduced motion: with prefers-reduced-motion: reduce, a CSS rule cuts the pulsing of the lightning bolt and the flipping of the cells, including the one on load, and the bar moves in one-second steps instead of sliding. The digits keep changing: the information stays, the motion goes.
  • Keyboard and touch: the only actionable element is the .fsc-cta button, a real <button> reached with Tab. It does nothing by itself: wire your action to it, or replace it with an <a href> link if it leads to a page.
  • Contrast: white digits on very dark cells (#26161a to #160d10), about 17:1, far above the 4.5:1 that WCAG AA asks for text (3:1 for text of this size). The HOURS / MIN / SEC labels, grey #71717a at 10 px, are below 4.5:1: lighten them if those words matter to your visitors.
  • End of the count: at zero, the aria-label stays on “0 hours 0 minutes 0 seconds remaining” and nothing else is announced. Listen for fsc-end to write a clear message (“Offer ended”) in a role="status" area of your page.

Browser compatibility

The script relies on String.padStart and NodeList.forEach: Chrome 57, Firefox 50, Safari 10. Below that, it stops on an error. The full layout needs something newer, because of gap in the flex rows (Chrome 84, Firefox 63, Safari 14.1): without it the cells touch. The reduced-motion rule is read from Chrome 74, Firefox 63 and Safari 10.1. Versions read from @mdn/browser-compat-data.

Chrome 57+✓ Full from version 84 (measured on Chromium 149); from 57 to 83, cells stuck together
Firefox 50+✓ Full from version 63 (measured on Firefox 151)
Safari 10+✓ Full from 14.1 in the WebKit 26.5 test build; real Safari not verified
Edge 79+✓ Not verified (same engine as Chrome)
iOS 10+✓ Not verified on a real phone; full layout expected from iOS 14.5
Android Chrome 57+✓ Not verified on a real phone

Without JavaScript, the banner shows the digits written in the HTML (02:45:00 in the demo), still, with the bar full: write values there that stay true. Below 440 px wide, the banner shrinks with its container; below about 370 px, the six cells stick out of its frame.

The code

HTML structure to paste into your page (the CSS + JS come with your purchase):

index.html — structure
<div class="fx-0811-root">
  <div class="fsc-scene">
    <div class="fsc-banner" data-fsc="" data-hours="2" data-minutes="45">
      <div class="fsc-title">
        <span class="fsc-zap">⚡</span> …
      </div>
      <div class="fsc-sub">…</div>
      <div class="fsc-clock" data-fsc-clock="" role="timer" aria-label="…">
        <div class="fsc-group" data-fsc-h="">
          <span class="fsc-digit">0</span>
          <span class="fsc-digit fsc-flip">2</span>
        </div>
        <span class="fsc-sep">:</span>
        <div class="fsc-group" data-fsc-m="">
          <span class="fsc-digit fsc-flip">4</span>
          <span class="fsc-digit fsc-flip">5</span>
        </div>
        <span class="fsc-sep">:</span>
        <div class="fsc-group" data-fsc-s="">
          <span class="fsc-digit">0</span>
          <span class="fsc-digit">0</span>
        </div>
      </div>
      <div class="fsc-lbl">
        <span>HEURES</span>
        <span>MIN</span>
        <span>SEC</span>
      </div>
      <div class="fsc-bar">
        <div class="fsc-bar-fill" data-fsc-bar="" style="width: 100%;"></div>
      </div>
      <button type="button" class="fsc-cta">…</button>
    </div>
  </div>
</div>

One-time payment, no subscription — the code is yours forever

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
Duration — data-hours and data-minutes attributes on [data-fsc] 2 hours 45 minutes Any combination of hours and minutes: data-hours="0" data-minutes="30" for half an hour. There is no attribute for seconds. The duration starts over on every page load: see the first question below for a real deadline.
Title text — content of .fsc-title in the HTML ⚡ Black Friday Flash Sale The title is free HTML; replace the emoji, text and event name directly in the HTML. The .fsc-zap emoji is the one that pulses — removing it also removes the animation.
Button text — content of .fsc-cta Shop now The CTA label is in the HTML. Replace with an <a href="…"> link element if the target is a navigable URL.
Banner colours — CSS on .fsc-banner and .fsc-bar-fill Dark red gradient + orange-to-red bar Edit border-color of .fsc-banner (default rgba red 0.3) and the background of .fsc-bar-fill (gradient #f59e0b → #ef4444) to match the brand palette. The .fsc-sep separators use #ef4444.
Banner width — CSS on .fsc-banner 380 px, max-width 100% Set width: 100% for a full-width strip, or width: 320px for a compact inset in a column. The inner layout adapts automatically.
Sub-label text — content of .fsc-sub Ends in Change the introductory phrase above the clock. E.g. "until" or "Offer valid for".
End of the count — fsc-end event Fired once, on [data-fsc] document.addEventListener('fsc-end', function (e) { … }): e.target is the banner that reached zero. Set the listener before the effect's script: with a duration of 0, the event fires on load.

FAQ

As it stands, it measures a duration from page load: each visitor, and each reload, starts again from data-hours and data-minutes. For a real deadline, have your server write the end time into an attribute, for example data-end="<timestamp in milliseconds>", and in the script replace n = Date.now() + c with n = parseInt(t.dataset.end, 10). Leave the total length of the sale in data-hours and data-minutes: the bar uses it to know how far along it is. A countdown that restarts for everyone while the offer never ends is fake urgency, to be avoided.
The digits stop on 00:00:00, the bar is empty, and the banner fires the fsc-end event. The component hides nothing and does not disable the button: listen for the event to do so, for example document.addEventListener('fsc-end', function (e) { e.target.querySelector('.fsc-cta').disabled = true; }).
Yes. The script goes through every [data-fsc] and gives each its own end time and its own interval. Two banners of 15 minutes and 3 hours run side by side without interfering, and each fires its fsc-end when the time comes. Nothing is added to window.