Back to Shopify Liquid
Copyable discount bar 3
Shopify Liquid

Copyable discount bar 3

A compact, interactive discount announcement bar featuring a one-click clipboard copy function. It includes subtle CSS animations like floating icons and hover effects to draw attention to seasonal promotions without being intrusive.

EasyAnnouncement BarDiscount CodeCROSalesUrgency
150 lines · 4.7 KB
Setup 5–10 minutes 6 min read 149 lines
Key features
  • Click-to-copy clipboard functionality
  • Floating SVG icon animations via CSS keyframes
  • Fully responsive mobile-optimized layout
  • Smooth fade-in entry effect
  • Native JavaScript without external dependencies
Best use cases
  • Promoting specific holiday discount codes like Mother's Day or Black Friday.
  • Adding a sticky or inline coupon bar to product pages to boost conversion.
Compatibility
  • Most Shopify themes
  • Shopify Online Store 2.0

The code

Shopify Liquid
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>Mother's Day Discount Banner</title>
7 <style>
8 body.unique-body-md2024 {
9 font-family: Arial, sans-serif;
10 display: flex;
11 justify-content: center;
12 align-items: center;
13 height: 100vh;
14 margin: 0;
15 background-color: #f0f2f5;
16 }
17
18 .discount-banner-md2024 {
19 display: flex;
20 align-items: center;
21 justify-content: flex-start;
22 background-color: #f5f5f5;
23 padding: 10px 15px;
24 border: 1px solid #dcdcdc;
25 border-radius: 10px;
26 box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
27 font-size: 12px;
28 width: 100%;
29 animation: fadeIn-md2024 2s ease-in-out;
30 margin: 3px 0; /* Yukarı ve aşağı boşluk ekler */
31 }
32
33 .discount-banner-md2024 span {
34 color: #333333;
35 display: flex;
36 align-items: center;
37 }
38
39 .coupon-container-md2024 {
40 display: inline-flex;
41 align-items: center;
42 cursor: pointer;
43 margin-left: 8px;
44 }
45
46 .coupon-code-md2024 {
47 font-weight: bold;
48 color: #333333;
49 display: inline-flex;
50 align-items: center;
51 }
52
53 .copy-button-md2024 {
54 background: none;
55 border: none;
56 cursor: pointer;
57 margin-left: 0;
58 transition: transform 0.3s ease-in-out;
59 display: inline-flex;
60 align-items: center;
61 padding: 0;
62 }
63
64 .copy-button-md2024:hover {
65 transform: scale(1.2);
66 }
67
68 .copy-button-md2024 img {
69 width: 14px;
70 height: 14px;
71 transition: transform 0.3s ease-in-out;
72 margin-left: 3px;
73 }
74
75 .copy-button-md2024 img:hover {
76 transform: rotate(20deg);
77 }
78
79 .coupon-icon-md2024 {
80 width: 20px;
81 height: 20px;
82 margin-right: 8px;
83 transition: transform 0.3s ease-in-out;
84 animation: floatAndRotate-md2024 5s infinite;
85 }
86
87 @keyframes fadeIn-md2024 {
88 from { opacity: 0; }
89 to { opacity: 1; }
90 }
91
92 @keyframes floatAndRotate-md2024 {
93 0%, 100% { transform: translateY(0) rotate(0deg); }
94 25% { transform: translateY(-5px) rotate(-5deg); }
95 50% { transform: translateY(0) rotate(0deg); }
96 75% { transform: translateY(5px) rotate(5deg); }
97 }
98
99 @media (max-width: 600px) {
100 .discount-banner-md2024 {
101 font-size: 10px;
102 }
103 .copy-button-md2024 img {
104 width: 12px;
105 height: 12px;
106 }
107 .coupon-icon-md2024 {
108 width: 16px;
109 height: 16px;
110 margin-right: 6px;
111 }
112 }
113 </style>
114</head>
115<body class="unique-body-md2024">
116 <div class="discount-banner-md2024">
117 <img class="coupon-icon-md2024" src="https://www.svgrepo.com/show/524464/confetti.svg" alt="Confetti Icon">
118 <span>Mother's Day Special! Extra 15% off coupon code:
119 <span class="coupon-container-md2024" id="coupon-container-md2024">
120 <strong id="coupon-code-md2024" class="coupon-code-md2024" onclick="copyToClipboard(event)">MOM2024</strong>
121 <button class="copy-button-md2024" onclick="copyToClipboard(event)">
122 <img src="https://www.svgrepo.com/show/520670/copy-2.svg" alt="Copy Icon">
123 </button>
124 </span>
125 </span>
126 </div>
127
128 <script>
129 function copyToClipboard(event) {
130 event.stopPropagation(); // Bu, tıklama olayının bubble yapmasını önler
131 const couponCode = document.getElementById("coupon-code-md2024").innerText.trim();
132 navigator.clipboard.writeText(couponCode).then(() => {
133 alert('Coupon code copied: ' + couponCode);
134 }).catch(err => {
135 console.error('Failed to copy text: ', err);
136 });
137 }
138
139 document.getElementById("coupon-container-md2024").addEventListener("click", (event) => {
140 const couponCode = document.getElementById("coupon-code-md2024").innerText.trim();
141 navigator.clipboard.writeText(couponCode).then(() => {
142 alert('Coupon code copied: ' + couponCode);
143 }).catch(err => {
144 console.error('Failed to copy text: ', err);
145 });
146 });
147 </script>
148</body>
149</html>

How to install Copyable discount bar 3 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.

  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 Copyable discount bar 3 to your brand without touching the rest of the theme.

  • Colours — the snippet uses #f0f2f5, #f5f5f5, #dcdcdc, #333333. 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.
  • 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 (12px, 10px) and the padding so the block carries the same visual weight as the elements around it.
  • Cornersborder-radius: 10px controls the roundness. Set it to 0 for a sharper editorial look, or increase it for a softer, app-like feel.
  • Images — replace the placeholder image URLs with your own assets. Upload them under Content → Files in Shopify admin and use the generated CDN URL, or reference a theme asset with {{ 'my-image.png' | asset_url }}.
  • Copy — rewrite the hard-coded text (for example “Mother's Day Discount Banner”) 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.
  • Leaving the demo images in place. They are hosted on third-party domains, can disappear at any time and slow the page down. Re-upload them to Shopify Files before going live.
  • 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.
  • Add loading="lazy" plus explicit width and height attributes to every image in the snippet. That prevents Cumulative Layout Shift, which is a Core Web Vitals ranking factor.
  • 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.
  • Third-party image URLs bypass the Shopify CDN and add extra DNS lookups. Self-hosting those assets usually saves 100–300ms on first paint.
  • 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.
  • Write a descriptive alt attribute for every image. Empty or generic alt text is one of the most common accessibility and SEO issues on Shopify stores.
  • 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

Copyable discount bar 3 — 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 “Copyable discount bar 3” 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