A hidden attribute on a <main> tag hides the main element.
Although the main element is not visible, it maintains its position on the page.
A hidden attribute on a <main> tag.
The main element is not visible.
A hidden main element:
<p>A hidden main element:</p>
<main hidden>
<b>Impressionism</b> is a 19th-century art movement
characterized by relatively small brush strokes,
emphasis on accurate depiction of light, ordinary
subject matter, and unusual visual angles.
Impressionism originated with a group of
Paris-based artists whose independent exhibitions
brought them to prominence in the 1870s and 1880s.
</main>
The hidden attribute hides the <main> element.
You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid.
A hidden <main> element is not visible, but it maintains its position on the page.
Removing the hidden attribute makes it re-appear.
<main hidden>
<main hidden="hidden">
Value | Description |
---|---|
hidden | Use 'hidden' or hidden='hidden'. Both are valid. |
Clicking the button toggles A hidden attribute on the <main> tag.
<main id="mymain">
<b>Impressionism</b> is a 19th-century art movement
characterized by relatively small brush strokes,
emphasis on accurate depiction of light, ordinary
subject matter, and unusual visual angles.
Impressionism originated with a group of
Paris-based artists whose independent exhibitions
brought them to prominence in the 1870s and 1880s.
</main>
<br />
<button onclick="toggle(this)">Hide main</button>
<script>
let toggle = button => {
let element = document.getElementById("mymain");
let hidden = element.getAttribute("hidden");
if (hidden) {
element.removeAttribute("hidden");
button.innerText = "Hide main";
} else {
element.setAttribute("hidden", "hidden");
button.innerText = "Show main";
}
}
</script>
Initially, the <main> element has no hidden attribute and can be seen.
Clicking the button calls JavaScript that toggles the hidden attribute.
When the hidden attribute is present, the <main> element will not be visible.
Here is when hidden support started for each browser:
Chrome
|
6.0 | Sep 2010 |
Firefox
|
4.0 | Mar 2011 |
IE/Edge
|
12.0 | Jul 2015 |
Opera
|
11.1 | Mar 2011 |
Safari
|
5.0 | Jun 2010 |
Back to <main>