The inert Attribute and Modal Focus Containment
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.
Manual aria-hidden + tabindex=-1 vs Native inert Attribute
shell.setAttribute('aria-hidden', 'true');
shell.querySelectorAll('a,button,input').forEach((el) => {
el.dataset.prevTab = el.getAttribute('tabindex') ?? '';
el.tabIndex = -1;
});Misses dynamically inserted buttons and fails to block pointer clicks.
shell.inert = isDrawerOpen;
// Single boolean blocks focus, clicks, selection, find-in-page, and A11y treeEngine-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.
- Hit-Test Suppression: The engine ignores pointer events inside an
inertsubtree, as ifpointer-events: nonewere set natively. - Focus & A11y Pruning: Tab navigation skips every descendant, and the accessibility tree drops the entire inert subtree.
- Automatic Modal Inertness:
<dialog>.showModal()applies engine-level inertness to everything outside the active Top Layer dialog.
<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
inertPolyfill): Required MutationObservers to patchtabindexacross subtrees. - 2023 (Baseline
inertAttribute): Native support landed across Chrome, Firefox, and Safari.
Production Pitfalls
- Self-Inert Deadlock: Setting
inerton 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
inertdrops focus back to<body>; restore focus to the trigger when closing.
- When not to use
inert: Never useinertto disable a single<button>, usedisabledoraria-disabledso the control remains discoverable.
Connections & Logical Next Steps
Accessibility-tree queries respect aria-hidden and inert subtrees when filtering exposed controls.
Inert subtrees suppress pointer and keyboard event dispatch during hit-testing before propagation.
Opening a <dialog> via showModal() automatically marks all non-Top-Layer DOM subtrees inert.
showModal() marks background subtrees inert automatically, whereas custom overlays require the inert attribute explicitly.