Dofactory.com
Dofactory.com
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

HTML <tbody> hidden Attribute

A hidden attribute on a <tbody> tag hides the table body.

Although the table body is not visible, its position on the page is maintained.

Example

#

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

First name Last name
<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 hidden>
    <tr>
      <td>Denice</td>
      <td>Hobermann</td>
    </tr>
    <tr>
      <td>Paulo</td>
      <td>Cornell</td>
    </tr>
  </tbody>
</table>

Using hidden

The hidden attribute hides the <tbody> element.

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

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

Removing the hidden attribute makes it re-appear.


Syntax

<tbody hidden>
or
<tbody hidden="hidden">

Values

#

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

More Examples

Clicking the button toggles A hidden attribute on the <tbody> element.

First name Last name
Denice Hobermann
Paulo Cornell

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

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

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

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

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

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

Code explanation

Initially, the <tbody> is visible.

Clicking the button calls JavaScript that toggles the hidden attribute.

With the hidden attribute the table body 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 <tbody>

Last updated on Sep 30, 2023

Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

Guides