Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

border-spacing — spacing between table cells

The border-spacing property sets the distance between table cell borders in the separated-border model. It accepts one length for both directions or two lengths: horizontal followed by vertical.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

border-spacing: <length [0,∞]>{1,2};

border-spacing sets the gap between neighboring table cell borders. Set it on the table; it works with border-collapse: separate and does not affect spacing with border-collapse: collapse.

One length sets both directions. With two lengths, the first is horizontal and the second vertical: border-spacing: 12px 6px. Values must be nonnegative; percentages are not allowed. The initial value is 0, and the property is inherited.

Spacing also occurs at the outer edges of the cell grid. The distance from the table border's inner edge to an outermost cell border is the relevant spacing plus the table's padding. Cell padding, by contrast, creates space inside the cell border.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>border-spacing</title>
<style>
  table {
    border-collapse: separate;
    border-spacing: 12px 6px;
    border: 2px solid black;
    padding: 0;
  }
  td {
    border: 1px solid black;
    padding: 4px;
  }
</style>
<table aria-label="Example">
  <tr><td>A</td><td>B</td></tr>
  <tr><td>C</td><td>D</td></tr>
</table>
</html>

Result

A B
C D

Cell-border gaps: 12px horizontally, 6px vertically.
Outer cell borders to inner table border: 12px horizontally, 6px vertically.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources