AD JB Toolbox 01 EN

CSS / Reference / border-spacing: Separate Cell Gaps and Collapsed Borders

border-spacing sets gaps between neighboring cell borders in a table using separate borders. One length sets both axes; two lengths specify horizontal then vertical spacing.

Syntax and value choices

Property Initial value Inherited Main application conditions
border-spacing 0 Yes Tables in the separated-border model

Initial values are not necessarily the values assigned to HTML elements by the browser’s stylesheet. Inspect the actual result in developer tools’ Computed panel.

table { border-collapse: separate; border-spacing: 12px 6px; }
Value or category Behavior and choice
0 Keep separate borders with no gap.
12px Use a 12px gap on both axes.
12px 6px Use 12px horizontally and 6px vertically.
collapse Use the collapsed-border model rather than cell spacing.

For supported values and conditions, see MDN border-spacing.

Run the example and compare results

Save this complete code as css-reference-10618-example.html in UTF-8 and open it in a browser. Keep its demonstration styles in that file rather than pasting them into a site-wide stylesheet.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>border-spacing comparison example</title>
<style>
body { margin: 0; color: #20242b; background: #fff; font: 16px/1.7 "Malgun Gothic", sans-serif; }
#demo { padding: 24px; max-width: 820px; margin: auto; }
h1 { font-size: 22px; margin: 0 0 20px; }
.samples { display: flex; flex-wrap: wrap; gap: 24px; }
.label { margin: 0 0 8px; font-weight: 700; }
table { border-collapse: separate; border: 2px solid #333; }
td { padding: 10px; border: 2px solid #006c9c; }
.target { border-spacing: 12px 6px; }
.reference { border-spacing: 0; }
</style>
</head>
<body>
<main id="demo">
<h1>border-spacing comparison</h1>
<section class="samples"><div><p class="label">12px 6px</p><table class="target"><tbody><tr><td>Content</td><td></td></tr><tr><td>Second</td><td>Value</td></tr></tbody></table></div><div><p class="label">0</p><table class="reference"><tbody><tr><td>Content</td><td></td></tr><tr><td>Second</td><td>Value</td></tr></tbody></table></div></section>
</main>
</body>
</html>

The first table has 12px horizontal and 6px vertical gaps. The zero-spacing table still has separate borders; zero gaps do not merge them as collapse does.

border-spacing browser comparison showing the specified and reference values in the same example

Cell padding versus gaps

Cell padding separates content from its own border. Border spacing separates neighboring borders. The space between the table’s outer border and edge cells also involves table padding and spacing.

Initial values versus browser styles

The property’s initial value is zero, even though a browser stylesheet may assign table spacing such as 2px. Explicitly set the border model and gap when the exact result matters.

Change one setting at a time

Use the complete example file above. Change only the specified selector or value rather than several comparison conditions at once.

  1. Keep zero spacing on .reference but switch to collapse. Border conflict treatment changes; zero gaps and collapsed borders are not the same. Restore separate.
  2. Reverse the first table’s gap to 6px 12px, observe the axis change, and restore 12px 6px without changing cell padding.

For table-wide sizing and cell layout, see CSS Tables: Borders, Sizing, and table-layout. Related properties to compare alongside these conditions are empty-cells.

When the result is missing or unexpected

  • Check for a theme rule forcing border-collapse: collapse.
  • Use supported nonnegative lengths rather than negative or percentage gaps.
More in This Category
CSS / Reference / text-indent: First-Line Indents and Hanging Paragraphs

CSS / Reference / text-indent: First-Line Indents and Hanging Paragraphs

Create first-line and hanging indents, distinguish them from paragraph padding, and check inheritance, writing direction, and narrow-screen clipping.

CSS / Reference / border-spacing: Separate Cell Gaps and Collapsed Borders

CSS / Reference / border-spacing: Separate Cell Gaps and Collapsed Borders

Set horizontal and vertical gaps in separate-border tables. Distinguish cell padding, zero spacing, collapsed borders, and browser default styles.

CSS / Reference / font-size: Understand px, em, rem, and Text Enlargement

CSS / Reference / font-size: Understand px, em, rem, and Text Enlargement

Choose text-size units by their reference and test nested em scaling. Check the actual root size, browser enlargement, and layout constraints.

CSS / Reference / background-repeat: Tiling, Space, and Round

CSS / Reference / background-repeat: Tiling, Space, and Round

Control horizontal and vertical background tiling and compare repeat, no-repeat, space, and round with the same tile and positioning area.

CSS / Reference / empty-cells: Show or Hide Empty Table Cells

CSS / Reference / empty-cells: Show or Hide Empty Table Cells

Control empty-cell borders and backgrounds in a separated table while preserving its structure. Compare show, hide, whitespace, and the collapsed-border exception.

CSS / Reference / font-weight: Numeric Weights, Relative Weights, and Font Matching

CSS / Reference / font-weight: Numeric Weights, Relative Weights, and Font Matching

Request numeric or relative font weights and inspect the supplied faces. Compare static and variable-font behavior without assuming every number produces a unique weight.

CSS / Reference / letter-spacing, word-spacing: Compare Character and Word Spacing

CSS / Reference / letter-spacing, word-spacing: Compare Character and Word Spacing

Adjust character and word gaps independently using the same text and a normal baseline. Account for inheritance, language, wrapping, and excessive negative spacing.

CSS / Reference / background-origin: Positioning References Versus Painting Boundaries

CSS / Reference / background-origin: Positioning References Versus Painting Boundaries

Choose a background image’s positioning box and distinguish it from background-clip. Compare how padding, borders, percentage sizes, and fixed attachment affect the reference.

CSS / Reference / content: Generate Pseudo-Element Text and Decoration

CSS / Reference / content: Generate Pseudo-Element Text and Decoration

Generate strings, attribute labels, counters, and decorative pseudo-elements. Compare none with an empty string and retain important information in real HTML.

CSS / Reference / white-space: Preserve Spaces, Line Breaks, and Wrapping

CSS / Reference / white-space: Preserve Spaces, Line Breaks, and Wrapping

Choose whitespace behavior by preservation and wrapping needs. Compare traditional values and break-spaces, and handle long words with separate wrapping properties.