HTML <div> hidden Attribute

The hidden attribute on a <div> tag hides that div element. Althought the div is not visible, its position on the page is maintained.

Example

#

A hidden attribute on a <div> element.
The division is not visible.

An invisible div element:

<p>An invisible div element:</p>

<div hidden>
  <b>Registration Successful!</b>
  <p>We will email your entry passes to the Louvre Museum in Paris.</p>
</div>

Using hidden

The hidden attribute hides the <div> element.

You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid.

A hidden <div> element is not visible, but it maintains its position on the page.

Removing the hidden attribute redisplays the <div> element.


Syntax

<div hidden>
or
<div hidden="hidden">

Values

#

Value Description
hidden Use value 'hidden' or no value at all.

More Examples

Clicking the button toggles the hidden attribute on the <div> element.

Registration Successful!

We will email your entry passes to the Louvre Museum in Paris.


<div id="mydiv"
     style="background-color:aliceblue;padding:25px;">
  <b>Registration Successful!</b>
  <p>We will email your entry passes to the Louvre Museum in Paris.</p>
</div>

<br />
<button onclick="toggle(this)">Hide div</button>

<script>
  let toggle = button => {
    let element = document.getElementById("mydiv");
    let hidden = element.getAttribute("hidden");

    if (hidden) {
       element.removeAttribute("hidden");
       button.innerText = "Hide div";
    } else {
       element.setAttribute("hidden", "hidden");
       button.innerText = "Show div";
    }
  }
</script>

Code explanation

Initially the <div> element has no hidden attribute and is visible.

Clicking the button calls JavaScript which toggles the hidden attribute on the <div>.


Browser support

Here is when hidden support started for each browser:

Chrome
6.0 Sep 2010
Firefox
4.0 Mar 2011
IE/Edge
9.0 Mar 2011
Opera
11.1 Mar 2011
Safari
5.0 Jun 2010

You may also like

 Back to <div>
Guides