HTML Colspan & Rowspan Guide
Learn how to create complex table layouts using colspan and rowspan attributes
Introduction to Colspan & Rowspan
The colspan and rowspan attributes allow table cells to span multiple columns or rows, enabling you to create more complex and visually appealing table layouts. These attributes are essential for creating headers that span multiple columns, vertical labels, and merged cells in data tables.
Basic Examples
Basic Colspan
Header spanning multiple columns
| Employee Details | |
|---|---|
| John Doe | johndoe@example.com |
Basic Rowspan
Cell spanning multiple rows
| Department | Employees |
|---|---|
| 25 |
Combined Example
Using both colspan and rowspan together
| Name | Contact | |
|---|---|---|
| Phone | ||
| John Doe | john@example.com | 555-1234 |
Advanced Examples
Complex Layout
Advanced table with multiple spans
| Product | Quarterly Sales | ||
|---|---|---|---|
| Q1 | Q2 | Q3 | |
| Laptops | $120,000 | $135,000 | $150,000 |
| Total: $405,000 | |||
Schedule Table
Timetable with row and column spans
| Time | Monday | Tuesday | Wednesday |
|---|---|---|---|
| 9:00-11:00 | Math | Science Lab | History |
| Physics | Geography | ||
| 11:00-12:00 | Break | ||
Accessibility Tips
Accessible Complex Tables
Using scope, headers, and ARIA attributes
| Category | January | February |
|---|---|---|
| Income | $5,000 | $5,200 |
| Expenses | ||
| Rent | $1,200 | $1,200 |