Open In App

How to create a table row using HTML?

Last Updated : 19 Jun, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Define a row in a table by using a <tr> tag in a document. This tag is used to define a row in an HTML table. The tr element contains multiple th or td elements.

Syntax:

<tr> ... </tr>

Example: In this example, a table row in HTML5, utilizes the <tr> tag within the <tbody> section of the table. Each <tr> tag encloses table cells that define the content for each column. Use CSS for styling, ensuring consistent borders and alignment across cells and headers.

html
<!DOCTYPE html>
<html>

<head>
    <title>
        How to define row of a table
    </title>

    <style>
        body {
            text-align: center;
        }

        h1 {
            color: green;
        }

        th {
            color: blue;
        }

        table,
        tbody,
        td {
            border: 1px solid black;
            border-collapse: collapse;
        }
    </style>
</head>

<body>
    <center>

        <h2>
            Define
            a row in a table
        </h2>
        <table>
            <thead>
                <!-- tr tag starts here -->
                <tr>
                    <th>Name</th>
                    <th>User Id</th>
                </tr>
                <!-- tr tag end here -->
            </thead>
            <tbody>
                <tr>
                    <td>Shashank</td>
                    <td>@shashankla</td>
                </tr>
                <tr>
                    <td>GeeksforGeeks</td>
                    <td>@geeks</td>
                </tr>
            </tbody>
        </table>
    </center>
</body>

</html>

Output:

tablerow
Output

Supported Browsers

  • Google Chrome: 129
  • Firefox: 130
  • Opera: 110
  • Safari: 17.6



Next Article

Similar Reads