Next.js and React · Troubleshooting walkthrough
A modal fails 'aria-hidden elements do not contain focusable elements'
Short answer
Chrome's Blocked aria-hidden warning and the axe and Lighthouse check aria-hidden elements do not contain focusable elements both mean focusable content sits under aria-hidden="true". Around a modal it is the page behind the dialog, or a closing dialog that still holds focus. Make the background inert instead, or open a native dialog with showModal(), and move focus before hiding anything.
Two different tools complain about the same underlying mistake. Chrome logs Blocked aria-hidden on an element because its descendant retained focus, and axe and Lighthouse fail the rule aria-hidden elements do not contain focusable elements. In both, content marked aria-hidden="true" is either holding the keyboard focus or can still receive it. For screen reader users that means focus has landed on something the accessibility tree says does not exist.
Modals are the usual place it happens, because opening one tempts you to hide the page behind it. The fix is to use the attribute made for that job, inert, and to order focus changes carefully. Work through the three situations below.
The text you see
Blocked aria-hidden on an element because its descendant retained focus. The focus must not be hidden from assistive technology users.Avoid using aria-hidden on a focused element or its ancestor. Consider using the inert attribute instead, which will also prevent focus.ARIA hidden element must not be focusable or contain focusable elementsaria-hidden elements do not contain focusable elements
Stage 5
Prefer the native dialog
A <dialog> opened with showModal() makes the rest of the document inert by itself, traps focus inside, and returns focus when closed. There is no aria-hidden bookkeeping to get wrong. If a component library hides things for you, the order of focus and hiding lives in that library, so update it or report the two console lines Chrome prints.
Stage 6
Check the fix
- With the modal open, press Tab repeatedly: focus never leaves the dialog.
- Run the first snippet again: the list is empty.
- Close with the keyboard: the console shows no warning and
document.activeElementis the opener. - Add an automated accessibility test that opens and closes each modal, not just the page at rest.
If you only keep one thing
- aria-hidden hides from screen readers but not from the keyboard.
- Use inert for the background, and render the modal outside it.
- Move focus before hiding anything.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.