
Announcement Bar
A high-visibility announcement bar featuring an animated linear-gradient background and a JavaScript-driven countdown timer. It uses a loop-back mechanism to reset the timer once it hits zero, ensuring the promotion always appears active.
- Animated gradient background transition
- Real-time JavaScript countdown timer
- Responsive mobile-first CSS styling
- Auto-resetting promotion logic
- Individual time unit badge styling
- Driving urgency for Black Friday or flash sale events
- Displaying a persistent limited-time offer in the header
- Capturing customer attention with animated color shifts
- Most Shopify themes
- Shopify Online Store 2.0
The code
1<!DOCTYPE html>2<html lang="en">3<head>4 <meta charset="UTF-8">5 <meta name="viewport" content="width=device-width, initial-scale=1.0">6 <title>Announcement Bar</title>7 <style>8 body.unique-body-class {9 margin: 0;10 font-family: Arial, sans-serif;11 }1213 .unique-announcement-bar {14 position: relative;15 display: flex;16 justify-content: center;17 align-items: center;18 height: 40px;19 color: white;20 font-size: 14px;21 font-weight: bold;22 background: linear-gradient(90deg, black, #8e2de2, #ff0080, black);23 background-size: 300% 300%;24 animation: unique-gradient-shift 6s infinite;25 overflow: hidden;26 }2728 .unique-countdown-wrapper {29 position: absolute;30 right: 15px;31 display: flex;32 gap: 8px;33 }3435 .unique-time {36 background: white;37 color: black;38 padding: 3px 8px;39 border-radius: 3px;40 font-size: 12px;41 }4243 @keyframes unique-gradient-shift {44 0% {45 background-position: 0% 50%;46 }47 50% {48 background-position: 100% 50%;49 }50 100% {51 background-position: 0% 50%;52 }53 }5455 /* Mobil Cihazlar İçin (768px ve Altı) */56 @media (max-width: 768px) {57 .unique-announcement-bar {58 height: 30px; /* Daha dar yükseklik */59 font-size: 12px; /* Yazı boyutu küçüldü */60 justify-content: flex-start; /* Metni sola hizala */61 padding-left: 10px; /* Sol boşluk eklendi */62 }6364 .unique-countdown-wrapper {65 right: 10px; /* Sağdan boşluk azaltıldı */66 gap: 5px; /* Geri sayım elemanları arasındaki boşluk azaltıldı */67 }6869 .unique-time {70 padding: 2px 6px; /* Geri sayımın padding değerleri küçültüldü */71 font-size: 10px; /* Yazı boyutu küçültüldü */72 }73 }74 </style>75</head>76<body class="unique-body-class">77 <div class="unique-announcement-bar">78 <div>Early Black Friday Sale Ends In</div>79 <div class="unique-countdown-wrapper">80 <span class="unique-time"><span id="unique-hours">00</span> HRS</span>81 <span class="unique-time"><span id="unique-minutes">00</span> MIN</span>82 <span class="unique-time"><span id="unique-seconds">00</span> SEC</span>83 </div>84 </div>8586 <script>87 function startCountdown(durationInSeconds) {88 let remainingTime = durationInSeconds;8990 function updateCountdown() {91 if (remainingTime < 0) {92 remainingTime = durationInSeconds;93 }9495 const hours = Math.floor(remainingTime / 3600);96 const minutes = Math.floor((remainingTime % 3600) / 60);97 const seconds = remainingTime % 60;9899 document.getElementById('unique-hours').textContent = String(hours).padStart(2, '0');100 document.getElementById('unique-minutes').textContent = String(minutes).padStart(2, '0');101 document.getElementById('unique-seconds').textContent = String(seconds).padStart(2, '0');102103 remainingTime--;104 }105106 updateCountdown();107 setInterval(updateCountdown, 1000);108 }109110 startCountdown(7200);111 </script>112</body>113</html>
How to install Announcement Bar 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 Announcement Bar to your brand without touching the rest of the theme.
- Colours — the snippet uses
#8e2de2,#ff0080. 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. - Typography — the block declares
font-family: Arial, sans-serif. Delete that line to inherit your theme font instead, which usually looks better integrated. - Sizing — adjust the font-size values (14px, 12px, 10px) 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 “Announcement Bar”) 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.
Announcement Bar — 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 “Announcement Bar” 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
Templates
Tools
Deals & Discounts



