HTML Tables

HTML tables allow you to arrange data like text, images, and links in rows and columns. You use the <table> tag to start and end a table.

Key Elements of HTML Table

<table>
	<captioin>Personal info</caption>
	<tr>
		<th>Name</th>
		<th>Age</th>
	</tr>
	<tr>
		<td>Chandu</td>
		<td>18</td>
	</tr>
</table>

Rowspan & Colspan attributes

Rowspan: If you want a table cell to span multiple rows, you can use the rowspan attribute. Colspan: If you want a table cell to span multiple columns, you can use the colspan attribute.

colspan-rowspan.png

Example for Colspan :

<table border="1">
	<tr>
		<td colspan="2">Merged columns</td>
	</tr>
	<tr>
		<td>column 1</td>
		<td>column 2</td>
	</tr>
</table>

Example for Rowspan :

<table border="1">
	<tr>
		<td>row1, column1</td>
		<td rowspan="2">Merged rows</td>
	<tr>
	<tr>
		<td>row2, column2</td>
	<tr>
</table>