HTML cellspacing Attribute

Definition
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.
Syntax
HTML Syntax
<table cellspacing=" length">
Historical form only. length was typically a pixel integer (or a percentage in older docs).
Values
Attribute Values
What authors used, and the modern CSS mapping:
| Value / approach | Description | Try it |
|---|
| Pixel integer | e.g. cellspacing="8" — 8px between cells | Try it |
0 | No gap between cells (cells sit flush) | Try it |
CSS border-spacing | Modern replacement — needs border-collapse: separate | Try it |
vs cellpadding | Inside-cell space → CSS padding on th/td | Try it |
Try it
Live Preview
Change the obsolete cellspacing value on a sample table. Prefer CSS in real projects.
Code
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.
<table border="1" cellspacing="10" cellpadding="4">
<tr>
<th>Name</th>
<th>Score</th>
</tr>
<tr>
<td>Ada</td>
<td>12</td>
</tr>
</table>
Gaps sit between cells — prefer CSS border-spacing today.
How It Works
- Put
cellspacing on <table>, not on each td. - The value is the gap between neighboring cells.
cellpadding (also shown) pads inside cells — a different job.- Obsolete. Keep for reading old HTML only.
Example 2 — Modern CSS border-spacing
Same between-cell gaps without the HTML attribute.
<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>
Open Try It Yourself to see border-spacing: 10px with separate borders.
How It Works
- Set
border-collapse: separate so spacing can appear. - Use
border-spacing for the gap (one value or horizontal/vertical pair). - Pad cells with CSS
padding if you also need inside space. - No
cellspacing on the table element.
Example 3 — Spacing Between vs Padding Inside
CSS stand-ins for cellspacing and cellpadding.
<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 shows border-spacing between cells vs padding inside them.
How It Works
- Border-spacing = gap between neighboring cells (old
cellspacing). - Padding = room around text inside a cell (old
cellpadding). - Collapse hides between-cell gaps — common for tight modern grids.
- Separate is required when you want visible
border-spacing.
Edge Cases & Pitfalls
Most issues come from border-collapse or mixing up padding.
obsoleteNot for new HTML
Validators flag it. Move gaps into CSS when you edit the table.
collapseborder-collapse: collapse hides spacing
CSS border-spacing only works with separate. Collapse merges borders and removes the gap.
namingNot the same as cellpadding
Between vs inside. Wrong attribute = wrong kind of space.
scopeTable-only attribute
It applied from <table> to the whole grid. Row- or column-specific gaps need CSS.
cascadeCSS can override legacy gaps
A stylesheet may replace the look of an old cellspacing. Prefer one CSS source of truth.
Compatibility
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 onlycellspacing Obsolete — use border-spacing
Bottom line: Expect old tables to keep their HTML gaps. Write new between-cell spacing with CSS border-spacing.
Remember
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
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