The Browser Top Layer vs The inert Attribute and Modal Focus Containment
showModal() marks background subtrees inert automatically, whereas custom overlays require the inert attribute explicitly.
Structured Comparison Matrix
| Dimension | The Browser Top Layer | The inert Attribute and Modal Focus Containment |
|---|---|---|
| Mental Model | End z-index: 99999 wars and overflow: hidden modal clipping—the Browser Top Layer paints <dialog> and [popover] in a document-level LIFO list above the root stacking context. | Boolean HTML attribute that removes an entire subtree from pointer hit-testing, keyboard focus order, text selection, find-in-page, and the accessibility tree. |
| Maturity & Domain | Baseline · Widely · DOM & Events Chrome 114+ · Firefox 125+ · Safari 17+ | Baseline · Widely · DOM & Events Chrome 102+ · Firefox 112+ · Safari 15.5+ |
| Prerequisites | ||
| When Not to Use | When not to use Top Layer: Do not promote persistent inline banners or sticky headers; keep them in normal document flow, and use the inert attribute when non-Top-Layer regions must block background focus. | When not to use inert: Never use inert to disable a single <button>, use disabled or aria-disabled so the control remains discoverable. |
Engine Mechanics & Trade-Offs
The Top Layer is a document-level paint list rendered after the root stacking context, escaping ancestor overflow: hidden, clip-path, and z-index.
Key Pitfalls: z-index Ignored Inside Top Layer: Setting z-index: 99999 on an earlier popover will not raise it above a later popover, order depends strictly on activation order. display: none Breaks Exit Transitions: Closing a Top Layer element snaps it out of the layer unless transition-behavior: allow-discrete is declared.
The HTML inert attribute instructs the engine to suppress pointer events, keyboard focus, text selection, find-in-page, and accessibility tree nodes for an entire subtree.
Key Pitfalls: Self-Inert Deadlock: Setting inert on a parent wrapper that also contains the active modal locks the user out of the close button. Forgetting Focus Restoration: Making the currently focused button inert drops focus back to <body>; restore focus to the trigger when closing.