A hidden attribute on a <nav> tag hides the nav element.
Although the nav is not visible, it maintains its position on the page.
A hidden attribute on a <nav> tag.
The nav element is not visible.
A hidden nav element:
<p>A hidden nav element:</p>
<nav hidden>
<a href="javascript:alert('Going to Introduction')">Introduction</a> <br />
<a href="javascript:alert('Going to What Is HTML')">What is HTML</a> <br />
<a href="javascript:alert('Going to HTML Syntax')">HTML Syntax</a> <br />
<a href="javascript:alert('Going to HTML Elements')">HTML Elements</a>
</nav>
The hidden attribute hides the <nav> element.
You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid.
A hidden <nav> element is not visible, but it maintains its position on the page.
Removing the hidden attribute makes it re-appear.
<nav hidden>
<nav hidden="hidden">
Value | Description |
---|---|
hidden | Use 'hidden' or hidden='hidden'. Both are valid. |
Clicking the button toggles A hidden attribute on the <nav> element.
<nav id="mynav">
<a href="javascript:alert('Going to Introduction')">Introduction</a> <br />
<a href="javascript:alert('Going to What Is HTML')">What is HTML</a> <br />
<a href="javascript:alert('Going to HTML Syntax')">HTML Syntax</a> <br />
<a href="javascript:alert('Going to HTML Elements')">HTML Elements</a>
</nav>
<br />
<button onclick="toggle(this);">Hide nav</button>
<script>
let toggle = button => {
let element = document.getElementById("mynav");
let hidden = element.getAttribute("hidden");
if (hidden) {
element.removeAttribute("hidden");
button.innerText = "Hide nav";
} else {
element.setAttribute("hidden", "hidden");
button.innerText = "Show nav";
}
}
</script>
Initially, the <nav> elements has no hidden attribute and can be seen.
Clicking the button calls JavaScript that toggles the hidden attribute.
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.0 | Dec 2010 |
Safari
|
5.0 | Jun 2010 |
Back to <nav>