# The Browser Top Layer vs The inert Attribute and Modal Focus Containment

- **Canonical URL:** https://frontend.rocks/vs/browser-top-layer-vs-inert-attribute-focus/
- **Relation:** Contrasts With
- **Last Verified:** 2026-11-15
- **Verdict:** showModal() marks background subtrees inert automatically, whereas custom overlays require the inert attribute explicitly.

## Comparison Matrix

| Dimension | The Browser Top Layer | The inert Attribute and Modal Focus Containment |
| :--- | :--- | :--- |
| **Maturity** | Baseline · Widely | Baseline · Widely |
| **Domain** | DOM & Events | DOM & Events |
| **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. |
| **Prerequisites** | CSS Stacking Context (Top Layer elements paint in a dedicated layer above the entire document root stacking context.) | DOM Event Propagation (Capture, Target, Bubble) (Inert subtrees suppress pointer and keyboard event dispatch during hit-testing before propagation.); The Browser Top Layer (Opening a <dialog> via showModal() automatically marks all non-Top-Layer DOM subtrees inert.) |
| **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. |

## The Browser Top Layer — Under the Hood
The rendering engine maintains the Top Layer as a document-level LIFO ordered set painted after the entire root stacking context. No matter how many `overflow: hidden` clips or `z-index: 99999` contexts exist inside the DOM tree, promoted elements render cleanly above the whole document.

1. **LIFO Ordered Set**: The document maintains a `top layer` list; each `showModal()` or `showPopover()` appends to the end, painting last-in on top.
2. **Viewport Containing Block**: Top Layer elements escape ancestor `transform` and `clip-path` containing blocks.
3. **`::backdrop` Layer**: Each modal or popover receives its own `::backdrop` pseudo-element painted immediately beneath it.

```css
/* Animating Top Layer entry & exit cleanly */
dialog[open], [popover]:popover-open {
  opacity: 1;
  transform: scale(1);
  transition: opacity 0.2s, transform 0.2s, display 0.2s allow-discrete;
}
@starting-style {
  dialog[open], [popover]:popover-open { opacity: 0; transform: scale(0.96); }
}
```

## The inert Attribute and Modal Focus Containment — Under the Hood
Picture flipping the master circuit breaker on one wing of a museum: every interactive kiosk, light switch, and doorway in that wing stops responding to [DOM Event Propagation](/concepts/dom-event-propagation) and vanishes from the floor map until power returns.

1. **Hit-Test Suppression**: The engine ignores pointer events inside an `inert` subtree, as if `pointer-events: none` were set natively.
2. **Focus & A11y Pruning**: Tab navigation skips every descendant, and the accessibility tree drops the entire inert subtree.
3. **Automatic Modal Inertness**: `<dialog>.showModal()` applies engine-level inertness to everything outside the active Top Layer dialog.

```html
<main inert>
  <button>Unreachable while drawer is open</button>
</main>
<aside id="drawer">
  <button onclick="closeDrawer()">Close Drawer</button>
</aside>
```

## Interactive Labs & Dissections
- [The Browser Top Layer Lab](https://frontend.rocks/concepts/browser-top-layer/#lab) ([Markdown](https://frontend.rocks/concepts/browser-top-layer.md))
- [The inert Attribute and Modal Focus Containment Lab](https://frontend.rocks/concepts/inert-attribute-focus/#lab) ([Markdown](https://frontend.rocks/concepts/inert-attribute-focus.md))

## Related Architecture Autopsies
- [Autopsy #05: The z-index 9999 Modal Trap (and Its Native Exit)](https://frontend.rocks/autopsies/zindex-9999-tooltip-war/) ([Markdown](https://frontend.rocks/autopsies/zindex-9999-tooltip-war.md)): Tooltip or modal remains trapped behind a sticky header despite z-index: 9999 while JS positioning thrashes layout.

## Primary Sources
- https://fullscreen.spec.whatwg.org/#top-layer
- https://developer.chrome.com/blog/what-is-the-top-layer
- https://html.spec.whatwg.org/multipage/interaction.html#the-inert-attribute
- https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inert
