HTML <tr> tag

Definition and Usage

<tr> tags define rows in HTML tables.

<tr> Element contains one or more <th> or <td> Element.

See also:

HTML Tutorial:HTML Table

HTML DOM Reference Manual:TableRow Object

CSS Tutorial:Set table styles

Example

Example 1

A simple three-row HTML table; one header row and two data rows:

<table>
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>¥3400</td>
  </tr>
  <tr>
    <td>February</td>
    <td>¥4500</td>
  </tr>
</table>

Try It Yourself

Example 2

How to align: <tr> Content within (using CSS):

<table style="width:100%">
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr style="text-align:right">
    <td>January</td>
    <td>¥3400</td>
  </tr>
</table>

Try It Yourself

Example 3

How to add a background color to a table row (using CSS):

<table>
  <tr style="background-color:#FF0000">
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>¥3400</td>
  </tr>
 </table>

Try It Yourself

Example 4

How to vertically align: <tr> Content within (using CSS):

<table style="height:200px">
  <tr  style="vertical-align:top">
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr style="vertical-align:bottom">
    <td>January</td>
    <td>¥3400</td>
  </tr>
</table>

Try It Yourself

Example 5

How to create a table header:

<table>
  <tr>
    <th>Name</th>
    <th>Email</th>
    <th>Phone</th>
  </tr>
  <tr>
    <td>Bill Gates</td>
    <td>bill.gates@example.com</td>
    <td>138-1234-5678</td>
  </tr>
</table>

Try It Yourself

Example 6

How to create a table with a header:

<table>
  <caption>Monthly savings</caption>
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>¥3400</td>
  </tr>
  <tr>
    <td>February</td>
    <td>¥4500</td>
  </tr>
</table>

Try It Yourself

Example 7

How to define a table cell spanning multiple rows or columns:

<table>
  <tr>
    <th>Name</th>
    <th>Email</th>
    <th colspan="2">Phone</th>
  </tr>
  <tr>
    <td>Bill Gates</td>
    <td>bill.gates@example.com</td>
    <td>138-1234-5678</td>
    <td>186-2345-6789</td>
  </tr>
</table>

Try It Yourself

Global Attributes

<tr> The tag also supports Global Attributes in HTML.

event attributes

<tr> The tag also supports Event Attributes in HTML.

Default CSS Settings

Most browsers will display the following default values <tr> Element:

tr {
  display: table-row;
  vertical-align: inherit;
  border-color: inherit;
}

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support