Table Cell Spanning with colspan and rowspan
HTML Living Standard
A cell can occupy multiple columns or rows. Count the grid positions the browser has already filled before adding another cell.
On this page
Span columns with colspan
colspan="2" makes a cell occupy two adjacent columns in the same row. In that row, write a single cell for those two positions.
How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Span columns with colspan</title>
<style>
th, td { border: 1px solid teal; padding: 8px; }
</style>
</head>
<body>
<table>
<caption>Product availability</caption>
<tr><th scope="col">Folder</th><th scope="col">Stapler</th></tr>
<tr><td colspan="2">Sold out</td></tr>
</table>
</body>
</html>
What to expect Sold out stretches across the two columns below their headings.
Span rows with rowspan
rowspan="2" makes a cell occupy the current row and the one below in the same column. In the second row, add cells only for the open positions.
How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Span rows with rowspan</title>
<style>
th, td { border: 1px solid teal; padding: 8px; }
</style>
</head>
<body>
<table>
<caption>Product catalog</caption>
<tr><th scope="col">Category</th><th scope="col">Item</th></tr>
<tr><td rowspan="2">Stationery</td><td>Pen</td></tr>
<tr><td>Notebook</td></tr>
</table>
</body>
</html>
What to expect Stationery appears in a tall cell next to both Pen and Notebook.
Design a timetable
Make columns for weekdays and rows for time slots. Use caption to name the schedule and th with scope to identify each axis. Merge the five lunch cells with colspan. Pick one lesson and identify its day and time from its headers.