A table is made of rows and columns. HTML provides special tags for structuring them.
<tr> ā Table Row<td> (table data) or <th> (table headers).š Attributes of <tr>:
align ā Aligns content inside the row (left, right, center, justify).valign ā Vertical alignment (top, middle, bottom).bgcolor ā Background color of the row (old HTML, now done with CSS).Example:
<table border="1" width="400">
<tr align="center" bgcolor="lightblue">
<th>Roll No</th>
<th>Name</th>
<th>Marks</th>
</tr>
<tr valign="top">
<td>1</td>
<td>Ravi</td>
<td>85</td>
</tr>
</table>
<td> ā Table Data Cellš Attributes of <td>:
colspan ā Merge cells horizontally.rowspan ā Merge cells vertically.align ā Horizontal alignment (left, center, right).valign ā Vertical alignment (top, middle, bottom).bgcolor ā Background color of cell (deprecated, use CSS).width, height ā Set size of the cell.Example:
<table border="1">
<tr>
<td rowspan="2">1</td>
<td>Ravi</td>
<td>85</td>
</tr>
<tr>
<td colspan="2" align="center">Passed</td>
</tr>
</table>
š Explanation:
rowspan="2" ā merges two rows.colspan="2" ā merges two columns.<th> ā Table Header Cellš Attributes of <th> (same as <td>):
colspan, rowspanalign, valignbgcolor, width, heightExample:
<table border="1" width="400">
<tr bgcolor="lightgray">
<th colspan="3" align="center">Exam Results</th>
</tr>
<tr>
<th>Roll No</th>
<th>Name</th>
<th>Marks</th>
</tr>
</table>
<thead> ā Table Head Section<tr> with <th>.š Attributes of <thead>:
align, style, class, id).Example:
<table border="1" width="400">
<thead>
<tr>
<th>Roll No</th>
<th>Name</th>
<th>Marks</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Ravi</td>
<td>85</td>
</tr>
<tr>
<td>2</td>
<td>Sita</td>
<td>92</td>
</tr>
</tbody>
</table>
<tfoot> ā Table Footer Section<tbody> but can be rendered at the bottom of the table.š Attributes of <tfoot>:
align, style, id, etc.)Example:
<table border="1" width="400">
<thead>
<tr>
<th>Product</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>Book</td>
<td>200</td>
</tr>
<tr>
<td>Pen</td>
<td>20</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Total</td>
<td>220</td>
</tr>
</tfoot>
</table>
<tbody> ā Table Body Sectionš Attributes of <tbody>:
align, style, id).| Tag | Meaning | Common Attributes | Example |
|---|---|---|---|
<tr> | Table row | align, valign, bgcolor | <tr align="center">...</tr> |
<td> | Table data cell | colspan, rowspan, align, valign, width, height, bgcolor | <td colspan="2">Data</td> |
<th> | Table header cell | Same as <td> | <th rowspan="2">Name</th> |
<thead> | Group header rows | Global attributes | <thead>...</thead> |
<tfoot> | Group footer rows | Global attributes | <tfoot>...</tfoot> |
<tbody> | Group body rows | Global attributes | <tbody>...</tbody> |
<table border="1" cellpadding="5" cellspacing="0" width="400">
<caption>
<b>Class 10 Results</b>
</caption>
<thead>
<tr bgcolor="lightblue">
<th>Roll No</th>
<th>Name</th>
<th>Marks</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Ravi</td>
<td>85</td>
</tr>
<tr>
<td>2</td>
<td>Sita</td>
<td>92</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="2" align="right">Total Students</td>
<td>2</td>
</tr>
</tfoot>
</table>
š So, these table-related tags (tr, td, th, thead, tfoot, tbody) make HTML tables well-structured, readable, and easier to manage.