How to add content to rows?

QuestionsQuestions8 SkillsProHTML TablesOct, 22 2025
091

To add content to rows in an HTML table, you need to use the <tr> (table row) element along with <td> (table data) elements for each cell within that row. Here’s a simple example demonstrating how to add content to rows:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        table {
            width: 100%;
            border-collapse: collapse;
        }
        th, td {
            border: 1px solid black;
            padding: 8px;
            text-align: left;
        }
        th {
            background-color: #f2f2f2;
        }
    </style>
</head>
<body>

<table>
    <thead>
        <tr>
            <th>Header 1</th>
            <th>Header 2</th>
            <th>Header 3</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Row 1, Cell 1</td>
            <td>Row 1, Cell 2</td>
            <td>Row 1, Cell 3</td>
        </tr>
        <tr>
            <td>Row 2, Cell 1</td>
            <td>Row 2, Cell 2</td>
            <td>Row 2, Cell 3</td>
        </tr>
        <tr>
            <td>Row 3, Cell 1</td>
            <td>Row 3, Cell 2</td>
            <td>Row 3, Cell 3</td>
        </tr>
    </tbody>
</table>

</body>
</html>

Explanation:

  1. Table Structure: The table is structured with a <thead> for the header and a <tbody> for the body content.
  2. Adding Rows: Each row is created using the <tr> tag.
  3. Adding Cells: Inside each row, you can add cells using the <td> tag for data cells and <th> for header cells.

You can add as many rows and cells as needed by repeating the <tr> and <td> elements. Adjust the content inside the <td> tags to display the desired information.

0 Comments

no data
Be the first to share your comment!