Back to Shopify Liquid
Announcement Bar 1
Shopify Liquid

Announcement Bar 1

Creates a high-visibility animated marquee bar featuring a shifting gradient background and scrolling text. The snippet includes a hover-to-pause feature and uses JavaScript to dynamically calculate width for a seamless, infinite loop.

MediumAnnouncement BarMarqueeShipping Info AirCROUrgency
134 lines · 4.6 KB
Setup 15–25 minutes 5 min read 133 lines
Key features
  • Infinite sliding text marquee
  • Animated gradient background effect
  • Auto-pause on mouse hover
  • Dynamic width calculation via JS
  • Reduced motion accessibility support
Best use cases
  • Highlighting free shipping or seasonal promotions
  • Displaying payment methods like Cash on Delivery
  • Increasing site urgency with a scrolling 'sale' ticker
Compatibility
  • Shopify Online Store 2.0
  • Most Shopify themes

The code

Shopify Liquid
1<!-- INICIO BARRA DE ANUNCIOS 1 -->
2 <style>
3 /* Section styling */
4 #custom-marquee-text {
5 overflow: hidden;
6 background-color: #f0f0f0; /* Ejemplo background color */
7 color: #ffffff; /* Ejemplo text color */
8 font-size: 12px;
9 padding-top: 1rem;
10 padding-bottom: 1rem;
11 margin-top: 0;
12 margin-bottom: 0;
13 background: linear-gradient(60deg, #00b26c 0%, #027548 15%, #00b26c 100%);
14 background-size: 300% 100% !important;
15 animation: 3.5s linear infinite featureAnimation;
16 }
17
18 #custom-marquee-text ul {
19 list-style: none;
20 margin: 0;
21 padding: 0;
22 display: inline-flex;
23 animation-timing-function: linear;
24 animation-iteration-count: infinite;
25 animation-name: marquee-animation;
26 animation-duration: 15s;
27 }
28
29 #custom-marquee-text ul:hover {
30 animation-play-state: paused;
31 }
32
33 #custom-marquee-text ul li {
34 position: relative;
35 flex-shrink: 0;
36 padding-left: 20px;
37 padding-right: 20px;
38 }
39
40 #custom-marquee-text ul li::after {
41 content: "";
42 background-color: currentColor;
43 mask-image: url("data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg version='1.1' width='10px' height='10px' viewBox='0 0 10.0 10.0' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Cdefs%3E%3CclipPath id='i0'%3E%3Cpath d='M10,0 L10,10 L0,10 L0,0 L10,0 Z'%3E%3C/path%3E%3C/clipPath%3E%3CclipPath id='i1'%3E%3Cpath d='M5,0 C7.76142375,0 10,2.23857625 10,5 C10,7.76142375 7.76142375,10 5,10 C2.23857625,10 0,7.76142375 0,5 C0,2.23857625 2.23857625,0 5,0 Z'%3E%3C/path%3E%3C/clipPath%3E%3C/defs%3E%3Cg clip-path='url(%23i0)'%3E%3Cg clip-path='url(%23i1)'%3E%3Cpolygon points='0,0 10,0 10,10 0,10 0,0' stroke='none' fill='currentColor'%3E%3C/polygon%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
44 background-repeat: no-repeat;
45 background-size: cover;
46 width: .25rem;
47 height: .25rem;
48 position: absolute;
49 right: 0;
50 top: 50%;
51 transform: translate(50%, -50%);
52 }
53
54 @media (prefers-reduced-motion:reduce) {
55 #custom-marquee-text ul {
56 animation: none;
57 }
58 }
59
60 /* Various classes */
61 .text-sm {
62 font-size: .8em;
63 }
64
65 .text-lg {
66 font-size: 1.2em;
67 }
68
69 .fw-bold {
70 font-weight: bold;
71 }
72
73 .text-uppercase {
74 text-transform: uppercase;
75 }
76
77 .text-capitalize {
78 text-transform: capitalize;
79 }
80
81 @keyframes featureAnimation {
82 0% {
83 background-position: 0%;
84 }
85 50% {
86 background-position: 150%;
87 }
88 100% {
89 background-position: 300%;
90 }
91 }
92
93 @keyframes marquee-animation {
94 from { transform: translateX(0); }
95 to { transform: translateX(-100%); }
96 }
97 </style>
98
99 <section id="custom-marquee-text" class="custom-marquee-text">
100 <ul class="text-lg fw-bold text-uppercase" data-animation-duration="15" data-marquee-direction="left">
101 <li>Envio gratis a todo el Peru</li>
102 <li>Paga tu producto al recibir en casa</li>
103 <li>Hasta 50% de descuento</li>
104 </ul>
105 </section>
106
107 <script>
108 document.addEventListener('DOMContentLoaded', () => {
109 const list = document.querySelector('#custom-marquee-text ul');
110 const marqueeWidth = list.scrollWidth;
111 const marqueeLength = list.querySelectorAll('li').length;
112
113 list.insertAdjacentHTML('beforeEnd', list.innerHTML);
114 list.insertAdjacentHTML('beforeEnd', list.innerHTML);
115
116 list.querySelectorAll('li').forEach((item, index) => {
117 if (index >= marqueeLength) {
118 item.setAttribute('aria-hidden', 'true');
119 }
120 });
121
122 const animationStyle = `
123 <style>
124 @keyframes marquee-animation {
125 from { transform: translateX(0); }
126 to { transform: translateX(-${marqueeWidth}px); }
127 }
128 </style>
129 `;
130 list.insertAdjacentHTML('beforeBegin', animationStyle);
131 });
132 </script>
133<!-- FINAL BARRA DE ANUNCIOS 1 -->

How to install Announcement Bar 1 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.

  1. 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.
  2. 2On the duplicated theme, click … → Edit code to open the theme code editor.
  3. 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.
  4. 4Click Copy code on this page, then paste the snippet directly above your header so it renders on every page.
  5. 5The snippet ships with its own scoped <style> block, so you do not need to touch base.css or theme.css. If you prefer to keep CSS centralised, move the contents of the style tag into your theme stylesheet and delete the inline block.
  6. 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.
  7. 7Click Save, then hit Preview and check the block on desktop, tablet and mobile widths.
  8. 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 1 to your brand without touching the rest of the theme.

  • Colours — the snippet uses #f0f0f0, #ffffff, #00b26c, #027548. 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 (12px, .8em, 1.2em) and the padding so the block carries the same visual weight as the elements around it.
  • Copy — rewrite the hard-coded text (for example “Envio gratis a todo el Peru”) in your own brand voice, and translate it if you sell in more than one language.
  • Responsive behaviour — the @media query 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.liquid instead of sections/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.
Frequently asked questions

Announcement Bar 1 — 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 1” 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

Deals & Discounts