Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
A hidden attribute on a <section> tag hides the section.
Although the section is not visible, its position on the page is maintained.
Example
#
A hidden attribute on a <section> element.
The section is not visible.
A hidden section:
<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>
Using hidden
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.
Syntax
<section hidden>
or
<section hidden="hidden">
Values
#
Value | Description |
---|---|
hidden | Use 'hidden' or hidden='hidden'. Both are valid. |
More Examples
Clicking the button toggles A hidden attribute on the <section> element.
The Night Watch
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>
Code explanation
Initially, the <section> is visible.
Clicking the button calls JavaScript which toggles the hidden attribute.
With the hidden attribute the section is invisible.
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
Last updated on Sep 30, 2023
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
Guides
On this page
- hidden Attribute
- Example
- Using hidden
- Syntax
- Values
- More Examples
- Browser support
- You may also like