Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

tbody — a group of table body rows

The `tbody` element groups rows that form the main data body of a table. It contains `tr` elements rather than cells directly, and lets one table contain several distinct groups of data rows.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

<table><tbody><tr><td>Data</td></tr></tbody></table>

tbody represents a group of data rows in its parent table. In contrast, thead groups header rows, while tfoot groups summary rows. One table can contain several tbody elements.

Place tbody directly inside table, after any caption, colgroup, and thead, and before tfoot. Do not mix these groups with tr elements that are direct children of the same table. A tbody may be empty; its content consists of tr and script-supporting elements. Put td and th cells inside tr.

The element supports global attributes. In JavaScript it uses the HTMLTableSectionElement interface; its rows property exposes its rows. Prefer explicit opening and closing tags: omitting them in text/html is permitted only under specific conditions.

Examples

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Table body example</title>
</head>
<body>
  <table>
    <caption>Scores</caption>
    <thead>
      <tr><th scope="col">Name</th><th scope="col">Score</th></tr>
    </thead>
    <tbody id="scores">
      <tr><th scope="row">Ada</th><td>8</td></tr>
      <tr><th scope="row">Lin</th><td>9</td></tr>
    </tbody>
  </table>
  <pre id="result"></pre>
  <script>
    const scores = document.getElementById('scores');
    document.getElementById('result').textContent =
      `tbody rows: ${scores.rows.length}`;
  </script>
</body>
</html>

Result

tbody rows: 2

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources