border-spacing

Sets the gap between table cells with separated borders.

Initial value
0
Inherited
Yes
Animatable
yes, as a length
Applies to
tables with border-collapse: separate
JavaScript
element.style.borderSpacing = "8px"
On this page

Example

#
CSS
.calendar {
  border-collapse: separate;
  border-spacing: 4px;
}

.calendar td {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: #1f1f23;
  text-align: center;
}
Preview

Definition and usage

#

The border-spacing property sets the distance between the borders of adjacent table cells. It only works with border-collapse: separate.

One value sets the same gap horizontally and vertically, two values set them separately: horizontal first, then vertical.

It lets a table look like a grid of tiles, for example a calendar or a progress table, with gaps between cells.

Syntax

#
Syntax
border-spacing: <length> <length>?;

Values

#
  • 0

    Cell borders touch each other.
  • 6px

    An even 6px gap between cells.
  • 16px 4px

    Wide horizontal gaps, narrow vertical ones.

Values in practice

#

0

Cell borders touch each other.
.demo { border-spacing: 0; }

6px

An even 6px gap between cells.
.demo { border-spacing: 6px; }

16px 4px

Wide horizontal gaps, narrow vertical ones.
.demo { border-spacing: 16px 4px; }

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • If the gap doesn’t work, check whether the table has border-collapse: collapse.
  • Gaps between cells make nice grids, but in data tables they make rows harder to read.

Related entries

#

Spotted a mistake or missing an example? Write to us.