DOM & EventsBaseline · Widely

The inert Attribute and Modal Focus Containment

Mental Model

Adding inert to a DOM container disables clicks, keyboard focus, text selection, find-in-page, and screen-reader visibility for every descendant in one attribute. It replaces brittle aria-hidden="true" plus tabindex="-1" loops and powers Native Dialog modal containment in the Browser Top Layer.

Interactive Simulator

Manual aria-hidden + tabindex=-1 vs Native inert Attribute

Lines of Code
Before
5
After
2
Reflows / Browser Cost
Before
DOM query + mutation
After
0 child mutations
BeforeManual aria-hidden + tabindex Loops
shell.setAttribute('aria-hidden', 'true');
shell.querySelectorAll('a,button,input').forEach((el) => {
  el.dataset.prevTab = el.getAttribute('tabindex') ?? '';
  el.tabIndex = -1;
});
Lines: 5Reflows: DOM query + mutationDependencies: Leaks new dynamic nodes

Misses dynamically inserted buttons and fails to block pointer clicks.

After (Native)Native HTML inert Attribute
shell.inert = isDrawerOpen;
// Single boolean blocks focus, clicks, selection, find-in-page, and A11y tree
Lines: 2Reflows: 0 child mutationsDependencies: 0 JS focus traps

Engine-enforced across all existing and future descendants.

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 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>

Problem Genealogy

  • 2014 (aria-hidden + tabindex="-1" Hacks): Developers wrote fragile recursive DOM walkers that broke on dynamically injected buttons.
  • 2017 (WICG inert Polyfill): Required MutationObservers to patch tabindex across subtrees.
  • 2023 (Baseline inert Attribute): Native support landed across Chrome, Firefox, and Safari.

Production Pitfalls

Production Pitfall
  • 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.
When Not to Use
  • When not to use inert: Never use inert to disable a single <button>, use disabled or aria-disabled so the control remains discoverable.

Connections & Logical Next Steps

Mechanical Comparisons