hidden
Hides an element: the browser neither displays nor exposes it.
- Applies to
- All HTML elements
Example
#<p>This paragraph is visible.</p>
<p hidden>This paragraph is not visible, although it is in the code.</p>
<button type="button" onclick="this.nextElementSibling.hidden = !this.nextElementSibling.hidden">
Show or hide the hint
</button>
<p hidden>Hint: start with the <h1> tag.</p>Definition and usage
#The boolean hidden attribute means the element is not relevant right now. The browser does not show it, and screen readers skip it. It is as if the element had display: none.
It is most often toggled in JavaScript: element.hidden = true hides, false shows. This is simpler and clearer than adding a hiding class.
Watch out for CSS: if you give the element its own display, for example display: flex, the author rule can win over the browser’s default style and the element becomes visible despite the hidden attribute.
Syntax
#<element hidden>…</element>Values
#hidden
or empty
The element is hidden and unavailable to the user.until-found
The element is hidden, but the browser’s find-in-page can locate and reveal it. A newer value that does not work everywhere yet.
Default CSS
#Most browsers display this element with these default styles:
[hidden] {
display: none;
}Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- If you want to hide something visually but keep it for screen readers, do not use
hidden; use a class such assr-only. - Add
[hidden] { display: none !important; }to your stylesheet so your own styles do not reveal hidden elements.
Related entries
#- inertDisables interaction with an element and its descendants: clicking, focus and screen readers.
- popoverTurns an element into a pop-up opened by a button, without JavaScript.
- <details>A collapsible section: the `<summary>` heading is always visible, and the rest of the content appears on click.
- <dialog>A dialog or modal window: a confirmation, form, or message shown above the rest of the page.
- aria-*ARIA attributes describe elements for screen readers: they give them names, link them to descriptions and report their state.
Spotted a mistake or missing an example? Write to us.