HTML <table> hidden Attribute

The hidden attribute on a <table> tag hides the table. Althought the table is not visible, its position on the page is maintained.

Example

#

A hidden attribute on a <table> tag.
The table is not visible.

A hidden table:

<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>

Using hidden

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.


Syntax

<table hidden>
or
<table hidden="hidden">

Values

#

Value Description
hidden Use 'hidden' or hidden='hidden'. Both are valid.

More Examples

Clicking the button toggles the 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>

Code explanation

Initially, the <table> is visible.

Clicking the button calls JavaScript that toggles the hidden attribute.

With the hidden attribute the table is invisible.


Browser support

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

You may also like

 Back to <table>
Guides