HTML <tr> tag

Definition and Usage

<tr> tags define rows in HTML tables.

<tr> Elements contain one or more <th> or <td> Element.

See also:

HTML Tutorial:HTML tabel

HTML DOM Reference Manual:TableRow Object

CSS Tutorial:Set table styles

Example

Example 1

A simple three-row HTML table; a 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>

Probeer het zelf

Example 2

How to align <tr> of the content (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>

Probeer het zelf

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>

Probeer het zelf

Example 4

How to vertically align <tr> of the content (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>

Probeer het zelf

Example 5

How to create a table title:

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

Probeer het zelf

Example 6

How to create a table with a title:

<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>

Probeer het zelf

Example 7

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

<table>
  <tr>
    <th>Name</th>
    <th>E-mail</th>
    <th colspan="2">Telefoon</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>

Probeer het zelf

Globale eigenschappen

<tr> De tag ondersteunt ook Globale eigenschappen in HTML.

event eigenschappen

<tr> De tag ondersteunt ook Event eigenschappen in HTML.

Standaard CSS instellingen

De meeste browsers zullen de volgende standaardwaarden weergeven <tr> Element:

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

Browserondersteuning

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Ondersteuning Ondersteuning Ondersteuning Ondersteuning Ondersteuning