A hidden attribute on a <section> tag hides the section.
Although the section is not visible, its position on the page is maintained.
A hidden attribute on a <section> element.
The section is not visible.
A hidden section:
The Night Watch (Dutch: De Nachtwacht), is a 1642 painting by Rembrandt van Rijn. It is in the collection of the Amsterdam Museum but is prominently displayed in the Rijksmuseum (State Museum) as the best-known painting in its collection. The Night Watch is the most famous Dutch Golden Age painting.
<p>A hidden section:</p>
<section hidden>
<h2>The Night Watch</h2>
<p>The Night Watch (Dutch: De Nachtwacht), is a 1642
painting by Rembrandt van Rijn. It is in the collection
of the Amsterdam Museum but is prominently displayed
in the Rijksmuseum (State Museum) as the best-known
painting in its collection. The Night Watch is
the most famous Dutch Golden Age painting.
</p>
</section>
The hidden attribute hides the <section> element.
You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid.
A hidden <section> element is not visible, but it maintains its position on the page.
Removing the hidden attribute makes it re-appear.
<section hidden>
<section hidden="hidden">
Value | Description |
---|---|
hidden | Use 'hidden' or hidden='hidden'. Both are valid. |
Clicking the button toggles A hidden attribute on the <section> element.
The Night Watch (Dutch: De Nachtwacht), is a 1642 painting by Rembrandt van Rijn. It is in the collection of the Amsterdam Museum but is prominently displayed in the Rijksmuseum (State Museum) as the best-known painting in its collection. The Night Watch is the most famous Dutch Golden Age painting.
<section id="mysection">
<h2>The Night Watch</h2>
<p>The Night Watch (Dutch: De Nachtwacht), is a 1642
painting by Rembrandt van Rijn. It is in the collection
of the Amsterdam Museum but is prominently displayed
in the Rijksmuseum (State Museum) as the best-known
painting in its collection. The Night Watch is
the most famous Dutch Golden Age painting.
</p>
</section>
<br />
<button onclick="toggle(this)">Hide Section</button>
<script>
let toggle = button => {
let element = document.getElementById("mysection");
let hidden = element.getAttribute("hidden");
if (hidden) {
element.removeAttribute("hidden");
button.innerText = "Hide Section";
} else {
element.setAttribute("hidden", "hidden");
button.innerText = "Show Section";
}
}
</script>
Initially, the <section> is visible.
Clicking the button calls JavaScript which toggles the hidden attribute.
With the hidden attribute the section is invisible.
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 |