Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Scroll locked after closing a modal: how to find and fix it

CNV-120Medium impactCould addBy FunnelGuardPublished Updated
On this page

What this issue is

When a modal (a popup box that sits over the page) opens, most scripts stop the page behind it from scrolling. They usually do this by adding overflow: hidden to the body or html element, or by setting position: fixed on the body. That is correct while the modal is open.

The bug appears when the modal closes but the lock stays. The popup disappears, yet the page will not scroll. Often it only happens on one close path, for example when the visitor submits the form inside the popup, presses Esc, or taps outside the box.

How the scroll lock gets stuck

The modal locks scrolling on open, but the close code never removes the lock.

Why it costs you leads or sales

A visitor who closes a popup expects to carry on reading. If the page is frozen, they cannot reach the pricing, the form below the fold or the add-to-cart button. Many will assume the site is broken and leave. Some will reload, and a few will not come back.

It hurts most on mobile, where there is no scroll bar and no obvious way to recover. It also hurts most right after a popup form submit, the moment when a visitor is most engaged. The impact is medium: it does not stop every visit, but it quietly wastes traffic you paid for.

Where the visit breaks
  1. Lands on pageReads the first screen
  2. Popup opensPage scroll is locked
  3. Closes popupLock is not removed
  4. Scrolls to offerPage will not move
  5. Form or checkoutNever reached

The visitor does what you asked, then hits a frozen page.

Visitors who keep browsing after closing a popupExample numbers
Visitors who keep browsing after closing a popup (example)Scroll restored: 80 %; Scroll stuck: 35 %031618035Scroll restoredScroll stuck%

Example: illustrative numbers only. A page that scrolls again after close keeps far more visitors than one that stays frozen.

How to check if your site has it

Test every way a modal can close
  1. Open the page in a fresh tab

    Use a private window so saved cookies do not hide the popup. Trigger it by waiting, scrolling or clicking the button that opens it.

  2. Close it with each method

    Try the X button, a click on the dark overlay, the Esc key, and submitting the form inside it. Test one at a time, reloading between tries.

  3. Try to scroll

    Use the mouse wheel, keyboard arrow keys and, on a phone, a finger swipe. Check the page really moves.

  4. Inspect the body and html elements

    In Chrome, right-click the page, choose Inspect, and select the body and html tags. Look in Styles for overflow: hidden, position: fixed, a set height, or a class such as modal-open or no-scroll left behind.

  5. Repeat on a real phone

    iPhone Safari and Android Chrome behave differently from desktop. Remote debugging or a real device is more reliable than a resized desktop window.

Common leftovers that freeze scrolling
WhereWhat you seeWhat it means
body styleoverflow: hiddenLock added on open, never removed
body styleposition: fixed; top: -1200pxScroll-position trick left in place
body or html classmodal-open, no-scroll, is-lockedClass not removed on close
html styleoverflow: hidden or height: 100%A second lock on the html element
body stylepadding-right: 15pxScrollbar-width compensation left behind

How to fix it

The fix is the same everywhere: whatever the open code adds, the close code must remove, on every close path. How you get there depends on your tool.

Fix by platform
  1. Find which plugin opens the popup

    Deactivate popup, cookie and slider plugins one at a time on a staging copy and retest. The one whose removal fixes scrolling is the cause.

  2. Update and check settings

    Update the plugin and theme. Look in the popup's settings for options such as Disable page scrolling or Lock body scroll and test with it off.

  3. Report or patch

    If the bug remains, send the plugin author the exact close path that fails. As a stopgap, add the custom code from the Custom code tab through a child theme or a code snippets plugin.

Lock and unlock in one place, used by every close pathjavascript
let savedScrollY = 0;

function lockScroll() {
  savedScrollY = window.scrollY;
  document.body.style.position = 'fixed';
  document.body.style.top = `-${savedScrollY}px`;
  document.body.style.width = '100%';
}

function unlockScroll() {
  document.body.style.position = '';
  document.body.style.top = '';
  document.body.style.width = '';
  window.scrollTo(0, savedScrollY);
}

function closeModal(modal) {
  modal.hidden = true;
  unlockScroll();
}

