agyanadda@gmail.com

HTML Tables

HTML Text & Links 1 min read Updated Nov 30, 2026 Topic 10 of 33

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 columns
  • rowspan="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 »

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which tag creates a table row?

Exercise 2 Fill in the Blank

To make a cell cover two columns use ___="2".

Exercise 3 True / False

Tables are the best way to build a page layout.

Frequently Asked Questions

The quick way is the border attribute, but the modern way is CSS: table, th, td { border: 1px solid #ccc; border-collapse: collapse; }.