HTML colspan Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

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.

HTML Syntax

syntax.html
<td colspan=" number"> … </td>

Same form on <th>. number is a non-negative integer (typically 1 or greater in practice).

Attribute Values

How common values behave:

ValueDescriptionTry it
1 or omittedDefault — cell occupies one columnTry it
2, 3, …Cell spans that many columns; do not add those covered cellsTry it
On <th>Span a header across grouped columnsTry it
With rowspanSpan both directions when the grid has free spaceTry it
> 1000Clipped to 1000 by the HTML rulesTry it

Live Preview

Change colspan on the footer cell. Extra cells in that row are added or removed so the grid stays valid.

A 3-column table. The last row adjusts cell count to match the span.

table
ItemQtyPrice
Apples4$3
Total$3

colspan="2"

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.

HTML
<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>
Try It Yourself

How It Works

  1. Two-column table from the header row (Name, Score).
  2. colspan="2" makes the average cell cover both columns.
  3. No second <td> in that row — the span already owns that space.
  4. scope="col" marks header cells for accessibility.

Example 2 — Grouped column headers

Use colspan on <th> to label a group of columns.

HTML
<table>
  <tr>
    <th scope="col" rowspan="2">Product</th>
    <th scope="colgroup" colspan="2">Sales</th>
  </tr>
  <tr>
    <th scope="col">Q1</th>
    <th scope="col">Q2</th>
  </tr>
  <tr>
    <td>Keyboard</td>
    <td>120</td>
    <td>140</td>
  </tr>
</table>
Try It Yourself

How It Works

  1. Sales uses colspan="2" to sit above Q1 and Q2.
  2. Product uses rowspan="2" so it spans both header rows.
  3. Second header row only lists Q1 and Q2 — Product is already spanned.
  4. scope helps assistive tech map headers to data cells.

Example 3 — colspan with rowspan

Combine both when a cell must cover a block — keep the remaining cells from overlapping.

HTML
<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>
Try It Yourself

How It Works

  1. Shared block covers 2 columns and 2 rows from the first data row.
  2. Row B only adds A-side cells — the shared block already fills the rest.
  3. Row C uses colspan="3" for a full-width note under a 3-column grid.
  4. No overlaps. Counting free slots prevents broken layouts.

Edge Cases & Pitfalls

Most broken tables come from overlapping spans or mixing up cols and colspan.

overlap

Do not overlap cells

If a cell spans two columns, delete the cell that would have sat in the second column of that row.

count

Keep column totals consistent

Each row’s cells (counting spans) should match the table’s column count.

limit

Max 1000

Huge colspan values are clipped to 1000. Real tables never need that size.

naming

Not the same as cols

cols sizes a textarea. colspan merges table columns.

JS

DOM property is colSpan

In JavaScript the property is colSpan (camelCase). The HTML attribute stays lowercase colspan.

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
Supported
colspan Widely supported

Bottom line: Safe to use for horizontal cell merging. Count columns carefully so spans never overlap.

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

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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