HTML global attributeGlobal attributes

hidden

Hides an element: the browser neither displays nor exposes it.

Applies to
All HTML elements
On this page

Example

#
HTML
<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 &lt;h1&gt; tag.</p>
Preview

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

#
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:

CSS
[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 as sr-only.
  • Add [hidden] { display: none !important; } to your stylesheet so your own styles do not reveal hidden elements.

Related entries

#

Spotted a mistake or missing an example? Write to us.