Back

Lock Page Scrolling in Webflow

Learn how to disable page scrolling in Webflow with this simple custom code tutorial. Great for menus, popups, and overlays. Copy + paste ready.

July 11, 2025
15
Min Read
Peter B
Product & Development
@flowbase

How to Lock Page Scrolling in Webflow with a Simple Code Snippet 🔒

Need to prevent page scrolling when a menu or popup is open? Here’s a quick and easy way to lock and unlock scrolling in your Webflow project using just a few lines of custom code. This technique is especially helpful when creating custom menus, overlays, or modals where you want to restrict user interaction with the background content.

What This Does ✅

This scroll-lock trick disables page scrolling by toggling the overflow: hidden style on the <html> element. With one click, you can lock or unlock scrolling dynamically using a trigger element—like a menu toggle or modal close button.

Clone or Preview 🔗

Want to test it out before adding it to your project?

Instructions ✍️

1. Add the script to your custom code settings.

Paste the following code into your Project Settings → Custom Code → Before </body> tag, or into the Page Settings if you only need it on specific pages.Add the code into your Before </body> tag in custom code settings.

<style>
/* Lock Webflow Scrolling CSS */
html.no-scroll {
  overflow: hidden;
}
</style>

<!-- Lock Webflow Scrolling Script -->
<script type = "text/javascript" > $('.lock-scroll').on('click', toggleScrolling);
function toggleScrolling() {
	$('html').toggleClass('no-scroll');
} 
</script>

💡 This code listens for clicks on any element with the .lock-scroll class. When clicked, it toggles the no-scroll class on the <html> element, which prevents the page from scrolling.

2. Add the .lock-scroll Class to Your Trigger Element

Now, add the class lock-scroll to any element you want to use as a toggle—for example, your mobile menu button or overlay close button.

Once published, test the feature on the live site to confirm it’s working as expected.

💬 Need More Customization?

Want more control? You can extend the code to:

  • Only lock scrolling when a certain element (like a menu) is visible
  • Automatically remove the scroll lock on Escape key press
  • Support nested modals or overlays

Let us know if you'd like a more advanced version!

Did you find this helpful? 💕

We love supporting the Webflow community, and your support means the world to us. If this helped you:

Thanks for being awesome. Keep building! 💪

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Pro
Upgrade to Flowbase Pro

Discover unlimited inspiration to help you build better, faster.

All Access
Join Pro
3500+ components
Build better, faster
Illustrations & Icons
Designers side-kick
Instant copy & paste
Paste to your platform