HTML <tr>
tag
The <tr>
tag in HTML is used to define a row within a table. This tag is always used within the <table>
tag, and each <tr>
tag represents a single row in the table.
Here is an example of how the <tr>
tag is used in a simple HTML table:
<table>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
<tr>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
</table>
In the example above, there are two rows in the table, each containing two cells. The content of each cell is defined using the <td>
(table data) tag.
Attributes of the <tr>
tag:
Here are the main attributes of the <tr>
tag and their uses:
Attribute | Description |
align | Specifies the horizontal alignment of the content within the row (left, center, right) |
valign | Specifies the vertical alignment of the content within the row (top, middle, bottom) |
bgcolor | Sets the background color of the row |
height | Sets the height of the row in pixels or percentage |
Here is an example of how the <tr>
tag with some attributes:
<table>
<tr align="center" bgcolor="lightblue" height="40">
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
</table>
In the example above, the row is centered horizontally, has a light blue background color, and a height of 40 pixels.
That's how the <tr>
tag works in HTML! It is essential for creating structured and organized tables on web pages.