Skip to content

HTML Inert and aria-hidden: Check What Receives Focus

Test Tab navigation and accessibility-tree visibility in three modal setups. See why a hidden background button can still receive focus.

Keyboard beside layered paper dialog cards with an orange outline around one button
Jack Lee
3 Min Read
Share
On This Page

Open a date picker from an appointment page and press Tab a few times. If focus reaches the shop’s opening-hours button behind the picker, the background still accepts keyboard input. Marking the background aria-hidden="true" can hide it from the accessibility tree without stopping that movement.

What each attribute controls

AttributeEffectUse
aria-hidden="true"Excludes content from the accessibility tree. The attribute itself leaves keyboard focus and visibility alone.Hide a decorative icon that duplicates an accessible label. Keep it off focusable elements and their ancestors.
inertRemoves a subtree from normal focus and pointer interaction, and excludes it from the accessibility tree.Temporarily deactivate the background of a custom modal. Apply it to the background container, outside the active modal.

For a native <dialog>, open it with showModal() to make the rest of the document inert while it is displayed as a modal. Test focus on opening and closing even when the browser handles that background state.

What happened in the browser test

I used a local appointment picker with a Close button and a Choose date button. The page behind it had Open appointment and Opening hours buttons. With focus on Close, I read Chrome’s accessibility tree for Opening hours, then pressed Tab five times.

SetupWas Opening hours omitted from the accessibility tree before Tab?Did Tab reach a background button?
aria-hidden="true" on the backgroundYesYes. Focus reached both background buttons.
inert on the backgroundYesNo.
Native modalYesNo.

For each setup, Escape closed the picker and returned focus to Open appointment. The custom cases did that with explicit code. The native case used the browser’s default Escape behavior. These are observations from one Chrome setup. The tree inspection was separate from the keyboard test.

How to check your own modal

  1. Open it with the keyboard. Confirm focus moves to a useful control or heading inside, and that the dialog’s name describes the task. For an icon-only close control, check its computed accessible name.
  2. Try Tab and Shift+Tab. Walk across the first and last controls in both directions. Background actions should stay out of the sequence. In a custom modal, verify wrapping at the endpoints separately. Adding the background attribute alone doesn’t select initial focus or implement wrapping.
  3. Close it and keep going. Test Escape and the close control, and check that focus returns to the opener or a sensible next control. Confirm that the background is usable again. Also inspect which controls are exposed in the accessibility tree. See how that differs from visually hiding text with CSS.

Frequently asked questions

What does aria-hidden do in HTML?

It controls what the browser exposes to assistive technologies. It does not prevent a button from receiving focus. Use it for redundant or decorative content when the equivalent meaning is already available.

Can I place inert on the entire page?

Limit it to the part you need to deactivate. If a custom modal is inside the inert container, its controls become inert too. Keep the active modal and background in separate containers.

Do I need to set inert when I use a native modal?

In the same document, showModal() handles the surrounding page. Check the dialog’s accessible name, initial focus and what happens when it closes.

Share This Article