Table Groups and Merged Cells
What Is It?
Sometimes one cell needs to cover more than one column or row.
What the Tags Mean
colspan: number of columns a cell covers.rowspan: number of rows a cell covers.thead: header rows.tbody: main rows.tfoot: summary rows.colgroupandcol: column groups.
Example 1
Save each example as index.html and open it in your browser. Each code block is a complete page.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Table Groups and Merged Cells</title>
</head>
<body>
<table style="border: 1px solid gray">
<tr><th colspan="2">Monday</th></tr>
<tr><td>Morning</td><td>Reading</td></tr>
</table>
</body>
</html>Browser preview
What you see: Monday covers both columns in the first row.
Example 2: Another Use
Use rowspan for a value shared by two rows.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Table Groups and Merged Cells</title>
</head>
<body>
<table style="border: 1px solid gray">
<tr><th rowspan="2">Monday</th><td>Reading</td></tr>
<tr><td>Writing</td></tr>
</table>
</body>
</html>Browser preview
Simple Tip
Do not add another cell where a spanning cell already fills the space. Use CSS borders in your finished page.
Try It Yourself
Change the activities in the rowspan example.