HTML Table Cell Spans: colspan and rowspan
Span columns
colspan tells the browser that a single cell covers multiple columns. In this schedule the workshop occupies two time slots, so the row needs only one data cell after its row header.
<table> <caption>Schedule</caption> <tr> <th scope="col">Room</th> <th scope="col">9 AM</th> <th scope="col">10 AM</th> </tr> <tr> <th scope="row">A</th> <td colspan="2">Workshop</td> </tr></table>Workshop occupies two columns, not two separate cells.
Span rows
rowspan extends a cell down across rows. The following row must omit the position already occupied by the spanning cell. This example repeats one price across two records without duplicating the data cell.
<table> <caption>Session prices (EUR)</caption> <thead> <tr> <th scope="col">Session</th> <th scope="col">Price</th> </tr> </thead> <tbody> <tr> <th scope="row">Morning</th> <td rowspan="2">10</td> </tr> <tr> <th scope="row">Afternoon</th> </tr> </tbody></table>The price cell spans both session rows.
Span to the end of a row group
Both attributes default to 1. Valid colspan values are 1–1000; valid rowspan values are 0–65534. A rowspan of zero means the remaining rows in the current row group, not the whole table. Prefer small explicit spans when the number is known.
<table> <caption>Daily desk status</caption> <thead> <tr> <th scope="col">Day</th> <th scope="col">Shift</th> <th scope="col">Status</th> </tr> </thead> <tbody> <tr> <th scope="row">Mon</th> <td>AM</td> <td rowspan="0">Open</td> </tr> <tr> <th scope="row">Mon</th> <td>PM</td> </tr> </tbody> <tbody> <tr> <th scope="row">Tue</th> <td>AM</td> <td>Closed</td> </tr> </tbody></table>Open spans the two Monday rows only; Tuesday has its own status.
Common mistakes and practice
Count logical grid positions rather than the number of tags in each row. Do not add a cell to a position occupied by an existing span or attempt to span across row groups. Complex header relationships are covered next; simpler tables are often easier to navigate.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML Table Cell Spans: colspan and rowspan — Knowledge Check
Apply table structure and accessibility concepts from this lesson.
How many grid columns does colspan="3" occupy?
A two-column table has a first cell with rowspan="2". How many new cells are needed in the next row?
What does rowspan="0" span?
A cell spans two columns in a three-column row. How many additional single-column cells fill the row?
When using rowspan, what must you consider in later rows?