Home CSS Properties border-spacing CSS border-spacing Property Definition
Definition and Usage The border-spacing property sets the distance between the borders of adjacent cells in a table. It applies only when border-collapse is separate.
One length sets both horizontal and vertical gaps. Two lengths set horizontal first, then vertical. The initial value is 0. It applies to table and inline-table elements, and it is inherited . For Flexbox or Grid, use gap instead.
Baseline · Replaces deprecated HTML. Not deprecated in CSS. Prefer border-spacing over the deprecated HTML cellspacing attribute. Spacing is ignored when borders are collapsed.
Syntax
CSS Syntax border-spacing: <length> | <length> <length> | initial | inherit ;
One non-negative length for both axes, or two lengths: horizontal then vertical. Negative values are invalid.
Values
Property Values Value Description Try it One <length> Same gap horizontally and vertically, such as 10px Try itTwo <length>s First: space between columns. Second: space between rows Try it0No extra gap. Initial value. Cells can still have separate borders Try it1emSpacing relative to the table’s font size Try itinitialSets this property to its default value, 0 Try itinheritInherits this property from the parent. Useful because spacing is inherited by default Try it
Approach
How to Use border-spacing Use the separate border model, then set how far cell borders sit apart.
Build a real <table> (or an element with display: table). Set border-collapse: separate . Spacing does nothing in the collapse model. Give cells a visible border so the gaps are easy to see. Set border-spacing to one length, or two lengths for horizontal then vertical. Piece Required? Role Table element Yes Only table / inline-table use this property border-collapse: separateYes Collapse mode ignores spacing Cell borders Usually Make the gaps between cells visible One or two lengths Yes Equal gap, or horizontal then vertical
Try it
Live Preview The table stays in the separate model. Change border-spacing and watch the gaps update.
Code
CSS Examples Each snippet uses a small table with border-collapse: separate. Use Try It Yourself for a live editor.
1. One value 2. Two values 3. Zero Example 1 — Equal Spacing One length sets the same gap between columns and between rows.
<style>
table {
border-collapse: separate;
border-spacing: 10px;
}
td {
border: 2px solid #2563eb;
padding: 8px;
}
</style>
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table> How It Works Stay in the separate model. border-collapse: separate allows gaps between cell borders.Set one length. border-spacing: 10px adds 10px between columns and between rows.Show the borders. Cell borders make those gaps visible.Outside edges too. Spacing also adds space between the outer cells and the table edge (plus any table padding).Example 2 — Horizontal and Vertical Two lengths: first for columns, second for rows.
<style>
table {
border-collapse: separate;
border-spacing: 5px 15px;
}
td {
border: 2px solid #2563eb;
padding: 8px;
}
</style>
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table> How It Works Keep separate borders. Collapse mode would ignore both values.First value is horizontal. 5px is the gap between cells in adjacent columns.Second value is vertical. 15px is the gap between cells in adjacent rows.Read the shape. Rows look farther apart than columns in this example.Example 3 — Zero Spacing Separate borders with no extra gap. This is the initial value.
<style>
table {
border-collapse: separate;
border-spacing: 0;
}
td {
border: 2px solid #2563eb;
padding: 8px;
}
</style>
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table> How It Works Stay separate. Cells still have their own borders. They are not merged.Set spacing to zero. 0 removes the extra gap between those borders.Compare with collapse. Adjacent borders can look double-thick here. border-collapse: collapse would merge them into one line.Default behavior. This matches the initial value until you choose a larger length. Edge Cases & Pitfalls If the gaps do not appear, one of these is usually why.
table Not for Flexbox or Grid border-spacing only applies to table and inline-table. Use gap for flex and grid layouts.
inherit Spacing is inherited Unlike most border properties, children can inherit the gap. Nested tables may pick up a parent’s spacing unless you override it.
minus Negative lengths are invalid border-spacing: -5px is dropped. Use 0 or a positive length.
HTML Prefer CSS over cellspacing The HTML cellspacing attribute is deprecated. Use border-spacing in CSS instead.
Compatibility
Browser Support border-spacing is a browser CSS property for the separated table border model. Node.js, Deno, and Bun do not apply it.
✓ Baseline · Widely available
border-spacing Supported in all modern browsers and Internet Explorer when border-collapse is separate.
Google Chrome All versions
Full support
Mozilla Firefox All versions
Full support
Apple Safari All versions
Full support
Microsoft Edge All versions
Full support
Opera All versions
Full support
Samsung Internet All versions
Full support
Internet Explorer All versions
Full support border-spacing Widely supported
Bottom line: Safe everywhere for one or two length values. Remember: it only works with border-collapse: separate. It is not a runtime API.
Remember
Key Takeaways Role: gap between adjacent table cell borders in the separate model.
Requires separate: ignored when border-collapse is collapse.
One or two lengths: equal gap, or horizontal then vertical.
Inherited: initial value is 0. Nested tables can inherit the gap.
One line: border-spacing opens gaps between table cell borders — only when border-collapse is separate.
Frequently Asked Questions What does the CSS border-spacing property do? It sets the distance between the borders of adjacent table cells. One length sets both axes. Two lengths set horizontal then vertical spacing.
What is the default value of border-spacing? The initial value is 0, so adjacent cell borders sit with no extra gap until you set a length.
Why is my border-spacing not working? It only applies when border-collapse is separate. If the table uses collapse, spacing is ignored. Set border-collapse: separate on the table.
Does border-spacing work on flex or grid? No. It applies only to table and inline-table elements. Use the gap property for Flexbox and Grid.
Is border-spacing inherited? Yes. It is inherited, so nested tables can pick up the parent's spacing unless you override it.
Which browsers support border-spacing? It is Baseline and widely available in all modern browsers and Internet Explorer. It is a browser CSS property, not a Node.js feature.
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
Helpful Share Copy link Suggestion