
HTML tr Tag
The HTML <tr>
tag is used to define a row within an HTML table. It represents a single row that contains one or more table cells (<td>
or <th>
).
Here’s an example of how the <tr>
tag can be used:
<table>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
<tr>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
</table>
In the above example, the <tr>
tags are used to define two rows in the table. Each <tr>
element contains two table cells represented by <td>
tags. The content within the <td>
tags, such as “Cell 1”, “Cell 2”, etc., represents the data within each cell of the table.
The <tr>
tag must be placed within a <table>
element to create a table structure. It is a container for table cells and helps organize and structure tabular data. By using multiple <tr>
tags, you can create multiple rows in the table.
Within each <tr>
tag, you can include one or more <td>
or <th>
tags to represent the cells in the row. The <td>
tags are used for regular data cells, while the <th>
tags are used for header cells. The header cells are usually placed within the first row of the table using <tr>
.
You can also apply CSS styles to the <tr>
elements to customize their appearance, such as changing the background color, font style, or alignment of the entire row.
By utilizing the <tr>
tag effectively, you can structure your table and organize the data in rows and columns. This helps create a visually appealing and well-organized table for displaying information on your web page.