Tables show data in rows and columns — like marks, timetables or price lists.
Table tags
<table>— the whole table<tr>— a table row<th>— a header cell (bold and centred by default)<td>— a normal data cell<caption>— a title for the table<thead>,<tbody>,<tfoot>— group the header, body and footer rows
Merging cells
colspan="2"— a cell spans two columnsrowspan="2"— a cell spans two rows
Tip: Use tables only for data, not for page layout. Use CSS Flexbox or Grid for layout.
Examples
Example — A marks table
HTML
<table border="1" cellpadding="8">
<caption>Class 10 Results</caption>
<thead>
<tr><th>Name</th><th>Maths</th><th>Science</th></tr>
</thead>
<tbody>
<tr><td>Asha</td><td>92</td><td>88</td></tr>
<tr><td>Rohit</td><td>78</td><td>85</td></tr>
</tbody>
</table>
Example — Merging cells
HTML
<table border="1" cellpadding="8">
<tr>
<th>Name</th>
<th colspan="2">Phone numbers</th>
</tr>
<tr>
<td>Asha</td>
<td>98765 43210</td>
<td>91234 56789</td>
</tr>
</table>
colspan="2" makes the header cover both phone columns.
Try it Now »