A hidden attribute on a <table> tag hides the table.
Although the table is not visible, its position on the page is maintained.
A hidden attribute on a <table> tag.
The table is not visible.
A hidden table:
First name | Last name |
---|---|
Denice | Hobermann |
Paulo | Cornell |
Jane | Hollander |
<p>A hidden table:</p>
<table hidden>
<tr>
<th>First name</th>
<th>Last name</th>
</tr>
<tr>
<td>Denice</td>
<td>Hobermann</td>
</tr>
<tr>
<td>Paulo</td>
<td>Cornell</td>
</tr>
<tr>
<td>Jane</td>
<td>Hollander</td>
</tr>
</table>
The hidden attribute hides the <table> element.
You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid.
A hidden <table> element is not visible, but it maintains its position on the page.
Removing the hidden attribute makes it re-appear.
<table hidden>
<table hidden="hidden">
Value | Description |
---|---|
hidden | Use 'hidden' or hidden='hidden'. Both are valid. |
Clicking the button toggles A hidden attribute on the <table> element.
First name | Last name |
---|---|
Denice | Hobermann |
Paulo | Cornell |
Jane | Hollander |
<style>
table.tb { border-collapse: collapse; width:300px; }
.tb th, .tb td { padding: 5px; border: solid 1px #777; }
.tb th { background-color: lightblue;}
</style>
<table class="tb" id="mytable">
<tr>
<th>First name</th>
<th>Last name</th>
</tr>
<tr>
<td>Denice</td>
<td>Hobermann</td>
</tr>
<tr>
<td>Paulo</td>
<td>Cornell</td>
</tr>
<tr>
<td>Jane</td>
<td>Hollander</td>
</tr>
</table>
<br />
<button onclick="toggle(this);">Hide table</button>
<script>
let toggle = button => {
let element = document.getElementById("mytable");
let hidden = element.getAttribute("hidden");
if (hidden) {
element.removeAttribute("hidden");
button.innerText = "Hide table";
} else {
element.setAttribute("hidden", "hidden");
button.innerText = "Show table";
}
}
</script>
Initially, the <table> is visible.
Clicking the button calls JavaScript that toggles the hidden attribute.
With the hidden attribute the table 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 |