HTML tagTables

<tbody>

The main part of a table: a group of rows with data.

Display
table-row-group
Closing tag
Required
Permitted content
<tr> elements
On this page

Example

#
HTML
<style>
  table { border-collapse: collapse; }
  th, td { border: 1px solid #8886; padding: 4px 10px; text-align: left; }
  tbody th { background: #38bdf833; }
</style>
<table>
  <tbody>
    <tr><th colspan="2" scope="rowgroup">Module 1: basics</th></tr>
    <tr><td>Document structure</td><td>completed</td></tr>
    <tr><td>Headings and paragraphs</td><td>completed</td></tr>
  </tbody>
  <tbody>
    <tr><th colspan="2" scope="rowgroup">Module 2: lists and tables</th></tr>
    <tr><td>Lists</td><td>in progress</td></tr>
    <tr><td>Tables</td><td>locked</td></tr>
  </tbody>
</table>
Preview

Definition and usage

#

The <tbody> element wraps the rows with the table’s actual data. It comes after <thead> (if there is one) and before <tfoot>.

A curiosity that often surprises people: if you write <tr> rows directly inside <table>, the browser adds a <tbody> around them itself while building the DOM tree. That’s why the CSS selector table > tr usually matches nothing, while table > tbody > tr works.

A table can have several <tbody> elements. It’s a handy way to split a long list of rows into groups, for example the lessons in each module of a course, with a separate header for each group.

Syntax

#
Syntax
<tbody>
  <tr>…</tr>
</tbody>

Attributes

#

This element has no attributes of its own. It supports the global attributes, such as class, id and hidden.

Default CSS

#

Most browsers display this element with these default styles:

CSS
tbody {
  display: table-row-group;
  vertical-align: middle;
}

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Write <tbody> explicitly. The code is easier to read, and what you see in the editor matches the DOM tree in the browser’s developer tools.
  • You can make “zebra” stripes with the tbody tr:nth-child(even) selector, without adding classes to every row.

Related entries

#

Practise it in lessons

#

Spotted a mistake or missing an example? Write to us.