Lesson 27 of 51 · Module 4, lesson 6 of 6 · 3 min
Cells that span rows and columns
Make a cell cover several columns or rows, and count cells so the table does not break.
What you'll learn
- How to make a cell span several columns with
colspan- How to make a cell span several rows with
rowspan- How to count cells so that the table does not break
Why this matters
Real timetables and price lists often have a cell that stretches across two columns or down two rows. HTML can do this — but only if you remove the cells that the big cell covers. This lesson shows how to count them.
The two attributes
colspan="2"— the cell is two columns wide. Remove one cell from the same row.rowspan="2"— the cell is two rows high. Remove one cell from the row below.
A timetable
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Timetable</title>
</head>
<body>
<table>
<caption>Class timetable</caption>
<thead>
<tr>
<th scope="col">Day</th>
<th scope="col">9:00</th>
<th scope="col">10:00</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Monday</th>
<td colspan="2">Project work</td>
</tr>
<tr>
<th scope="row">Tuesday</th>
<td>HTML</td>
<td>CSS</td>
</tr>
<tr>
<th scope="row">Wednesday</th>
<td rowspan="2">Self-study</td>
<td>Review</td>
</tr>
<tr>
<th scope="row">Thursday</th>
<td>Quiz</td>
</tr>
</tbody>
</table>
</body>
</html>
What you'll see: "Project work" starts under 9:00 and runs into the 10:00 column. "Self-study" sits between the Wednesday and Thursday rows. Without borders (a CSS job) the spans are hard to see — open the developer tools and point at a cell in the Elements panel: the browser outlines exactly the area it covers. The figure above shows the same idea with borders.
Count the cells
Each row must still add up to the number of columns (here: 3).
| Row | Cells in code | Adds up to |
|---|---|---|
| Monday | Day + colspan="2" | 1 + 2 = 3 |
| Tuesday | Day + HTML + CSS | 3 |
| Wednesday | Day + rowspan="2" + Review | 3 |
| Thursday | Day + Quiz (9:00 is filled from above) | 1 + 1 + 1 = 3 |
Keep it simple
Spanning cells make tables harder to read for everyone, and especially with a screen reader. Use them only when the data needs them. If a table becomes complicated, split it into two simpler tables.
Try it yourself
- Select the example and choose Try it.
- Add a Friday row where one activity fills both columns.
- Break it on purpose: add a third cell to Monday's row. The table grows an extra column. Remove it again.
Common mistakes
- Not removing the covered cell. The row pushes out an extra column. Fix: count each row.
- Removing a cell from the wrong row with
rowspan. Fix: the cell is removed from the row below, in the same column. - Using
colspanto make a title across the top. Fix: use<caption>for the title.
Check yourself
- A row has 4 columns. One cell has
colspan="3". How many other cells does that row need? - With
rowspan="2"in Monday's row, which row loses a cell? - What should you do when a table becomes hard to read?
Answers
- One (3 + 1 = 4).
- The next row (Tuesday's), in the same column.
- Split it into simpler tables.
Next: that completes lists and tables. Practise both in the next exercise.
a study timetable and to-do list
Starter code
Build it in your own folder, on your computer. ZAM students hand this project in on their dashboard, and their mentor reviews it.


