A useful interface does not need to be complicated. Start with native HTML, then add JavaScript only when you need it.
What You Need to Know
An inert section cannot normally receive focus or be interacted with. This is useful when part of the interface is temporarily unavailable, but inert is not the same thing as hiding it visually.
In this example: make background controls inert during overlay interaction.
Try the Example
Take a look at the example. We’ll explain the important lines right below it.
<section id="background" inert>
<button type="button">Unavailable action</button>
<p>Background actions are temporarily disabled.</p>
</section>
<button type="button">Current action</button>
Let’s Read the Code
- <section>: A section groups content with a shared topic.
- <button>: The button offers an action; its type or command determines what happens.
- id: An id uniquely identifies an element on this page.
- inert: Inert prevents interaction and normal focus on a region.
Read the named elements and attributes together. They explain how the browser connects this feature to the rest of the page.
What Happens in the Browser?
When this example includes JavaScript, it supplies behavior that ordinary HTML does not automatically provide. Always think about a fallback.
Start with native behavior. Details, dialog, and popover each solve a different interface problem. Choose the simplest control that actually matches what a visitor wants to do, then test focus and dismissal as well as appearance.
Your Turn
Run this on a local development server if it loads modules or resources. Change the visible text or trigger and check what still works with scripts disabled.
Common Beginner Mistakes
- Assuming new HTML syntax works in every browser without testing.
- HTML supplies structure; JavaScript is necessary for the scripted behavior in this example. Check keyboard access and focus movement too.
Key Takeaways
- An inert section cannot normally receive focus or be interacted with.
- <section>: A section groups content with a shared topic.
- Test the behavior you expect rather than trusting how the snippet looks in your editor.