The <tr> tag specifies a row in an HTML table. The cells inside it are defined using <th> (a header cell) or <td> (a standard cell) elements. Both the <td> and <th> tags support the colspan attribute for additional control over how cells span across or fit into columns. This attribute allows defining how many columns wide the cell must be (the default being 1). You can use the rowspan attribute on cells if you want to specify that they must span more than one row.

Some tables can also include the <col>, <colgroup>, <caption>, <tfoot>, <tbody>, and <thead> elements.

The <tr> element is declared inside the <table> tag.

All the rows in a table contain an equal number of cells, which is equivalent to the number of cells in the longest row. If there are fewer cells in a row, then the browser will automatically fill the row, placing empty cells at the end of it.

If you need to emphasize that there is no data in other cells, then create cells without content where necessary.

The cells added by browser have no borders, and if they go after each other, they will be shown as one integrated cell.

To customize the look of the table, use CSS properties.

Syntax

The <tr> tag comes in pairs. The content is written between the opening (<tr>) and closing (</tr>) tags.

<table> 
  <tr> 
    <td>...</td> 
  </tr> 
</table>

Example of the HTML <tr> tag:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      table {
        width: 80%;
        margin: 30px auto;
        border-collapse: collapse;
      }
      th,
      td {
        padding: 10px;
        border: 1px solid #666;
      }
    </style>
  </head>
  <body>
    <table>
      <tr>
        <th>Month</th>
        <th>Date</th>
      </tr>
      <tr>
        <td>March</td>
        <td>10.09.2018</td>
      </tr>
      <tr>
        <td>June</td>
        <td>18.07.2018</td>
      </tr>
    </table>
  </body>
</html>

Result

tr example

Attributes

Attribute Value Description
align right
left
center
justify
char
Aligns the content in a table row.
Not supported in HTML 5.
bgcolor bgcolor Specifies a background color for a table row.
Not supported in HTML 5.
bordercolor bordercolor Sets the color of the border.
Not supported in HTML 5.
char character Aligns the content in a table row to a character. It is used only if the attribute is align="char".
Not supported in HTML 5.
charoff number Sets the number of characters the content will be aligned from the character specified by the char attribute. It is used only if the attribute is align="char".
Not supported in HTML 5.
valign top
middle
bottom
baseline
Specifies the vertical alignment of the content inside a table row.
Not supported in HTML 5.

The <tr> tag supports the Global Attributes and the Event Attributes.

How to style <tr> tag?

Common properties to alter the visual weight/emphasis/size of text in <tr> tag:

  • CSS font-style property sets the style of the font. normal | italic | oblique | initial | inherit.
  • CSS font-family property specifies a prioritized list of one or more font family names and/or generic family names for the selected element.
  • CSS font-size property sets the size of the font.
  • CSS font-weight property defines whether the font should be bold or thick.
  • CSS text-transform property controls text case and capitalization.
  • CSS text-decoration property specifies the decoration added to text, and is a shorthand property for text-decoration-line, text-decoration-color, text-decoration-style.

Coloring text in <tr> tag:

  • CSS color property describes the color of the text content and text decorations.
  • CSS background-color property sets the background color of an element.

Text layout styles for <tr> tag:

  • CSS text-indent property specifies the indentation of the first line in a text block.
  • CSS text-overflow property specifies how overflowed content that is not displayed should be signalled to the user.
  • CSS white-space property specifies how white-space inside an element is handled.
  • CSS word-break property specifies where the lines should be broken.

Other properties worth looking at for <tr> tag:

Browser support

chrome edge firefox safari opera

Practice Your Knowledge

What is the purpose and usage of the <tr> tag in HTML?

Quiz Time: Test Your Skills!

Ready to challenge what you've learned? Dive into our interactive quizzes for a deeper understanding and a fun way to reinforce your knowledge.

Do you find this helpful?