
Announcement Bar 2
A high-impact announcement bar featuring a scrolling image background and a dynamic radial gradient animation. It supports separate background images for mobile and desktop to ensure optimal scaling across different devices.
- Infinite horizontal scrolling animation
- Dynamic radial gradient background effect
- Device-specific background images (Mobile/Desktop)
- Full-width clickable banner area
- Touch-optimized interaction for mobile devices
- Displaying scrolling brand logos or promotional assets
- Adding a highly visual, animated call-to-action to the top of the store
- Creating a tactile, clickable banner for mobile users to navigate to specific collections
- Most Shopify themes
The code
1<!-- INICIO BARRA DE ANUNCIOS 2-->2 <section id="ad-banner-section">3 <div id="ad-banner"></div>4 </section>56 <script>7 document.addEventListener('DOMContentLoaded', () => {8 const adBannerSection = document.getElementById('ad-banner-section');9 const adLink = 'https://www.tusitio.com'; // Reemplaza con el enlace deseado1011 adBannerSection.addEventListener('click', () => {12 window.location.href = adLink;13 });1415 adBannerSection.addEventListener('touchstart', () => {16 window.location.href = adLink;17 });1819 // Activar la animación infinita si se desea20 const activateInfiniteBanner = true; // Cambia a 'false' si no deseas la animación infinita21 if (activateInfiniteBanner) {22 document.getElementById('ad-banner').style.animation = 'infinite-shift-left 1000s linear infinite';23 }24 });25 </script>2627<style>28 #ad-banner-section {29 background: radial-gradient(#3C70EE 20%, #0E4895 50%, #3C70EE 80%);30 width: 100%;31 background-size: 400% 400%;32 animation: 5s infinite rgbAnimation;33 }3435 #ad-banner {36 background: transparent url('https://cdn.shopify.com/s/files/1/0673/9787/7980/files/celular-barra.webp?v=1718159212') repeat-x 50% 0;37 height: 70px;38 cursor: pointer;39 }4041 /* Animación infinita para el banner */42 @keyframes infinite-shift-left {43 0% {44 background-position: 50000px;45 }46 100% {47 background-position: 0;48 }49 }5051 @media screen and (min-width: 701px) {52 #ad-banner {53 background: transparent url('https://cdn.shopify.com/s/files/1/0673/9787/7980/files/computador-barra.webp?v=1718159212') repeat-x 50% 0;54 height: 50px;55 }56 }57 </style>58<!-- FINAL BARRA DE ANUNCIOS 2-->
How to install Announcement Bar 2 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 5–10 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 2 to your brand without touching the rest of the theme.
- Colours — the snippet uses
#3C70EE,#0E4895. 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. - 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.
- 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 2 — 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 2” 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
Deals & Discounts



