The Browser Top Layer vs CSS Stacking Context
Stacking contexts trap z-index inside ancestors, whereas the Top Layer renders above every stacking context.
Structured Comparison Matrix
| Dimension | The Browser Top Layer | CSS Stacking Context |
|---|---|---|
| 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. | Hierarchical tree isolating Z-axis paint order. A high z-index remains trapped inside its parent stacking context. |
| Maturity & Domain | Baseline · Widely · DOM & Events Chrome 114+ · Firefox 125+ · Safari 17+ | Baseline · Widely · Rendering Pipeline Chrome 1+ · Firefox 1+ · Safari 1+ |
| Prerequisites | Foundational primitive | |
| 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 z-index: Use the Native <dialog> Element or Popover API in the Browser Top Layer for modals and tooltips instead of managing global z-index scales. |
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.
opacity < 1, transform, filter, or isolation: isolate create an atomic Z-axis boundary.
Key Pitfalls: Modal stuck under a header: An intermediate ancestor receives transform: translateY(0) for an animation, trapping the modal's z-index: 9999 under the sticky header. z-index: 999999 escalation: Adding extra nines to z-index is the CSS equivalent of shouting louder in a soundproof room, it never crosses a parent stacking