HTML <tr> Tag

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 3 Examples
Tables

What You’ll Learn

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.

01

Table Rows

Horizontal row containers.

02

td & th

Data vs header cells.

03

Row Groups

thead, tbody, tfoot.

04

Core Syntax

Opening and closing tr tags.

05

CSS Styling

Style rows with classes.

06

Best Practices

Valid table structure.

What Is the <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.

Building block of every HTML table

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.

📝 Syntax

Use opening and closing tr tags to wrap the cells in one table row:

syntax.html
<tr>
  <!-- Your table data (td) or table header (th) elements go here -->
</tr>

Complete Table Row

complete-row.html
<table>
  <tbody>
    <tr>
      <td>Data 1</td>
      <td>Data 2</td>
    </tr>
  </tbody>
</table>

Syntax Rules

  • tr must be inside table, thead, tbody, or tfoot.
  • Only td and th elements go directly inside tr.
  • Each row should contain a consistent number of cells (accounting for colspan and rowspan on child cells).
  • Use th in header rows and td in data rows for correct semantics.
  • Style rows with CSS classes—avoid obsolete HTML attributes like align on tr.

⚡ Quick Reference

TopicCode SnippetNotes
Basic row<tr>...</tr>Row container
Data cells<td>...</td>Inside tr
Header cells<th>...</th>Header rows
Parent sectionsthead, tbody, tfootRow groups
vs tdtr = rowtd = cell
Browser supportUniversalAll browsers

🗃 Where <tr> Fits in a Table

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

ElementRoleAnalogy
<tr>Row containerA horizontal line in a spreadsheet
<td>Data cellOne value in that row
<th>Header cellColumn or row label
Relationshiptr contains td or thRow wraps cells

🧰 Attributes

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:

attributes.html
<tr class="row-center">
  <td>Column 1</td>
  <td>Column 2</td>
</tr>
class / id Global

Style entire rows with CSS—zebra stripes, hover highlights, or centered text.

class="row-highlight"
align / valign Obsolete

Deprecated on tr. Use CSS text-align on td/th or row classes instead.

text-align: center
colspan / rowspan On cells

Cell spanning attributes go on td or th, not on tr.

colspan="2"
style Global

Inline row styling works but prefer CSS classes for maintainability.

background: #f8fafc

Examples Gallery

Styled rows, basic data rows, and header rows with copy-ready code, live previews, and hands-on practice.

👀 Live Preview

A table with header and data rows:

ProductPrice
Notebook$4.99
Pencil$1.25

Styled Table Row

Style alignment and background on a row using a CSS class instead of the obsolete align attribute:

styled-row.html
<style>
  tr.row-center td { text-align: center; background: #eff6ff; }
</style>

<tr class="row-center">
  <td>Column 1</td>
  <td>Column 2</td>
</tr>
Try It Yourself

📚 Common Use Cases

Use <tr> to group td data cells into rows, build header rows with th, and organize tabular content inside thead, tbody, and tfoot.

Basic Table Row

The primary purpose of <tr> is defining a basic table row by nesting <td> elements inside it:

basic-table-row.html
<tr>
  <td>Data 1</td>
  <td>Data 2</td>
</tr>
Try It Yourself

Table Header Row

For header rows, use <th> elements inside <tr> within <thead> to denote column labels instead of data:

table-header-row.html
<thead>
  <tr>
    <th scope="col">Header 1</th>
    <th scope="col">Header 2</th>
  </tr>
</thead>
Try It Yourself

Styling <tr> Rows with CSS

Target rows for zebra striping, hover effects, and highlighted states:

tr:nth-child Zebra stripes
tr:hover Row highlight
tr.class Selected row
td styling Cell alignment
tr-styles.css
/* 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

ItemQty
Apples12
Bananas8
Oranges5

♿ Accessibility

  • Use thead for header rows — Place tr with th cells inside thead so screen readers identify column headers.
  • Add scope on th — Use scope="col" or scope="row" on header cells inside tr.
  • Keep row structure consistent — Each data row should have the same number of logical columns.
  • Do not use tables for layout — Reserve tr for genuine tabular data, not page grids.
  • Add a caption — A caption on the parent table describes the whole table before rows are read.

🧠 How <tr> Works

1

Author creates a row

Open <tr> and add td or th cells for each column.

Markup
2

Browser builds the grid

Rows stack vertically; cells in each row align into columns.

Layout
3

CSS styles the row

Classes and pseudo-selectors on tr control striping, hover, and highlights.

Design
=

Organized tabular data

Each <tr> is one horizontal line of related values—the backbone of every HTML table.

Browser Support

The <tr> tag is supported in all browsers, including legacy Internet Explorer.

Baseline · HTML4 / HTML5

Table rows everywhere

All browsers render <tr> as the standard table row element.

100% Core tag support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
Internet Explorer Fully supported · EOL
Full support
Opera Fully supported
Full support
<tr> tag 100% supported

Bottom line: Use <tr> confidently to build table rows in any browser.

Conclusion

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.

💡 Best Practices

✅ Do

  • Always nest tr inside table via thead, tbody, or tfoot
  • Combine with td or th to create complete rows
  • Use CSS for row styling, striping, and hover effects
  • Keep the same number of cells per row for clean alignment

❌ Don’t

  • Use obsolete align or valign on tr
  • Put non-cell content directly inside tr
  • Use tables (and tr) for page layout
  • Mix header th and data td randomly in the same row without reason

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about <tr>

Bookmark these before you build your next HTML table.

5
Core concepts
📑 02

Holds Cells

Each row wraps td data cells or th header cells.

Structure
🗃 03

Row Groups

Place rows in thead, tbody, or tfoot.

Semantics
🎨 04

CSS Rows

Style with classes, :hover, and :nth-child.

Design
🌐 05

100% Support

Works in every browser, including legacy IE.

Compatibility

❓ Frequently Asked Questions

The <tr> element defines a table row containing td or th cells. It must be placed inside table, thead, tbody, or tfoot.
One or more 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.
No. The align attribute on tr is obsolete. Use CSS classes on the row or text-align on td/th cells instead.
Yes. Full support in every major browser including Internet Explorer.

Build your first table row

Practice <tr> with <td> and <th> in the Try It editor.

Try basic data row →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful