Ajouter

Lorem ipsum

Lorem ipsum

CRO / Conversion

3 views

2 min

How to Close a Popup with the Esc Key in Webflow

Learn how to close a popup or modal in Webflow with the Esc key using a JavaScript keydown listener.

In this tutorial, Sandro, cofounder of the Gemeos Webflow agency, shows you how to close a popup or modal in Webflow with the Escape key.

Example

CSS classElementRole
modal-overlayPopup divElement to hide when Escape is pressed
is-visibleActive classClass added when the popup is open

The script

Add this script in the Before </body> tag of your page. Replace .modal-overlay with your popup class.

document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
var modal = document.querySelector('.modal-overlay');
if (modal) {
modal.style.display = 'none';
document.body.style.overflow = '';
}
}
});

Adapt it for multiple popups

To close all open popups at once with Escape:

document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
document.querySelectorAll('.modal-overlay').forEach(function(m) {
m.style.display = 'none';
});
document.body.style.overflow = '';
}
});

good to know

This script complements the close-on-outside-click behavior. Use both for the full experience: close on overlay click + close with the Escape key. That’s the WCAG 2.1 accessibility standard for dialogs: they should be closable with the keyboard.

Conclusion

One line of code that significantly improves keyboard accessibility. See also: create a native modal in Webflow.

Published on

You might be interested in these tutorials

Similar tutorials

SEO / GEO

5 min read

5 views

How to Set Up a Redirect in Webflow? (2026)

Updated on 19.12.2025 by Sandro DA SILVA

SEO / GEO

5 min read

5 views

Add structured data to your Webflow site?

Updated on 21.08.2025 by Sandro DA SILVA

No-code

5 min read

5 views

How to Obfuscate a Link in Webflow

Updated on 23.04.2025 by Sandro DA SILVA

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

Ready to launch
Your business?

Alexandre

Max

Enora

Bryan

Cannelle

Tiphaine

You'll :heart: our collaboration...