A hidden attribute on a <header> tag hides the header.
Although the header is not visible, its position on the page is maintained.
A hidden attribute on a <header>.
The header is not visible.
A hidden header:
<p>A hidden header:</p>
<header hidden>
Header section of a page...
</header>
The hidden attribute hides the <header> element.
You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid.
A hidden <header> is not visible, but maintains its position on the page.
<header hidden>
<header hidden="hidden">
Value | Description |
---|---|
hidden | Use value 'hidden' or no value at all. |
Clicking the button toggles A hidden attribute on the <header> element.
<header id="myheader" style="background:indigo;color:white;padding:15px;">
Company logo goes here...
</header>
<br />
<button onclick="toggle(this)">Hide header</button>
<script>
let toggle = button => {
let element = document.getElementById("myheader");
let hidden = element.getAttribute("hidden");
if (hidden) {
element.removeAttribute("hidden");
button.innerText = "Hide header";
} else {
element.setAttribute("hidden", "hidden");
button.innerText = "Show header";
}
}
</script>
Initially, the <header> has no hidden attribute and can be seen.
Clicking the button calls JavaScript that toggles A hidden attribute on the <header>.
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 |