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 value | Documented behavior |
|---|---|
auto | Initial value; classic-scrollbar space depends on overflow and whether content overflows. |
stable | Reserves space with classic scrollbars when overflow is auto, scroll or hidden, even without overflowing content. |
stable both-edges | Also reserves a matching gutter on the opposite inline edge. |
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
- CSS Overflow Module Level 3 (W3C CSS Working Group).
- scrollbar-gutter (MDN contributors).
- dialog element (MDN contributors).
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