// Every close path calls closeModal
document.querySelector('.modal-close').addEventListener('click', () => closeModal(modalEl));
document.querySelector('.modal-overlay').addEventListener('click', () => closeModal(modalEl));
document.addEventListener('keydown', (e) => { if (e.key === 'Escape') closeModal(modalEl); });
Close behaviour

Broken

  • Open code adds overflow: hidden
  • Only the X button removes it
  • Form submit or Esc leaves the page frozen

Fixed

  • One unlock function
  • Called from X, overlay, Esc and form success
  • Scroll position restored on close

How to confirm it's fixed

Confirm checklist
  • Page scrolls after closing with the X button
  • Page scrolls after clicking the overlay
  • Page scrolls after pressing Esc
  • Page scrolls after submitting the popup form
  • body and html have no leftover overflow: hidden, position: fixed or lock class in the inspector
  • The page is back at the same scroll position, not jumped to the top
  • Tested on iPhone Safari and Android Chrome
  • Popup can be opened and closed twice in a row without issue

How to prevent it happening again

Scroll lock bugs usually return after a plugin, theme or popup tool update, or when a marketer adds a new popup with different close rules. Build a habit around that.

Prevention habits
  • Test popups on a phone after every theme, plugin or popup tool update
  • Add each new popup to a short test list covering all four close paths
  • Keep only one scroll-lock mechanism on the site, not one per plugin
  • Prefer maintained popup tools or the native dialog element over custom code
  • Note who owns popup changes so tests are not skipped

How FunnelGuard handles this

FunnelGuard does not check for this yet. A scroll-after-close check is a possible future addition, but today it is not part of what FunnelGuard runs, so do not rely on it to warn you about a frozen page.

What FunnelGuard does do is run your real customer journeys, such as lead forms, checkouts and booking or chat buttons, on a schedule with a robot visitor. It checks each step, the tracking hits sent to ad and analytics platforms, and whether test leads reach your inbox and CRM. A popup problem that stops a form or button from being used can show up as a failed journey step, but a page that simply will not scroll is not something it looks for.

To watch for scroll lock yourself, add the popup close test above to your release checklist and run it on a real phone after any change. You can also use a free browser tool such as Chrome DevTools to inspect the body styles. To see what FunnelGuard does catch, you can start with the free plan (1 site, 2 journeys, daily checks, no card) or request the free read-only website audit.

Questions people ask

Why can't I scroll after closing a popup on my website?

The popup almost certainly added overflow: hidden or position: fixed to the body or html element when it opened, and the close code never removed it. Inspect the body in your browser's developer tools to see the leftover style, then fix the close code so it removes it.

How do I unlock scrolling after a modal closes?

Remove whatever the modal added when it opened. That usually means resetting document.body.style.overflow to an empty string, or clearing position and top if you used position: fixed, then restoring the saved scroll position with window.scrollTo.

Why does scrolling only break when I submit the form inside the popup?

The form success handler probably hides the modal without calling the same unlock function as the X button. Make every close path, including form success, call one shared close function.

Why does the page jump to the top after closing a modal?

This happens when the lock uses position: fixed on the body without saving the scroll position. Store window.scrollY when the modal opens and call window.scrollTo(0, savedY) when it closes.

Why is scroll stuck only on iPhone after closing a modal?

iOS Safari handles overflow: hidden on the body differently from desktop browsers, so many scripts use position: fixed instead and sometimes forget to undo it. Test on a real iPhone and check the body styles for leftovers.

Is it safe to use overflow: auto !important to fix a stuck scroll?

It works as a quick patch but lets people scroll the page behind an open modal and can hide the real bug. Fix the close code instead and keep the override only as a short-term stopgap.

Does FunnelGuard detect scroll lock after closing a modal?

No. FunnelGuard does not check for this yet, though it is a possible future check. It does run your real journeys and report failed steps, so test popup closing manually on a phone.

How can I find which plugin is locking my scroll?

Disable popup, cookie banner and slider plugins one at a time on a staging copy and retest scrolling. The plugin whose removal fixes it is the cause, and you can then update it or report the bug.

Does FunnelGuard catch this?

Could add

Not checked yet: could be added to FunnelGuard.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.