A hidden attribute on a <div> tag hides the div.
Although the div is not visible, its position on the page is maintained.
A hidden attribute on a <div> element.
The division is not visible.
An invisible div element:
We will email your entry passes to the Louvre Museum in Paris.
<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>
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.
<div hidden>
<div hidden="hidden">
Value | Description |
---|---|
hidden | Use value 'hidden' or no value at all. |
Clicking the button toggles A hidden attribute on the <div> element.
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>
Initially the <div> element has no hidden attribute and is visible.
Clicking the button calls JavaScript which toggles A hidden attribute on the <div>.
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 |
Back to <div>