HTML <tr> hidden Attribute

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

Example

#

A hidden attribute on a <tr>.
The first table row is not visible.

First name Last name
Paulo Cornell
<style>
  table.tb { width:300px; border-collapse: collapse; }
  .tb th, .tb td { border: solid 1px #777; padding: 5px; }
  .tb thead { background-color:lightblue; }
  .tb tbody { font-style: italic; }
</style>

<table class="tb">
  <thead>
    <tr>
      <th>First name</th>
      <th>Last name</th>
    </tr>
  </thead>

  <tbody>
    <tr hidden>
      <td>Denice</td>
      <td>Hobermann</td>
    </tr>
    <tr>
      <td>Paulo</td>
      <td>Cornell</td>
    </tr>
  </tbody>
</table>

Using hidden

The hidden attribute hides the <tr> element.

You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid.

A hidden <tr> element is not visible, but it maintains its position on the page.

Removing the hidden attribute makes it re-appear.


Syntax

<tr hidden>
or
<tr 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 first <tr> element in the table.

First name Last name
Denice Hobermann
Paulo Cornell


<style>
  table.tb { width:300px; border-collapse: collapse; }
  .tb th, .tb td { border: solid 1px #777; padding: 5px; }
  .tb thead { background-color:lightblue; }
  .tb tbody { font-style: italic; }
</style>

<table class="tb">
  <thead>
    <tr>
      <th>First name</th>
      <th>Last name</th>
    </tr>
  </thead>

  <tbody>
    <tr id="mytr">
      <td>Denice</td>
      <td>Hobermann</td>
    </tr>
    <tr>
      <td>Paulo</td>
      <td>Cornell</td>
    </tr>
  </tbody>
</table>

<br /><br />
<button onclick="toggle(this)">Hide tr</button>

<script>
  let toggle = button => {
    let element = document.getElementById("mytr");
    let hidden = element.getAttribute("hidden");

    if (hidden) {
       element.removeAttribute("hidden");
       button.innerText = "Hide tr";
    } else {
       element.setAttribute("hidden", "hidden");
       button.innerText = "Show tr";
    }
  }
</script>

Code explanation

Initially, the <tr> is visible.

Clicking the button calls JavaScript that toggles the hidden attribute.

With the hidden attribute the table row 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 <tr>
Guides