HTML Encyclopaedia

The tr tag

This tag is used to define a table row. The tag is a container tag and the tag pair <tr> ... </tr> should contain a sequence of <td> and <th> containers. The <tr> tag can only meaningfully appear within a <table> ... </table> container.

In practice the presence of a <tr> tag implies closure of the previous table row so the </tr> is not necessary.

HTML 3.2 defines two attributes for the <tr> tag. These both control the default alignment of cell content on the table row. The default can always be over-ridden by use of <td> tag attributes. The attributes are

  1. align

    This can take one of the values left, center and right. It controls the horizontal alignment of the content of all the cells on a row.

  2. valign

    This can take one of the values top, middle and bottom. It controls the vertical alignment of the content of all the cells on a row.

  3. bgcolor

    This tag is not included in the HTML 3.2 standard. It can be used to set the background colour for every cell in a row.

Here are some examples.

First here's a three row table showing the three styles of horizontal alignment with default vertical alignment. The non HTML 3.2 tag bgcolor is used on the final row.

Cell 11Cell 12Cell 13
Cell 21Cell 22Cell 23
Cell 31Cell 32Cell 33

and here's the associated HTML

<table width=50% border=5>
<tr align=left><td width=33%>Cell 11<td width=33%>Cell 12<td width=33%>Cell 13
<tr align=center><td>Cell 21<td>Cell 22<td>Cell 23
<tr align=right bgcolor=yellow><td>Cell 31<td>Cell 32<td>Cell 33
</table>

Notice the use of the width attribute in the <table> and <td> tags.

Here's another three row table this time showing vertical alignment with default left horizontal alignment.

Cell 12Cell 13
Cell 21Cell 23
Cell 31Cell 32

The image is included here to ensure that the rows are high enough for vertical alignment to be an issue.

Browsers
NN, IE and OP2 support the use of the non-HTML 3.2 attribute bgcolor, otherwise all browsers behave in the same fashion.


See also <td>, <th>, <table> and general notes on tables