Skip to main content

What does the <tr> tag do?

The <tr> tag (from table row) is used in HTML to create a row in a table. Each table row is wrapped in <tr>, and inside it sit the cells - <td> (regular data) or <th> (headers).


Main purpose

<tr> groups cells into a single horizontal line - a table row. Without this tag, a table's structure cannot be defined: every new row of data must sit inside its own <tr>.


Example:

html
<table border="1"> <tr> <th>Name</th> <th>Age</th> </tr> <tr> <td>Maria</td> <td>25</td> </tr> <tr> <td>Oleh</td> <td>30</td> </tr> </table>

What happens here:

  • The first <tr> - creates the header row (<th>).
  • The following <tr> rows - create rows of data (<td>).

Can be used inside:

  • <thead> - for the header row,
  • <tbody> - for rows with the main data,
  • <tfoot> - for rows with totals.
html
<table> <thead> <tr><th>Month</th><th>Income</th></tr> </thead> <tbody> <tr><td>January</td><td>10000</td></tr> <tr><td>February</td><td>12000</td></tr> </tbody> <tfoot> <tr><td>Total</td><td>22000</td></tr> </tfoot> </table>

Conclusion:

The <tr> tag creates a single table row, containing data cells (<td>) or header cells (<th>). Every table consists of a sequence of such rows, forming its "horizontal" structure.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.

What does the <tr> tag do?: HTML Interview Question