hidden
Control element visibility and interactivity. Covers hidden, hidden='until-found', and inert — three levels of removing content from the user experience.
Overview
Three native attributes control whether and how users can see and interact with content. They represent three levels of removal from the user experience:
| Attribute | Visible | Interactive | In Accessibility Tree | Find-in-Page |
|---|---|---|---|---|
hidden | No | No | No | No |
hidden="until-found" | No | No | Yes | Yes (reveals on find) |
inert | Yes | No | No | Yes |
| (none) | Yes | Yes | Yes | Yes |
hidden
The hidden attribute removes an element from rendering entirely. It behaves like display: none but is semantic — it declares that the content is not relevant to the current state of the page.
When to Use hidden
- Conditional UI: Content that should appear only in certain states (logged in, feature enabled, etc.)
- Template content: Fragments cloned by JavaScript
- Deferred content: Content loaded after user interaction
hidden="until-found"
A newer value that collapses content visually but allows the browser to reveal it during find-in-page (Ctrl+F) searches. When a match is found inside, the browser fires a beforematch event and removes the hidden attribute.
This is useful for long FAQ pages, accordions, or collapsed sections where users should be able to search for content without expanding every section manually.
inert
The inert attribute keeps content visible but makes it completely non-interactive. Inert elements cannot be clicked, focused, selected, or found by assistive technology. The browser applies a visual dimming effect.
The form above is inert — try clicking or tabbing into it.
When to Use inert
- Behind modals: Prevent interaction with page content while a dialog is open. Note:
<dialog>withshowModal()applies inert automatically. - Loading states: Disable a form section while a submission is in progress
- Preview mode: Show content that shouldn't be interacted with yet
- Step-by-step flows: Disable future steps until the current step is complete
JavaScript API
Both hidden and inert are reflected as boolean properties on the element.
Comparison with CSS
| Approach | Visual | Accessibility | Semantic |
|---|---|---|---|
hidden | Removed from layout | Removed from tree | Yes — declares irrelevance |
display: none | Removed from layout | Removed from tree | No — only visual |
visibility: hidden | Invisible but occupies space | Removed from tree | No |
.visually-hidden | Invisible, no space | Still in tree | No — screen reader only |
inert | Visible (dimmed) | Removed from tree | Yes — declares non-interactivity |
Prefer hidden over display: none when the content is semantically irrelevant. Prefer inert when content should remain visible but non-interactive.
See Also
<dialog>— automatically manages inert on the rest of the page<details>— native collapsible contentdata-show-when— conditional visibility based on form field values- class:
.visually-hidden— hide visually but keep accessible