Skip to content
Tutorials Center
My learning

Topics

HTML Reference ยท Tables

The <tr> element

Reference for the HTML <tr> element: a row of header and data cells, where rows may appear, striping and highlighting rows with CSS, and technical details.

The <tr> element is a table row. It holds a sequence of cells, <th> for headers and <td> for data, from the start of the row to the end. The browser builds the table's columns by lining up the cells of all rows.

Rows sit inside a row group (<thead>, <tbody> or <tfoot>) or directly inside a <table>, in which case the parser places them in an implied <tbody>.

HTML
<tr>
  <th scope="row">Pine</th>
  <td>32 m</td>
</tr>

Try it

Striped and highlighted rows

Rows are a handy target for CSS: :nth-child() stripes them and :hover highlights the row under the pointer.

Attributes

This element has no attributes of its own. It accepts the global attributes. The obsolete align, valign, char, charoff and bgcolor attributes should be replaced with CSS (text-align, vertical-align, background-color).

Usage notes

  • Rows only hold cells. Put text and other content inside a <td> or <th>, never directly in <tr>. Content outside a cell is moved out of the table by the parser.
  • Consistent width. After colspan and rowspan are counted, each row should cover the same number of columns.
  • Borders on rows. A row's border only shows when the table uses border-collapse: collapse. Otherwise, put borders on the cells.
  • Interactive rows. Making a whole row clickable is tempting, but rows are not focusable or announced as links. Put a real link or button in one of the cells.
  • Scripting. table.insertRow() and section.insertRow() add rows, row.insertCell() adds cells, and row.rowIndex gives the row's position in the whole table.

Technical summary

Content categories None
Permitted content Zero or more <td>, <th> and script-supporting elements
Tag omission The start tag is required. The end tag can be omitted if the row is immediately followed by another <tr>, or if there is no more content in the parent element
Permitted parents A <thead>, <tbody> or <tfoot> element; or a <table>, after any <caption>, <colgroup> and <thead> elements, if the table has no <tbody>
Implicit ARIA role row
DOM interface HTMLTableRowElement
Default display table-row

Browser support

Supported in every browser.