CSS border-spacing Property

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

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.

CSS Syntax

syntax.css
border-spacing: <length> | <length> <length> | initial | inherit;

One non-negative length for both axes, or two lengths: horizontal then vertical. Negative values are invalid.

Property Values

ValueDescriptionTry it
One <length>Same gap horizontally and vertically, such as 10pxTry it
Two <length>sFirst: space between columns. Second: space between rowsTry it
0No extra gap. Initial value. Cells can still have separate bordersTry it
1emSpacing relative to the table’s font sizeTry it
initialSets this property to its default value, 0Try it
inheritInherits this property from the parent. Useful because spacing is inherited by defaultTry it

How to Use border-spacing

Use the separate border model, then set how far cell borders sit apart.

  1. Build a real <table> (or an element with display: table).
  2. Set border-collapse: separate. Spacing does nothing in the collapse model.
  3. Give cells a visible border so the gaps are easy to see.
  4. Set border-spacing to one length, or two lengths for horizontal then vertical.
PieceRequired?Role
Table elementYesOnly table / inline-table use this property
border-collapse: separateYesCollapse mode ignores spacing
Cell bordersUsuallyMake the gaps between cells visible
One or two lengthsYesEqual gap, or horizontal then vertical

Live Preview

The table stays in the separate model. Change border-spacing and watch the gaps update.

border-collapse: separate is already set. Two values mean horizontal then vertical.

Table
AB
12
34

border-spacing: 12px

CSS Examples

Each snippet uses a small table with border-collapse: separate. Use Try It Yourself for a live editor.

Example 1 — Equal Spacing

One length sets the same gap between columns and between rows.

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

How It Works

  1. Stay in the separate model. border-collapse: separate allows gaps between cell borders.
  2. Set one length. border-spacing: 10px adds 10px between columns and between rows.
  3. Show the borders. Cell borders make those gaps visible.
  4. 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.

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

How It Works

  1. Keep separate borders. Collapse mode would ignore both values.
  2. First value is horizontal. 5px is the gap between cells in adjacent columns.
  3. Second value is vertical. 15px is the gap between cells in adjacent rows.
  4. 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.

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

How It Works

  1. Stay separate. Cells still have their own borders. They are not merged.
  2. Set spacing to zero. 0 removes the extra gap between those borders.
  3. Compare with collapse. Adjacent borders can look double-thick here. border-collapse: collapse would merge them into one line.
  4. 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.

collapse

Collapsed borders ignore spacing

border-collapse: collapse turns spacing off. Switch to separate when you want gaps.

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.

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.

100% Table spacing
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.

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

It sets the distance between the borders of adjacent table cells. One length sets both axes. Two lengths set horizontal then vertical spacing.
The initial value is 0, so adjacent cell borders sit with no extra gap until you set a length.
It only applies when border-collapse is separate. If the table uses collapse, spacing is ignored. Set border-collapse: separate on the table.
No. It applies only to table and inline-table elements. Use the gap property for Flexbox and Grid.
Yes. It is inherited, so nested tables can pick up the parent's spacing unless you override it.
It is Baseline and widely available in all modern browsers and Internet Explorer. It is a browser CSS property, not a Node.js feature.

Next: border-start-end-radius

Learn the logical corner radius for the start-end corner.

border-start-end-radius 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