HTML Tables
HTML tables are used to display data in a structured
tabular format using rows and columns.
table elements
<table>: The container element that defines the
start and end of a table.
<tr>: Stands for "table row". Each <tr> tag defines
a row in the table.
<th>: Stands for "table header". It's used for the
headers of the columns
<td>: Stands for "table data". This tag is used for
actual data cells under each column.
<caption>: Provides a descriptive title for the table.
This should be the first element after the opening
<table> tag.
Ex
<table border="1">
<tr>
<th>Heading 1</th>
<th>Heading 2</th>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
<tr>
<td>Cell 4</td>
<td>Cell 5</td>
</tr>
</table>
rowspan and colspan Attributes
Rowspan: If you want a table cell to span multiple rows, you
can use the rowspan attribute.
<td rowspan="value">
Colspan: If you want a table cell to span multiple columns, you
can use the colspan attribute.
<td colspan="value">
EX (Colspan)
<table border="1">
<tr>
<th colspan="2">Name</th>
<th>Age</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>30</td>
</tr>
<tr>
<td>Jane</td>
<td>Smith</td>
<td>25</td>
</tr>
</table>
EX (Rowspan)
<table border="1">
<tr>
<th rowspan="2">Name</th>
<th>Subject</th>
<th>Score</th>
</tr>
<tr>
<th>Subject</th>
<th>Score</th>
</tr>
<tr>
<td rowspan="2">John</td>
<td>Math</td>
<td>85</td>
</tr>
<tr>
<td>Science</td>
<td>90</td>
</tr>
</table>