A hidden attribute on a <ul> tag hides the unordered list.
Although the list is not visible, its position on the page is maintained.
A hidden attribute on a <ul> tag.
The unordered list is not visible.
A hidden unordered list:
<p>A hidden unordered list:</p>
<ul hidden>
<li>Vincent Van Gogh</li>
<li>Paul Cézanne</li>
<li>Claude Monet</li>
</ul>
The hidden attribute hides the <ul> element.
You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid.
A hidden <ul> element is not visible, but it maintains its position on the page.
Removing the hidden attribute makes it re-appear.
<ul hidden>
<ul hidden="hidden">
Value | Description |
---|---|
hidden | Use 'hidden' or hidden='hidden'. Both are valid. |
Clicking the button toggles A hidden attribute on the <ul> element.
<ul id="myul">
<li>Vincent Van Gogh</li>
<li>Paul Cézanne</li>
<li>Claude Monet</li>
</ul>
<br />
<button onclick="toggle(this);">Hide list</button>
<script>
let toggle = button => {
let element = document.getElementById("myul");
let hidden = element.getAttribute("hidden");
if (hidden) {
element.removeAttribute("hidden");
button.innerText = "Hide list";
} else {
element.setAttribute("hidden", "hidden");
button.innerText = "Show list";
}
}
</script>
Initially, the <ul> is visible.
Clicking the button calls JavaScript that toggles the hidden attribute.
With the hidden attribute the unordered list is invisible.
Here is when hidden support started for each browser:
Chrome
|
1.0 | Sep 2008 |
Firefox
|
1.0 | Sep 2002 |
IE/Edge
|
1.0 | Aug 1995 |
Opera
|
1.0 | Jan 2006 |
Safari
|
1.0 | Jan 2003 |