HTML Tables: table, tr, th, td, caption, thead, tbody, tfoot, colspan, rowspan and Accessible Data Tables
When to Use a Table
Use a table for data that has rows and columns, like a price list or schedule. Do not use tables to place the page layout. Use CSS for that.
A Basic Table
html
<table>
<caption>Monthly Plans</caption>
<thead>
<tr>
<th scope="col">Plan</th>
<th scope="col">Price</th>
<th scope="col">Users</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Basic</th>
<td>$9</td>
<td>1</td>
</tr>
<tr>
<th scope="row">Team</th>
<td>$29</td>
<td>10</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="3">Prices shown per month</td>
</tr>
</tfoot>
</table>
| Tag | Meaning |
|---|---|
table | The whole table |
caption | A title for the table |
thead, tbody, tfoot | Header, body and footer groups |
tr | A row |
th | A header cell, bold and centered by default |
td | A data cell |
Joining Cells
html
<tr>
<td colspan="2">Spans two columns</td>
<td rowspan="2">Spans two rows</td>
</tr>
<tr>
<td>A</td>
<td>B</td>
</tr>
Make It Accessible
- Use
thfor headers andscope="col"orscope="row" - Add a
captionso people know what the table is about - Keep tables simple. Avoid many merged cells
Style the Table with CSS
css
table {
border-collapse: collapse;
width: 100%;
max-width: 40rem;
}
caption { font-weight: bold; text-align: left; padding: .5rem 0; }
th, td { border: 1px solid #ccd3dd; padding: .6rem .8rem; text-align: left; }
thead th { background: #0b5fff; color: #fff; }
tbody tr:nth-child(even) { background: #f3f6fb; }
Wide tables on phones Wrap a wide table in a
div with overflow-x: auto so it scrolls sideways instead of breaking the page.
Practice
- Create a weekly timetable table
- Use colspan for a title cell
- Add zebra stripes and a header color with CSS
Conclusion
Tables are for data. Use thead, tbody, th with scope and a caption, and style them with CSS.
Quick Summary: When to use; basic table; merging; accessibility; CSS styling.

