HTML tr tag

Example

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

<table>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>Rs.100</td>
</tr>
<tr>
<td>February</td>
<td>Rs.80</td>
</tr>
</table>

Definition and Usage

The <tr> tag defines a row in an HTML table.

<tr> element contains one or more <th> or <td> elements.

Browser Support

Element
<tr> Yes Yes Yes Yes Yes

Global Attributes

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

Event Attributes

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

More Examples

Example

How to align content inside <tr> (with CSS):

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

Example

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

<table>
<tr style="background-color:#FF0000">
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>Rs.100</td>
</tr>
 </table>

Example

How to vertical align content inside <tr> (with 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>Rs.100</td>
</tr>
</table>

Example

How to create table headers:

<table>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
</tr>
<tr>
<td>SamS</td>
<td>sam.s@lovelife.com</td>
<td>123-45-678</td>
</tr>
</table>

Example

How to create a table with a caption:

<table>
<caption>Monthly savings</caption>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>Rs.100</td>
</tr>
<tr>
<td>February</td>
<td>Rs.80</td>
</tr>
</table>

Example

How to define table cells that span more than one row or one column:

<table>
<tr>
<th>Name</th>
<th>Email</th>
<th colspan="2">Phone</th>
</tr>
<tr>
<td>SamS</td>
<td>sam.s@lovelife.com</td>
<td>123-45-678</td>
<td>212-00-546</td>
</tr>
</table>

Default CSS Settings

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

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

Comments