totn HTML

HTML: <tbody> tag

This HTML tutorial explains how to use the HTML element called the <tbody> tag with syntax and examples.

Description

The HTML <tbody> tag defines a set of rows that make up the body of an HTML table. This tag is also commonly referred to as the <tbody> element.

Syntax

In HTML, the syntax for the <tbody> tag is: (example of a table with two rows in the <tbody> tag)

<body>
<table>
  <thead>
    <tr>
      <th>Item</th>
      <th>Amount</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Bananas</td>
      <td>$12</td>
    </tr>
    <tr>
      <td>Pears</td>
      <td>$7</td>
    </tr>
  </tbody>
</table>
</body>

Sample Output


Attributes

In addition to the Global Attributes, the following is a list of attributes that are specific to the <tbody> tag:

Attribute Description HTML Compatibility
align Horizontal alignment of text in each cell within the table body. It can be one of the following values: left, center, right, justify, char Deprecated in HTML 4.01, Obsolete in HTML5, use CSS
bgcolor Background color of each cell within the table body Deprecated in HTML 4.01, Obsolete in HTML5, use CSS
char Set the character to align the cells in a column Deprecated in HTML 4.01, Obsolete in HTML5
charoff Number of characters to offset column data from the alignment characters (in char attribute) Deprecated in HTML 4.01, Obsolete in HTML5
valign Vertical alignment of text of each cell within the table body. It can be one of the following values: baseline, bottom, middle, top Deprecated in HTML 4.01, Obsolete in HTML5, use CSS

Note

  • The HTML <tbody> element is found in an HTML table within the <body> tag.
  • The <tbody> tag must appear after the <caption>, <colgroup> and <thead> tags in a table but before the <tfoot> tag.
  • The <tbody> tag can contain zero or more <tr> tags.

Browser Compatibility

The <tbody> tag is compatible with the following browsers:

  • Chrome
  • Android
  • Firefox (Gecko)
  • Firefox Mobile (Gecko)
  • Internet Explorer (IE)
  • Edge Mobile
  • Opera
  • Opera Mobile
  • Safari (WebKit)
  • Safari Mobile

Example

We will discuss the <tbody> tag below, exploring examples of how to use the <tbody> tag in HTML5, HTML 4.01 Transitional, XHTML 1.0 Transitional, XHTML 1.0 Strict, and XHTML 1.1.