References

Beginner-friendly references for web development, with live, editable examples.

The HTML inert attribute

Global attribute Works on every element All modern browsers Updated
Quick answer

The HTML inert attribute makes an element and everything inside it inert — it cannot be clicked, focused, selected or reached by assistive technology. It is a boolean global attribute, perfect for disabling the background content behind a modal dialog.

Overview

When you add inert to an element, the browser removes the whole subtree from the tab order and the accessibility tree and ignores pointer interaction. It is the standards-based replacement for fragile combinations of aria-hidden, tabindex="-1" and pointer-events: none.

The classic use is "trapping" focus: when a modal opens, mark the rest of the page inert so keyboard and screen-reader users cannot wander into the hidden content behind it. The native <dialog> element's showModal() does this automatically.

Values

Value
inert (boolean)

Example

Live example
<div inert style="opacity:.5;">
  <button>You cannot focus or click me</button>
</div>

Best practices

  • Use autofocus sparingly — auto-focusing can disorient screen-reader users.
  • Use inert to disable everything behind a modal so focus cannot reach it.
  • Only one element per page should have autofocus.
  • Pair these with deliberate focus management for accessible dialogs and overlays.

Accessibility

inert is a major accessibility win: it cleanly removes a region from the accessibility tree and the tab order at once, which is exactly what focus management around dialogs needs. Toggle it on the page's background while a modal is open so assistive-tech users cannot escape into hidden content, and remove it when the modal closes.

Frequently asked questions

What does the inert attribute do?
Makes an element and its subtree inert: non-interactive, unfocusable, and ignored by assistive tech.
Should I use autofocus?
Sparingly. It can move focus unexpectedly for keyboard and screen-reader users; reserve it for pages whose sole purpose is that input.
Is inert a global attribute?
Yes — it is a global attribute, so it can be set on any HTML element (it is a global attribute).