<tr>
A table row that contains `<th>` and `<td>` cells.
- Display
- table-row
- Closing tag
- Required
- Permitted content
<th>and<td>cells
Example
#<style>
table { border-collapse: collapse; }
th, td { padding: 4px 12px; text-align: left; }
tbody tr:nth-child(even) { background: #8883; }
tr.me { background: #8b5cf655; font-weight: bold; }
</style>
<table>
<thead>
<tr><th scope="col">Place</th><th scope="col">Student</th><th scope="col">Points</th></tr>
</thead>
<tbody>
<tr><td>1</td><td>Ola</td><td>980</td></tr>
<tr><td>2</td><td>Kuba</td><td>870</td></tr>
<tr class="me"><td>3</td><td>You</td><td>845</td></tr>
<tr><td>4</td><td>Maja</td><td>790</td></tr>
</tbody>
</table>Definition and usage
#The <tr> element (from table row) creates one row of a table. Inside it you put cells: <th> for headers and <td> for data. A row can sit in <thead>, <tbody>, <tfoot>, or directly in <table>, although in the last case the browser will add a <tbody> around it anyway.
The number of cells in the rows should match the number of columns. When a cell should span several columns or rows, use the colspan and rowspan attributes on <td> or <th> instead of inserting empty cells.
A row is a handy hook for CSS: coloring every other row (tr:nth-child(even)), highlighting on hover (tr:hover), or emphasizing the row of the current user in a ranking.
Syntax
#<tr>
<td>β¦</td>
<td>β¦</td>
</tr>Attributes
#This element has no attributes of its own. It supports the global attributes, such as class, id and hidden.
Default CSS
#Most browsers display this element with these default styles:
tr {
display: table-row;
vertical-align: inherit;
}Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Text written directly in a
<tr>, outside a cell, is moved by the browser to before the table. Put everything that should appear in a row inside a<td>or<th>. - Margins (
margin) donβt work on table rows. Set spacing withborder-spacingon the table or withpaddingin the cells.
Related entries
#Practise it in lessons
#Spotted a mistake or missing an example? Write to us.