<tr> Tag in HTML | Table Row Element

The <tr> tag in HTML is used to define a single row within a table. It is placed inside the <table> tag and typically contains <td> (table data) or <th> (table header) elements to specify individual cells in the row.

Key Points on <tr> Tag:

Syntax of <tr> Tag:

Syntax Example

<table>
            <tr>
                <td>Row Data 1</td>
                <td>Row Data 2</td>
            </tr>
        </table>

Example of Using <tr> Tag:

This example demonstrates a table with two rows, each containing two cells.

Code Example

<table border="1">
            <tr>
                <th>Header 1</th>
                <th>Header 2</th>
            </tr>
            <tr>
                <td>Row 1, Cell 1</td>
                <td>Row 1, Cell 2</td>
            </tr>
            <tr>
                <td>Row 2, Cell 1</td>
                <td>Row 2, Cell 2</td>
            </tr>
        </table>

Output

Header 1 Header 2
Row 1, Cell 1 Row 1, Cell 2
Row 2, Cell 1 Row 2, Cell 2

Attributes of <tr> Tag:

Best Practices:

The <tr> tag is essential for creating rows in HTML tables, allowing structured data organization. Using this tag along with <td> and <th> helps in creating readable, organized tables.