CSS Reference ยท Borders, Outlines and Shadows
The border-spacing property
Reference for the CSS border-spacing property: set horizontal and vertical gaps between table cells in the separate border model, with a live example.
The border-spacing property sets the distance between the borders of adjacent table cells (and between the cells and the table's own border). It only works when border-collapse is separate, which is the default. With collapse the property is ignored.
One value sets the same gap in both directions; two values set the horizontal gap first and the vertical gap second. The gap is not part of any cell, so cell backgrounds do not fill it: you see the table's background (or the page) through it.
table { border-spacing: 8px 4px; }
Try it
Syntax
border-spacing: <length> <length>?;
- Initial value:
0(browsers' built-in stylesheet gives tables a small default gap, commonly2px) - Applies to: table and inline-table elements
- Inherited: yes
- Animatable: yes, as a length
- Computed value: two absolute lengths
Values
| Value | Description |
|---|---|
One <length> |
The gap between cells in both directions. |
Two <length> values |
Horizontal gap first, then vertical gap. |
Percentages and negative lengths are not allowed.
Usage notes
- The default gap you see comes from the browser's own style sheet, not from the initial value. Resetting it needs an explicit
border-spacing: 0. - Not used in collapsed tables. To get cell separation with
border-collapse: collapse, use padding or borders in the background colour instead. - Outer gap. The spacing also appears between the outer cells and the table's border, so a table with spacing is wider than the sum of its columns.
- Set it on the table. Because it is inherited, you can set it on any ancestor, but the table is the only element that uses it.
- Row-by-row control is not possible; the gap is uniform for the whole table.
Browser support
Supported in every browser.
Related
border-collapseโ turn off separate borderstable-layout,empty-cellspadding- Lesson: Styling Tables