Tag HTML <tr>

Definition and Usage

<tr> tags define rows in HTML tables.

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

See also:

HTML Tutorial:Tabella HTML

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>

Prova personalmente

Example 2

How to align: <tr> Content inside (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>

Prova personalmente

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>

Prova personalmente

Example 4

How to vertically align: <tr> Content inside (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>

Prova personalmente

Example 5

How to create a table title:

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

Prova personalmente

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>

Prova personalmente

Example 7

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

<table>
  <tr>
    <th>Name</th>
    <th>Email</th>
    <th colspan="2">Telefono</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>

Prova personalmente

Attributi globali

<tr> Il tag supporta anche Attributi globali in HTML.

Attributi eventi

<tr> Il tag supporta anche Attributi eventi in HTML.

Impostazioni CSS predefinite

La maggior parte dei browser utilizzerà i seguenti valori predefiniti per la visualizzazione <tr> Elemento:

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

Supporto browser

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Supporto Supporto Supporto Supporto Supporto