Description

The HTML element <tr> is used to define a table row, which acts as a container for table cells.

A table row can contain one or more <th> or <td> elements.

  • One or more <th> elements in the case of a header row.
  • One or more <td> elements in the case of a data row.

The below table summarizes its usage.

Usage Details
Placement It can be a child of any of these elements - <table>, <thead>, <tfoot>, <tbody>
Contents It can contain <th> or <td> elements.
Tags Opening tag: required; Closing Tag: optional
If the closing tag is not used, then an empty row is created.
Versions HTML 3.2, 4, 4.01, 5

Syntax

Here is the basic syntax of the <tr> element.

<tr>...</tr>

Examples

Run this on IDE

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Example - HTML Element tr</title>
</head>
<body>
    <table>
        <caption>Products List</caption>
        <thead>
            <tr>
                <th>Product</th>
                <th>Sales</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Bread</td>
                <td>10000</td>
            </tr>
            <tr>
                <td>Butter</td>
                <td>3000</td>
            </tr>
        </tbody>
    </table>
</body>
</html>

Attributes

The following table shows the list of supported and unsupported attributes for the <tr> element.

Attribute Type Details
Element-Specific Attributes The tag <tr> has some element-specific attributes listed in the below table.
Global Attributes Like all other HTML tags, the tag <tr> supports the HTML Global Attributes.
Event Attributes The tag <tr> also supports the HTML Event Attributes.

Here is a list of attributes that are specific to the <tr> element.

Attribute Value Required Description
align left, right, center, justify, char No Obsolete
Specifies the horizontal alignment of each cell content within the table row.
bgcolor color No Obsolete
Sets the background color of each cell of the table row.
char character No Obsolete
Sets the character to which cell contents within a table row should align.
charoff number No Obsolete
Defines the number of characters by which cell contents within a table will be offset from the alignment characters specified by the char attribute.
valign top, middle, bottom, baseline No Obsolete
Specifies the vertical alignment of cell contents within a table row.

Browser Compatibility

The tag <tr> is supported in all modern browsers.

  • Google Chrome 1+
  • Internet Explorer or Edge 2+
  • Firefox 1+
  • Apple Safari 1+
  • Opera 4+

Related Links