CRO / Conversion5 min read
How to control a Webflow banner with local storage ?

Introduction
| Element | ID / Class | Role |
|---|---|---|
| Banner | id='banner' | Element to show/hide |
| Close button | class='close-btn' | Triggers closing and storage |
| localStorage key | bannerClosed | Stores 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



