HTML <tr> Tag
To define the rows in a table, the HTML <tr> tag is used. Both the <th> head cells and <td> data cells can be placed within a <tr> tag to define a single row of an HTML table, but the <tr> tag itself is either the direct child of <table> element or a nested child of <thead>, <tbody>, and <tfoot> elements.
Syntax:
<tr>.......</tr>
Example:
<!DOCTYPE html> <html> <body> <h3>Students Table</h3> <table style="width:50%" border="2"> <tr> <th>NAME</th> <th>AGE</th> <th>CITY</th> </tr> <tr> <td>Tom</td> <td>10</td> <td>London</td> </tr> <tr> <td>Jerry</td> <td>8</td> <td>London</td> </tr> <tr> <td>Bruno</td> <td>12</td> <td>Wells</td> </tr> </table> </body> </html>
Explanation:
In the above example, a table is created with three header cells namely, “NAME,” “AGE”, and “CITY”. Here, the width of the table is also defined to be 50%. A border is added to the table of size 2 pixels using the border attribute of the HTML table.
Tag specific Attributes:
Attribute | Value | Uses | HTML 5 |
align | left
right center justify char |
Used to align a row of content. | Not supported in HTML5. |
bgcolor | rgb(x,x,x)
#xxxxxx colorname |
Used to define the background color of a row. | Not supported in HTML5. |
char | character | Used to align a row of content to a character. | Not supported in HTML5. |
charoff | number | Used to define the number of characters the content will be aligned from the character specified by the char attribute. | Not supported in HTML5. |
valign | top
middle bottom baseline |
Used to vertically align the content in a row. | Not supported in HTML5. |
Global Attributes:
The HTML Global attributes are supported by the HTML <tr> tag.
Event Attributes:
The HTML Event attributes are supported by the HTML <tr> tag.
Supporting Browser:
Chrome, IE, Firefox, Opera, and Safari.