Inert Background and aria-modal
Make the rest of the page unreachable while open.
Inert Background and aria-modal is a free Web Accessibility Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Web Accessibility Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Page Behind Still Exists
Even with focus trapped, the content behind your modal is still in the DOM. A screen reader can wander into it unless you stop it.
Enter the inert Attribute
The inert attribute makes an element and all its children unfocusable, unclickable, and skipped by assistive tech in one move.
<main inert>...page content...</main>Make the Background Inert
When the modal opens, add inert to everything outside it. Now the page behind truly cannot be reached by anyone.
pageContent.inert = true;Remove inert on Close
When the modal closes, drop the inert attribute so the page becomes interactive again. Forgetting this leaves the page frozen.
pageContent.inert = false;Native dialog Does This For You
A native dialog opened with showModal() makes the rest of the page inert automatically, so you get this protection without extra code.
What aria-modal Declares
Adding aria-modal set to true tells assistive tech that content outside this dialog is not available while it is open.
<div role="dialog" aria-modal="true">...</div>aria-modal Is a Promise, Not a Wall
Watch out: aria-modal only informs the screen reader. It does not actually block focus or clicks, so you still need inert.
Use Both Together
The robust pattern pairs inert on the background with aria-modal on the dialog. One enforces, the other announces the boundary.
<div role="dialog" aria-modal="true">
<!-- background gets inert -->The Old aria-hidden Trick
Before inert had wide support, devs put aria-hidden on the background. It hid content from readers but did not stop keyboard focus.
Never Hide the Dialog Itself
One classic bug: applying aria-hidden so broadly it covers the dialog too. Make sure your modal stays out of the hidden region.
Verify in the Tree
Open the browser accessibility tree with the modal up. Confirm the page behind has vanished from it and only the dialog remains. ✅
Quick Check
You add aria-modal=true but skip inert. What problem remains?
Recap: Seal Off the Background
You learned to make the page behind inert and declare aria-modal, so the modal is truly the only thing users can reach. 🎯
Frequently asked questions
Is the “Inert Background and aria-modal” lesson free?
Yes — the full text of “Inert Background and aria-modal” is free to read here on the web, and the Web Accessibility Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Web Accessibility Academy course, upgrade to CoddyKit PRO.
What will I learn in “Inert Background and aria-modal”?
Make the rest of the page unreachable while open. You practise Web Accessibility Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Web Accessibility Academy?
No prior experience is required. Web Accessibility Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Inert Background and aria-modal” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Web Accessibility Academy lesson?
Yes. Every Web Accessibility Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Dialog Roles and the Native dialog Element
- Trapping Focus Inside the Modal
- Escape to Close and Restore Focus
- Inert Background and aria-modal