Table sections and spanning cells
Larger tables can group rows and represent values that cover more than one row or column.
✓ What you will learn in this topic
- Explain the purpose of Table sections and spanning cells in a real HTML document.
- Choose and apply the elements shown in both examples.
- Recognize the specific mistake described in this lesson.
Concept explanation
Thead groups column headings, tbody groups the main data, and tfoot can group totals or notes. Colspan lets a cell extend across columns; rowspan lets it extend across rows. Spanning cells can make relationships harder to follow, so use them only when the data really has that shape. Complex tables may need explicit headers and id associations instead of relying only on simple scope.
Syntax
Group rows with thead, tbody, and optionally tfoot; set colspan or rowspan to the number of cells covered.
Example 1: a small page
The footer row summarizes the body and is marked as a row header.
<table>
<thead><tr><th scope=\"col\">Item</th><th scope=\"col\">Count</th></tr></thead>
<tbody><tr><td>Seed packets</td><td>8</td></tr></tbody>
<tfoot><tr><th scope=\"row\">Total</th><td>8</td></tr></tfoot>
</table>Expected result: The browser displays a table with a header row, one data row, and a total row.
Example 2: a practical page
Studio spans two day rows, while the Hall status spans two columns because the same note applies across them.
<table>
<caption>Room availability</caption>
<thead><tr><th scope=\"col\">Room</th><th scope=\"col\">Day</th><th scope=\"col\">Availability</th></tr></thead>
<tbody>
<tr><th scope=\"row\" rowspan=\"2\">Studio</th><td>Monday</td><td>Open</td></tr>
<tr><td>Tuesday</td><td>Open</td></tr>
<tr><th scope=\"row\">Hall</th><td colspan=\"2\">Closed for repairs</td></tr>
</tbody>
</table>Expected result: A captioned schedule shows Studio availability for two days and a single Hall closure note across its remaining columns.
Common mistakes
Do not use a table to arrange page layout; reserve tables for genuinely tabular data.
Best practices
Give data tables a caption and use th with scope so row and column relationships are clear.
Practice exercise
Create a weekly class timetable with a caption, two column headers, three rows, and a row header for each class.
Lesson summary
- Row groups clarify larger tables, and spanning cells represent values shared across rows or columns.
- Give data tables a caption and use th with scope so row and column relationships are clear.
Knowledge check
What does colspan=\"2\" mean on a table cell?
Show the explanation
The cell occupies two columns in that row; rowspan instead extends a cell across rows.
Practical example
html<table>
<thead><tr><th scope=\"col\">Item</th><th scope=\"col\">Count</th></tr></thead>
<tbody><tr><td>Seed packets</td><td>8</td></tr></tbody>
<tfoot><tr><th scope=\"row\">Total</th><td>8</td></tr></tfoot>
</table>
Expected result:
The browser displays a table with a header row, one data row, and a total row.
Hands-on practice task
Create a weekly class timetable with a caption, two column headers, three rows, and a row header for each class.
In this section
Other lessons in Tables
Broaden your knowledge