Webflow sync, pageviews & more.
NEW

How can I prevent the body from scrolling when the mobile menu overlay is active in Webflow?

TL;DR
  • Create a no-scroll class with overflow set to hidden.
  • Use Webflow interactions on the Navbar to add this class to the Body when the menu opens and remove it when it closes.

To prevent body scrolling when the mobile menu overlay is active in Webflow, you need to disable page scrolling while the menu is open.

1. Create a Custom no-scroll Class

  • In your Webflow project, create a new class, e.g., no-scroll.
  • Set the following style for this class:
  • Overflow: Hidden
  • Do not assign this class to any elements yet.

2. Add Interactions to Toggle no-scroll

  • Go to your Navbar element or the element that triggers your mobile menu.
  • In the Interactions panel, create a new page trigger or element trigger based on the menu open/close event.

For native Webflow Navbar component:

  • Select the Navbar element.
  • Go to the Interactions panel, and under Element Trigger, choose Navbar.
  • Set two actions:
  • When Navbar opens → Add Class no-scroll to Body
  • When Navbar closes → Remove Class no-scroll from Body

3. Assign the Actions to the Body

  • In the interaction steps above, choose Body (All Pages) as the target element when adding/removing the class.

4. Double-Check that Overflow is Hidden

  • Open the menu in preview mode. Body scrolling should be disabled when the menu is open and re-enabled when closed.
  • You may want to test on both actual mobile devices and browser emulators to confirm UX behavior.

Summary

To stop body scrolling when the mobile menu is open, add a no-scroll class (with overflow: hidden) to the Body using interactions triggered by the Navbar open/close events, then remove it when the menu closes. This ensures a clean mobile user experience.

Rate this answer

Other Webflow Questions