The <tr> tag is used to define a row in an HTML table in a webpage.The <tr> tag contains one or more <th> or <td> tags.These three grouping tags: headers (thead tag), bodies (tbody tag) and footers (tfoot tag) contain rows.It is an HTML5 tag.It has opening and closing tags.

Optional Attributes of <tr> tag :- ALIGN/HALIGN|VALIGN|BGCOLOR
Thesee attributes are not valid in HTML5 but in earlier version these are valid.
ALIGN/HALIGN: horizontal alignment of cell contents
VALIGN: vertical alignment of cell contents
BGCOLOR: background color.

You can understand use of <tr> tag by a simple example:-

e.g.1

<!DOCTYPE html>
<html>
<head>
<title>use of <tr> tag</title>
</head>
<body>
<table border="1">
<tr>
<th>Name</th> <th>month</th> <th>Salary</th> </tr>

<tr>
<td>Amit Kumar</td> <td>January</td> <td>15000/-Rs.</td> </tr>

<tr>
<td>Rahul</td> <td>January</td> <td>12000</td> </tr>

</table>
</body> </html>


Result:-
Name month Salary
Amit Kumar January 15000/-Rs.
Rahul January 12000/-Rs.


e.g.2.1

There are two attribiutes cellpadding and cellspacing which can use to adjust the white space in your table cell. Cellspacing defines the width of the border, while cellpadding specifies the distance between cell borders and the content within.

<!DOCTYPE html>
<html>
<head>
<title>use of <tr> tag</title>
</head>
<body>
<table border="1" cellpadding="16">
<tr>
<th>Month</th> <th>Savings</th> </tr>

<tr>
<td>January</td> <td>$100</td> </tr>

</table>
</body>
</html>


Result:-
Month Savings
January $100


e.g.2.2

<!DOCTYPE html>
<html>
<head>
<title>use of <tr> tag</title>
</head>
<body>
<table border="1" cellpadding="16" cellspacing="5">
<tr>
<th>Month</th> <th>Savings</th> </tr>

<tr>
<td>January</td> <td>$100</td> </tr>

</table>
</body>
</html>


Result:-
Month Savings
January $100






Conclusion:--

So the <tr> tag is used to define a row in an HTML table in a webpage and <th> and <td> tags are used inside <tr> tag.You can understand it by above example.



0 comments:

Post a Comment