HTML colspan Attribute

Definition
Definition and Usage
The colspan attribute on <td> or <th> makes a cell span multiple columns horizontally. Default is 1. Values above 1000 are clipped to 1000.
Omit the cells that the span already covers. Pair with rowspan for vertical merges, and use scope or headers when headers need clearer associations.
Baseline · Widely available.Not deprecated and not experimental. Standard table attribute across modern browsers.
Syntax
HTML Syntax
<td colspan=" number"> … </td>
Same form on <th>. number is a non-negative integer (typically 1 or greater in practice).
Values
Attribute Values
How common values behave:
| Value | Description | Try it |
|---|
1 or omitted | Default — cell occupies one column | Try it |
2, 3, … | Cell spans that many columns; do not add those covered cells | Try it |
On <th> | Span a header across grouped columns | Try it |
With rowspan | Span both directions when the grid has free space | Try it |
> 1000 | Clipped to 1000 by the HTML rules | Try it |
Try it
Live Preview
Change colspan on the footer cell. Extra cells in that row are added or removed so the grid stays valid.
Code
HTML Examples
Short, copy-ready snippets. Use Try It Yourself for a live editor.
Example 1 — Basic colspan on td
Span a note across two data columns. Do not place a second cell where the span already sits.
<table>
<tr>
<th scope="col">Name</th>
<th scope="col">Score</th>
</tr>
<tr>
<td>Ada</td>
<td>95</td>
</tr>
<tr>
<td colspan="2">Class average: 90</td>
</tr>
</table>
| Name | Score |
|---|
| Ada | 95 |
| Class average: 90 |
How It Works
- Two-column table from the header row (
Name, Score). - colspan="2" makes the average cell cover both columns.
- No second <td> in that row — the span already owns that space.
- scope="col" marks header cells for accessibility.
Example 3 — colspan with rowspan
Combine both when a cell must cover a block — keep the remaining cells from overlapping.
<table>
<tr>
<th scope="row">A</th>
<td>Alfa</td>
<td rowspan="2" colspan="2">Shared block</td>
</tr>
<tr>
<th scope="row">B</th>
<td>Bravo</td>
</tr>
<tr>
<th scope="row">C</th>
<td colspan="3">Charlie — full width note</td>
</tr>
</table>
| A | Alfa | Shared block |
|---|
| B | Bravo |
|---|
| C | Charlie — full width note |
|---|
How It Works
- Shared block covers 2 columns and 2 rows from the first data row.
- Row B only adds A-side cells — the shared block already fills the rest.
- Row C uses
colspan="3" for a full-width note under a 3-column grid. - No overlaps. Counting free slots prevents broken layouts.
Edge Cases & Pitfalls
Most broken tables come from overlapping spans or mixing up cols and colspan.
overlapDo not overlap cells
If a cell spans two columns, delete the cell that would have sat in the second column of that row.
countKeep column totals consistent
Each row’s cells (counting spans) should match the table’s column count.
limitMax 1000
Huge colspan values are clipped to 1000. Real tables never need that size.
namingNot the same as cols
cols sizes a textarea. colspan merges table columns.
JSDOM property is colSpan
In JavaScript the property is colSpan (camelCase). The HTML attribute stays lowercase colspan.
Compatibility
Browser Support
colspan is an HTML attribute for table cells in the browser. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
colspan
Widely available on td and th across modern browsers. Default span is 1 column.
96% Global support (approx.)
Google Chrome All modern
Full support
Mozilla Firefox All modern
Full support
Apple Safari All modern
Full support
Microsoft Edge All modern
Full support
Opera All modern
Full support
Samsung Internet All modern
Full support
Internet Explorer Supported
Supportedcolspan Widely supported
Bottom line: Safe to use for horizontal cell merging. Count columns carefully so spans never overlap.
Remember
Key Takeaways
Role: span a <td> / <th> across multiple columns.
Default: 1; values above 1000 are clipped.
vs rowspan: columns horizontal, rows vertical.
Rule: never overlap — omit covered cells.
One line: colspan merges columns — leave those slots empty in the markup.
Frequently Asked Questions
On td or th, colspan makes the cell span that many columns horizontally. The default is 1 (a normal single column).
Only table cells: td and th. It does not apply to div, span, or the textarea cols attribute.
A non-negative integer. Default is 1. Values greater than 1000 are clipped to 1000.
colspan merges across columns (horizontal). rowspan merges across rows (vertical). You can use both on one cell when the grid allows it.
No. Do not build a table where spans cover the same grid slot. Leave out the cells that the span already covers.
Use cell.colSpan = 3 (capital S in the DOM property) or setAttribute("colspan", "3").
Next: compact
Deprecated spacing hint on lists and other legacy elements.
compact tutorial →About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful