Skip to content

CRO / Conversion5 min read

How to control a Webflow banner with local storage ?

Introduction

ElementID / ClassRole
Bannerid='banner'Element to show/hide
Close buttonclass='close-btn'Triggers closing and storage
localStorage keybannerClosedStores the closed state

In this tutorial, Sandro, cofounder of the Gemeos Webflow agency, shows you how to control when a banner appears and closes using the browser's local storage in Webflow.

Controlling when a promotional banner appears and closes using the browser's local storage improves the user experience. This technique keeps the banner from showing up on every visit, reducing interruptions and distractions for the user.

Here's how to do it:

1. Add the "banner" ID to your banner

2. Add the "close-btn" class to the element that closes your banner

3. Hide your banner by default

Your banner should be set to Display: None by default

4. Add this code to the <body> of your page

<script>
// Check whether the banner should stay hidden when the page loads
document.addEventListener('DOMContentLoaded', function() {
 if (localStorage.getItem('bannerClosed') !== 'true') {
 document.getElementById('banner').style.display = 'flex';
 }
});

// Add an event listener to close the banner
document.querySelector('.close-btn').addEventListener('click', function() {
 document.getElementById('banner').style.display = 'none';
 localStorage.setItem('bannerClosed', 'true');
});
</script>

5. All that's left is to test it

Published on Apr 10, 2025

Sandro DA SILVA

Growth Marketer, Webflow expert, and jack-of-all-trades. Sandro handles commercial operations, ensures projects run smoothly, and addresses marketing-related issues (SEO, Tracking, Copywriting, etc).

You might be interested in these tutorials

Related tutorials

See all

You're going to working with us, guaranteed

Ready to launch your business?

get a quote

Let’s f*****G GO !!