Course contentsShow
← Web Development
Lesson 1156 of 2,98221. Accessible ComponentsFree lesson

Managing Inert Background Content

Preventing interaction with background content when a modal is open using inert or aria-hidden.

Managing Inert Background Content

What you'll learn: How to prevent users from interacting with background page content when a modal dialog is open.

When you open a modal dialog, you want the user's full attention on that modal—not on the page behind it. Think of it like putting up a "closed" sign on a store: people shouldn't be able to interact with what's inside while the sign is up.

Why This Matters

Without properly managing background content, keyboard users can accidentally tab out of your modal and interact with elements behind it. Screen reader users might navigate to content that's visually hidden but still accessible. This breaks the modal experience and creates confusion.

Two Key Techniques

1. The inert Attribute

The inert attribute removes an entire section from the tab order and screen reader navigation:

<main id="main-content" inert>
  <!-- Background content users shouldn't reach -->
</main>

<div role="dialog" aria-modal="true">
  <!-- Modal content stays interactive -->
</div>

When the modal opens, add inert to your main content container. Remove it when the modal closes.

2. The aria-hidden Attribute

For broader browser support, use aria-hidden="true":

<main id="main-content" aria-hidden="true">
  <!-- Hidden from screen readers -->
</main>

This hides content from assistive technologies but doesn't affect keyboard navigation, so combine it with your focus trap (from the previous lesson).

Implementation Pattern

When opening a modal, apply inert or aria-hidden="true" to all top-level containers except the modal. When closing, remove these attributes and restore focus to the trigger element.

Key Takeaway: Use inert or aria-hidden="true" on background content when a modal is open to prevent keyboard and screen reader users from accidentally interacting with content that's visually obscured.