
Sales timer
An animated announcement bar featuring a real-time countdown timer for hours, minutes, and seconds. It uses a dynamic CSS gradient background and automatically displays a 'Sale Ended' message once the target date is reached.
- Animated CSS gradient background
- Real-time JavaScript countdown engine
- Fully responsive mobile-optimized layout
- Zero-dependency vanilla JavaScript implementation
- Automatic expiration state handling
- Flash sales and holiday promotions
- Creating urgency for limited-time shipping offers
- New Year or seasonal event launches
- Promoting store-wide discount deadlines
- Most Shopify themes
- Shopify Online Store 2.0
The code
1<div class='announcement-section-1'>2 <div class='container'>3 <div class='announcement-wrapper'>4 <span class='clock-down_text'>New Year Sale Ends In</span>5 <div class='holiday-clock' id='js-clock'>6 <div class='box-3'>7 <div class='clock-number-2' id='js-clock-hours'>00</div>8 <div class='clock-label-2'>Hrs</div>9 </div>10 <div class='text-block-countdown'>:</div>11 <div class='box-3'>12 <div class='clock-number-2' id='js-clock-minutes'>00</div>13 <div class='clock-label-2'>Min</div>14 </div>15 <div class='text-block-countdown'>:</div>16 <div class='box-3'>17 <div class='clock-number-2' id='js-clock-seconds'>00</div>18 <div class='clock-label-2'>Sec</div>19 </div>20 </div>21 </div>22 </div>23</div>2425<style>26.announcement-section-1 {27 background: linear-gradient(45deg, #BDE6FF, #6A93AC, #174059);28 background-size: 400% 400%;29 animation: primaryGradient 5s ease infinite;30 color: #fff;31 text-align: center;32 padding: 10px 0;33}3435.announcement-wrapper {36 font-size: 16px;37 font-weight: 700;38 line-height: 19.7px;39 letter-spacing: -0.01em;40 display: flex;41 justify-content: center;42 align-items: center;43 gap: 1rem;44}4546.holiday-clock {47 display: flex;48 justify-content: center;49 align-items: center;50 color: #2a2552;51 border-radius: 3px;52}5354.box-3 {55 display: flex;56 flex-direction: column;57 justify-content: center;58 align-items: center;59 background-color: #fff;60 border-radius: 2px;61 width: 2.5rem;62 height: 3rem;63 margin: 0 2px;64 padding: 3px;65 font-size: 12px;66 line-height: 20px;67}6869.clock-number-2 {70 font-size: 14px;71 font-weight: 900;72 line-height: 1;73}7475.clock-label-2 {76 font-size: 1rem;77 line-height: 1;78 text-transform: uppercase;79}8081.text-block-countdown {82 color: #fff;83 padding: 0 0.15rem;84 font-weight: 800;85}8687.atcButton button {88 background: #039d00 !important;89 color: #fff;90 padding: 5px 20px !important;91 border-radius: 5px;92 font-size: 13px;93 min-height: 40px;94}9596@keyframes primaryGradient {97 0% { background-position: 0% 50%; }98 50% { background-position: 100% 50%; }99}100101@media (max-width: 740px) {102 .announcement-wrapper {103 font-size: 16px;104 padding: 0px 0;105 gap: 7px;106 }107.clock-number-2 {108 font-size: 15px!important;109 font-weight: 900;110 line-height: 1;111}112.clock-label-2 {113 font-size: 7px!important;114 line-height: 1;115 text-transform: uppercase;116}117 .holiday-clock {118 flex-wrap: wrap;119 }120121 .box-3 {122 width: 1.5rem;123 height: 1.75rem;124 }125126 .clock-number-2 {127 font-size: 0.8rem;128 }129130 .clock-label-2 {131 font-size: 0.45rem;132 }133}134135@media (max-width: 379px) {136 .announcement-wrapper {137 font-size: 15px;138 gap: 5px;139 }140141 .box-3 {142 width: 2.5rem;143 height: 3rem;144 }145146 .text-block-countdown {147 padding: 0 0.1rem;148 }149}150151@media (max-width: 360px) {152 .atcButton button {153 padding-inline: 20px;154 }155}156</style>157158<script>159// Countdown Timer Script160(function() {161 const endTime = new Date("January 25, 2025 00:00:00").getTime();162163 function updateTimer() {164 const now = new Date().getTime();165 const timeLeft = endTime - now;166167 if (timeLeft < 0) {168 document.getElementById('js-clock').innerHTML = '<span>Sale Ended</span>';169 return;170 }171172 const hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));173 const minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));174 const seconds = Math.floor((timeLeft % (1000 * 60)) / 1000);175176 document.getElementById('js-clock-hours').textContent = String(hours).padStart(2, '0');177 document.getElementById('js-clock-minutes').textContent = String(minutes).padStart(2, '0');178 document.getElementById('js-clock-seconds').textContent = String(seconds).padStart(2, '0');179 }180181 setInterval(updateTimer, 1000);182 updateTimer(); // Initial call to avoid delay183})();184</script>
How to install Sales timer on your Shopify theme
This snippet belongs in sections/announcement-bar.liquid (or the top of layout/theme.liquid), directly above your header so it renders on every page. Expect the whole job to take about 15–25 minutes.
- 1From your Shopify admin, open Online Store → Themes, click the … button on your live theme and choose Duplicate. Always work on a copy so you can roll back instantly.
- 2On the duplicated theme, click … → Edit code to open the theme code editor.
- 3Open sections/announcement-bar.liquid (or the top of layout/theme.liquid) in the file tree. If your theme uses different file names, search for the template that renders the area where you want the block to show up.
- 4Click Copy code on this page, then paste the snippet directly above your header so it renders on every page.
- 5The snippet ships with its own scoped
<style>block, so you do not need to touchbase.cssortheme.css. If you prefer to keep CSS centralised, move the contents of the style tag into your theme stylesheet and delete the inline block. - 6Keep the
<script>tag at the end of the snippet. It only runs once the surrounding markup exists in the DOM, so moving it higher up the file can break the behaviour. - 7Click Save, then hit Preview and check the block on desktop, tablet and mobile widths.
- 8When you are happy with the result, publish the duplicated theme from Online Store → Themes → Actions → Publish.
How to customise it
Every value below lives inside the snippet, so you can adapt Sales timer to your brand without touching the rest of the theme.
- Colours — the snippet uses
#BDE6FF,#6A93AC,#174059,#fff. Replace those values inside the style block with your brand palette, keeping at least a 4.5:1 contrast ratio between text and background so the block stays accessible. - Gradient — swap the
linear-gradient(...)declaration for a flat background colour if you want a more minimal, theme-native look. - Sizing — adjust the font-size values (16px, 12px, 14px) and the padding so the block carries the same visual weight as the elements around it.
- Corners —
border-radius: 3pxcontrols the roundness. Set it to 0 for a sharper editorial look, or increase it for a softer, app-like feel. - Copy — rewrite the hard-coded text (for example “New Year Sale Ends In”) in your own brand voice, and translate it if you sell in more than one language.
- Timing — the countdown duration is set in the script. Change the target time or the interval value to control how long the offer runs before it resets.
- Responsive behaviour — the
@mediaquery defines the mobile breakpoint. Adjust the pixel value if your theme uses a different breakpoint scale.
Common mistakes to avoid
These are the issues merchants run into most often when installing a snippet like this one.
- Editing the live theme directly. Duplicate it first — a single unbalanced Liquid tag can take a storefront down mid-campaign.
- Pasting the code into the wrong file. Dropped into
layout/theme.liquidinstead ofsections/announcement-bar.liquid, this block will render on every page of the store, including ones where it makes no sense. - Renaming the CSS classes in the markup but not in the style block, or vice versa. The class names have to match exactly or the styling silently disappears.
- Adding the snippet twice on the same page. The script targets its selector, so two copies can conflict or double-fire.
- Running a countdown that resets on every page load and never actually expires. Shoppers notice fake urgency, and in the EU and UK it can breach consumer-protection rules.
- Publishing without testing on a real phone. Most Shopify traffic is mobile, and layout problems almost always surface there first.
Performance notes
What this block costs you in load time, and how to keep that cost at zero.
- The CSS is inline and scoped to this block, so it adds no extra network request. At a few kilobytes it has no measurable effect on your Lighthouse score.
- The JavaScript is vanilla — no jQuery, no external library, no additional request. Keep it after the markup so it never blocks rendering.
- The animation runs on CSS keyframes. Animate only transform and opacity where you can — animating width, height or top forces a layout recalculation on every frame.
- Run PageSpeed Insights before and after you add the block so you have a concrete number rather than a guess.
SEO & accessibility
How to add this block without damaging your on-page structure or your rich results.
- Nothing in this snippet should replace your page
<h1>. Keep product and page headings intact and use<h2>or<h3>for the block's own heading so the document outline stays clean. - If the block shows review or rating content, keep it consistent with the structured data your review app already outputs. Duplicating or contradicting rating markup can cost you the rich result entirely.
- The block does not create a new URL, so there is no canonical or indexing change to make. It improves on-page engagement signals rather than crawlability.
Sales timer — questions merchants ask
Will this snippet work with my theme?
It is built with standard Liquid, HTML and CSS, so it works with Dawn and virtually every Online Store 2.0 theme, as well as most vintage themes. The only thing that changes between themes is the file you paste it into — if yours has no sections/announcement-bar.liquid, look for the equivalent template that renders the same area.
Do I need an app to use it?
No. This is theme code you own outright: no monthly fee, no third-party script tag, and no app that can break your storefront the next time it updates.
How long does it take to add “Sales timer” to a store?
Most merchants have it live in under fifteen minutes — duplicate the theme, paste the code, adjust the colours and copy, preview on mobile, publish.
The block appears but nothing happens. What is wrong?
That is almost always a script-order problem. Check that the script tag is still at the bottom of the snippet and that the markup was not pasted inside another script or a Liquid comment block. Open your browser console and look for an error naming the snippet's selector.
The styling looks broken after pasting. How do I fix it?
Confirm you copied the whole snippet including the closing style tag, then check whether one of your theme's own CSS rules is overriding it. If a theme rule wins, increase the specificity of the snippet's selector rather than scattering !important through the file.
Will it slow my store down?
Not meaningfully. It is inline markup with scoped CSS and at most a few lines of vanilla JavaScript — no external libraries, no extra HTTP request. Optimising your product images will always have a far bigger impact on load time.
Can I use it on a client store or a commercial project?
Yes. Every snippet in the MCO Hub library is free to copy, modify and ship on any store, including client work. Attribution is appreciated but not required.
Related snippets
Keep exploring
Guides
Shopify Liquid
Deals & Discounts



