HTML cellspacing Attribute

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

Definition and Usage

The cellspacing attribute belonged on <table>. It set the space between cells — the gap outside each cell’s border — not the padding inside the cell.

Do not use it in new pages. MDN marks it obsolete. Use CSS border-spacing on the table (with border-collapse: separate). Do not confuse it with cellpadding (space inside cells).

Obsolete.

Presentational HTML. Kept for reading legacy tables — not for new markup. Prefer CSS border-spacing.

Still honored in many browsers.

Old pages may still show gaps because engines keep compatibility. That is not a reason to write new cellspacing.

HTML Syntax

syntax.html
<table cellspacing=" length">

Historical form only. length was typically a pixel integer (or a percentage in older docs).

Attribute Values

What authors used, and the modern CSS mapping:

Value / approachDescriptionTry it
Pixel integere.g. cellspacing="8" — 8px between cellsTry it
0No gap between cells (cells sit flush)Try it
CSS border-spacingModern replacement — needs border-collapse: separateTry it
vs cellpaddingInside-cell space → CSS padding on th/tdTry it

Live Preview

Change the obsolete cellspacing value on a sample table. Prefer CSS in real projects.

Legacy attribute demo on <table>.

Table
ItemQty
Apples3
Pears2

cellspacing="8"

HTML Examples

Example 1 is historical. Examples 2–3 show CSS (and how spacing differs from padding).

Example 1 — Legacy cellspacing (Do Not Ship)

Older pages set the gap between cells from the table element.

HTML
<table border="1" cellspacing="10" cellpadding="4">
  <tr>
    <th>Name</th>
    <th>Score</th>
  </tr>
  <tr>
    <td>Ada</td>
    <td>12</td>
  </tr>
</table>
Try It Yourself

How It Works

  1. Put cellspacing on <table>, not on each td.
  2. The value is the gap between neighboring cells.
  3. cellpadding (also shown) pads inside cells — a different job.
  4. Obsolete. Keep for reading old HTML only.

Example 2 — Modern CSS border-spacing

Same between-cell gaps without the HTML attribute.

HTML
<style>
  table.scores {
    border-collapse: separate;
    border-spacing: 10px;
  }
  table.scores th,
  table.scores td {
    border: 1px solid #888;
    padding: 4px 8px;
  }
</style>

<table class="scores">
  <tr>
    <th>Name</th>
    <th>Score</th>
  </tr>
  <tr>
    <td>Ada</td>
    <td>12</td>
  </tr>
</table>
Try It Yourself

How It Works

  1. Set border-collapse: separate so spacing can appear.
  2. Use border-spacing for the gap (one value or horizontal/vertical pair).
  3. Pad cells with CSS padding if you also need inside space.
  4. No cellspacing on the table element.

Example 3 — Spacing Between vs Padding Inside

CSS stand-ins for cellspacing and cellpadding.

HTML
<style>
  table.space {
    border-collapse: separate;
    border-spacing: 12px; /* was cellspacing */
  }
  table.space th,
  table.space td {
    border: 1px solid #888;
    padding: 4px;
  }
  table.pad {
    border-collapse: collapse;
  }
  table.pad th,
  table.pad td {
    border: 1px solid #888;
    padding: 12px; /* was cellpadding */
  }
</style>

<p>Between cells (border-spacing):</p>
<table class="space">
  <tr><td>A</td><td>B</td></tr>
</table>

<p>Inside cells (padding):</p>
<table class="pad">
  <tr><td>A</td><td>B</td></tr>
</table>
Try It Yourself

How It Works

  1. Border-spacing = gap between neighboring cells (old cellspacing).
  2. Padding = room around text inside a cell (old cellpadding).
  3. Collapse hides between-cell gaps — common for tight modern grids.
  4. Separate is required when you want visible border-spacing.

Edge Cases & Pitfalls

Most issues come from border-collapse or mixing up padding.

obsolete

Not for new HTML

Validators flag it. Move gaps into CSS when you edit the table.

collapse

border-collapse: collapse hides spacing

CSS border-spacing only works with separate. Collapse merges borders and removes the gap.

naming

Not the same as cellpadding

Between vs inside. Wrong attribute = wrong kind of space.

scope

Table-only attribute

It applied from <table> to the whole grid. Row- or column-specific gaps need CSS.

cascade

CSS can override legacy gaps

A stylesheet may replace the look of an old cellspacing. Prefer one CSS source of truth.

Browser Support

cellspacing is an obsolete HTML attribute on tables. Many browsers still honor it for compatibility.

✓ Obsolete · Legacy only

cellspacing

Still applied in modern browsers for old pages. Not recommended for new work — use CSS border-spacing with separate borders.

0% Recommended for new work
Google Chrome Still applies · legacy
Legacy only
Mozilla Firefox Still applies · legacy
Legacy only
Apple Safari Still applies · legacy
Legacy only
Microsoft Edge Still applies · legacy
Legacy only
Opera Still applies · legacy
Legacy only
Internet Explorer Legacy support
Legacy only
cellspacing Obsolete — use border-spacing

Bottom line: Expect old tables to keep their HTML gaps. Write new between-cell spacing with CSS border-spacing.

Key Takeaways

  • Was: gap between cells, set on <table>.
  • Now: obsolete — use CSS border-spacing.
  • Needs separate borders: border-collapse: collapse hides spacing.
  • Not cellpadding: that is space inside cells.

One line: learn cellspacing to read old tables — ship border-spacing instead.

Frequently Asked Questions

On a table element it set the space between neighboring cells — the gap outside each cell’s border, not the padding inside the cell.
Yes. MDN marks it obsolete. Use the CSS border-spacing property on the table instead, with border-collapse set to separate.
cellspacing is space between cells. cellpadding is space inside cells (content to border). In CSS: border-spacing vs padding on th/td.
border-spacing only applies when borders are separate. With collapse, adjacent borders merge and the between-cell gap disappears.
No. It belonged on the table element and affected the whole grid. Fine-grained control belongs in CSS.
Many browsers still honor it for compatibility. New pages should use CSS border-spacing.

Next: char

Another legacy table attribute from the alignment era.

char 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