CSS Portal

CSS border-spacing Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The border-spacing property controls the amount of space between adjacent cells in a table when the table uses the separated borders model. It creates a visible gap between the outer edges of neighboring cell borders so that the table's background (or whatever sits behind the cells) is exposed in that gap rather than the cell backgrounds being contiguous. This property only has an effect when the table is not using collapsed borders - see border-collapse for how the two border models differ.

At a conceptual level, border-spacing defines independent horizontal and vertical gaps between the boxes that represent table cells, allowing different spacing in each direction if desired. Those gaps are applied outside each cell’s own border, so they do not replace cell borders or internal padding; instead they add extra separation and therefore contribute to the table’s overall width and height. Because the gaps sit between cell borders, cell backgrounds do not fill the spacing - the table background (or underlying content) shows through.

In practice, designers use border-spacing to create breathing room between cells without increasing the internal padding of cells or adjusting individual cell margins. It’s a convenient way to control the visual rhythm of a table - for example to make grid data easier to scan - while keeping borders and cell contents unchanged. Keep in mind that using spacing influences layout calculations, so when precise alignment or fixed table sizing is required you may need to combine it thoughtfully with other layout choices or use alternative techniques.

Definition

Initial value
0
Applies to
'table' and 'inline-table' elements*
Inherited
Yes
Computed value
Two absolute lengths
Animatable
No
JavaScript syntax
object.style.borderSpacing

Interactive Demo

Bananas5 Dollars
Bananas10 Dollars
Oranges2 Dollars
Grapes3 Dollars

Syntax

border-spacing: <length> <length>? | inherit

Values

  • <length>The distance that separates adjoining cell borders. If one length is specified, it gives both the horizontal and vertical spacing. If two are specified, the first gives the horizontal spacing and the second the vertical spacing. Lengths may not be negative.

Example

<div class="table-wrapper">
<table class="spaced-table">
<caption>Border-spacing example</caption>
<thead>
<tr>
<th>Item</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>Apple</td>
<td>$1.00</td>
</tr>
<tr>
<td>Orange</td>
<td>$1.25</td>
</tr>
<tr>
<td>Banana</td>
<td>$0.75</td>
</tr>
</tbody>
</table>
<p class="note">This table uses <code>border-spacing: 12px 8px</code> (horizontal vertical).</p>
</div>
/* Basic page styles */
body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
    background: #f7f9fc;
    color: #0f1720;
    padding: 24px;
}

.table-wrapper {
    max-width: 480px;
    margin: 0 auto;
}

.spaced-table {
    width: 100%;
    border-collapse: separate; /* required for border-spacing */
    border-spacing: 12px 8px; /* horizontal vertical */
    background: transparent;
}

.spaced-table caption {
    padding: 8px 12px;
    font-weight: 600;
    text-align: left;
    color: #0b2b4a;
}

.spaced-table th,
.spaced-table td {
    padding: 10px 12px;
    background: #ffffff;
    border: 1px solid #dfe7ef;
    border-radius: 6px;
    text-align: left;
}

.spaced-table tbody tr td {
    background: #fbfdff;
}

.note {
    margin-top: 10px;
    font-size: 13px;
    color: #3b4852;
}

Browser Support

The following information will show you the current browser support for the CSS border-spacing property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!