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.
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



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 anaria-labelrewritten every second (“2 hours 44 minutes 59 seconds remaining”). Atimeris 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-ctabutton, 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 (
#26161ato#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#71717aat 10 px, are below 4.5:1: lighten them if those words matter to your visitors. - End of the count: at zero, the
aria-labelstays on “0 hours 0 minutes 0 seconds remaining” and nothing else is announced. Listen forfsc-endto write a clear message (“Offer ended”) in arole="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.
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):
<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 / property | Default | Effect |
|---|---|---|
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
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.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; }).[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.