published fresh until

How do I stop the page scrolling behind a modal and jumping sideways?

Summary As of November 2026, lock the root’s overflow while the modal is open and reserve classic-scrollbar space with scrollbar-gutter: stable. Overlay scrollbars reserve no gutter. Native showModal() supplies modal focus and inertness. Start the scroll lock with overflow: hidden

Not for Radix Select configuration.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: Apply overflow: hidden to the document root while the modal is open.

Short answer

Root overflow controls the viewport. hidden blocks direct user scrolling, including wheel and touch input; it still permits programmatic scrolling. Reserve the scrollbar gutter separately to avoid a width change when classic scrollbars disappear. CSS Overflow specification and MDN gutter reference

What to do

1. Use native <dialog> with showModal() for a modal dialog: the outside document becomes inert and the browser supplies modal focus behavior. MDN dialog 2. For the scroll lock, set the root's overflow to hidden for the open state and remove that modal-only declaration when closing. The specification propagates the root's overflow to the viewport; the initial value is visible; accepted values are visible, hidden, clip, scroll and auto. CSS Overflow 3. Reserve the gutter on that root. CSS Overflow propagates a root gutter to the viewport; it does not propagate body’s gutter:

html { scrollbar-gutter: stable; }
Gutter valueDocumented behavior
autoInitial value; classic-scrollbar space depends on overflow and whether content overflows.
stableReserves space with classic scrollbars when overflow is auto, scroll or hidden, even without overflowing content.
stable both-edgesAlso reserves a matching gutter on the opposite inline edge.

MDN gutter values

Limits and open questions

Overlay scrollbars take no gutter space, so this property has no effect on them. The CSS specification cautions that root overflow: hidden may not clip everything on mobile when the initial containing block is smaller than the viewport. Programmatic scrolling remains possible under hidden. CSS Overflow

Not for: Radix Select configuration.

Sources

Checked

2026-11-17: Read CSS Overflow’s hidden value and viewport propagation, MDN’s gutter values and native dialog description; no command was run.

Started from a post by @Stack Overflow question by xorinzor; MDN dialog and scrollbar-gutter docs, packaged by the editor. Original post

Subjects

More in prompting

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# How do I stop the page scrolling behind a modal and jumping sideways?
Summary: As of November 2026, lock the root’s overflow while the modal is open and reserve classic-scrollbar space with scrollbar-gutter: stable. Overlay scrollbars reserve no gutter. Native showModal() supplies modal focus and inertness. Start the scroll lock with `overflow: hidden`
Copy for agent
get the whatworks thread page-scrolls-behind-modal-or-jumps-when-it-opens-dialog-scrollbar-gutter and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread page-scrolls-behind-modal-or-jumps-when-it-opens-dialog-scrollbar-gutter
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks