👀 Live Preview
A table with header and data rows:
| Product | Price |
|---|---|
| Notebook | $4.99 |
| Pencil | $1.25 |

The <tr> tag defines a row in an HTML table. This guide covers syntax, td and th cells, thead/tbody structure, CSS row styling, accessibility, and best practices for beginners.
Horizontal row containers.
Data vs header cells.
thead, tbody, tfoot.
Opening and closing tr tags.
Style rows with classes.
Valid table structure.
<tr> Tag?The <tr> tag, short for table row, is a fundamental HTML element used to define a horizontal row within a table. It serves as the container for individual cells— either td (table data) or th (table header) elements.
Without tr, you cannot organize tabular data into readable rows. Each row groups related values across columns.
Rows are nested inside table (via thead, tbody, or tfoot). Together, multiple tr elements form the grid structure that displays data on the web.
Use opening and closing tr tags to wrap the cells in one table row:
<tr>
<!-- Your table data (td) or table header (th) elements go here -->
</tr><table>
<tbody>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</tbody>
</table>tr must be inside table, thead, tbody, or tfoot.td and th elements go directly inside tr.colspan and rowspan on child cells).th in header rows and td in data rows for correct semantics.align on tr.| Topic | Code Snippet | Notes |
|---|---|---|
| Basic row | <tr>...</tr> | Row container |
| Data cells | <td>...</td> | Inside tr |
| Header cells | <th>...</th> | Header rows |
| Parent sections | thead, tbody, tfoot | Row groups |
| vs td | tr = row | td = cell |
| Browser support | Universal | All browsers |
<tr> Fits in a Table| Hierarchy | Element | Contains |
|---|---|---|
| 1 | <table> | The entire table |
| 2 | <thead> / <tbody> / <tfoot> | Row group sections |
| 3 | <tr> | One horizontal row |
| 4 | <td> or <th> | Individual cells |
<tr> vs <td> vs <th>| Element | Role | Analogy |
|---|---|---|
<tr> | Row container | A horizontal line in a spreadsheet |
<td> | Data cell | One value in that row |
<th> | Header cell | Column or row label |
| Relationship | tr contains td or th | Row wraps cells |
The <tr> tag has no tag-specific attributes in modern HTML. Use global attributes and CSS for row styling. Alignment belongs on cells or via CSS—not obsolete align on tr:
<tr class="row-center">
<td>Column 1</td>
<td>Column 2</td>
</tr>class / id GlobalStyle entire rows with CSS—zebra stripes, hover highlights, or centered text.
class="row-highlight"align / valign ObsoleteDeprecated on tr. Use CSS text-align on td/th or row classes instead.
text-align: centercolspan / rowspan On cellsCell spanning attributes go on td or th, not on tr.
colspan="2"style GlobalInline row styling works but prefer CSS classes for maintainability.
background: #f8fafcStyled rows, basic data rows, and header rows with copy-ready code, live previews, and hands-on practice.
A table with header and data rows:
| Product | Price |
|---|---|
| Notebook | $4.99 |
| Pencil | $1.25 |
Style alignment and background on a row using a CSS class instead of the obsolete align attribute:
<style>
tr.row-center td { text-align: center; background: #eff6ff; }
</style>
<tr class="row-center">
<td>Column 1</td>
<td>Column 2</td>
</tr>Use <tr> to group td data cells into rows, build header rows with th, and organize tabular content inside thead, tbody, and tfoot.
The primary purpose of <tr> is defining a basic table row by nesting <td> elements inside it:
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>For header rows, use <th> elements inside <tr> within <thead> to denote column labels instead of data:
<thead>
<tr>
<th scope="col">Header 1</th>
<th scope="col">Header 2</th>
</tr>
</thead>Target rows for zebra striping, hover effects, and highlighted states:
tr:nth-child Zebra stripestr:hover Row highlighttr.class Selected rowtd styling Cell alignment/* Zebra striping on tbody rows */
tbody tr:nth-child(even) {
background: #f8fafc;
}
/* Hover highlight */
tbody tr:hover {
background: #eff6ff;
}
/* Centered row via class */
tr.row-center td {
text-align: center;
}Live styled table rows
| Item | Qty |
|---|---|
| Apples | 12 |
| Bananas | 8 |
| Oranges | 5 |
tr with th cells inside thead so screen readers identify column headers.scope="col" or scope="row" on header cells inside tr.tr for genuine tabular data, not page grids.caption on the parent table describes the whole table before rows are read.Open <tr> and add td or th cells for each column.
Rows stack vertically; cells in each row align into columns.
Classes and pseudo-selectors on tr control striping, hover, and highlights.
Each <tr> is one horizontal line of related values—the backbone of every HTML table.
The <tr> tag is supported in all browsers, including legacy Internet Explorer.
All browsers render <tr> as the standard table row element.
Bottom line: Use <tr> confidently to build table rows in any browser.
Mastering the <tr> tag is essential for web developers working with tabular data. By understanding its syntax, relationship to td and th, and proper placement in thead and tbody, you can create well-structured HTML tables that effectively present data on the web.
tr inside table via thead, tbody, or tfoottd or th to create complete rowsalign or valign on trtrtr) for page layoutth and data td randomly in the same row without reason<tr>Bookmark these before you build your next HTML table.
<tr> is the horizontal row container in every HTML table.
Each row wraps td data cells or th header cells.
Place rows in thead, tbody, or tfoot.
Style with classes, :hover, and :nth-child.
Works in every browser, including legacy IE.
Compatibility<tr> element defines a table row containing td or th cells. It must be placed inside table, thead, tbody, or tfoot.td (data) or th (header) cells. No other elements should be direct children of tr.tr is the row container. td is an individual data cell inside that row.align attribute on tr is obsolete. Use CSS classes on the row or text-align on td/th cells instead.Practice <tr> with <td> and <th> in the Try It editor.
5 people found this page helpful