border-spacing
Specifies the spacing between cells when the 'border-collapse' property is set to 'separate'.
When one value is specified, it applies to all four sides (top, right, bottom, left).
When two values are specified, the first value sets the horizontal spacing (left and right) and the second sets the vertical spacing (top and bottom).
Sample Code
table.test { border-spacing: 10px;}
table.test1 { border-spacing: 20px 10px;}
Available Values
| Value | Description |
|---|---|
| Number | Specifies the spacing as a number. You can use units such as 'px' or 'em', but '%' and negative values are not allowed. The initial value is '0'. |
Browser Preview
The table element in the sample below has 'border-collapse: separate' and 'border: solid 1px #f00', and each td element has 'border: solid 1px #00f' and 'border: solid 1px #0f0' respectively.
<table style=" border-spacing: 10px; border-collapse: separate; border: solid 1px #f00; margin: 0 auto;"> <tr><td style="border: solid 1px #00f;">This is a td element.</td><td style="border: solid 1px #0f0;">This is a td element.</td></tr> <tr><td style="border: solid 1px #0f0;">This is a td element.</td><td style="border: solid 1px #00f;">This is a td element.</td></tr> </table>
<table style=" border-spacing: 20px 10px; border-collapse: separate; border: solid 1px #f00; margin: 0 auto;"> <tr><td style="border: solid 1px #00f;">This is a td element.</td><td style="border: solid 1px #0f0;">This is a td element.</td></tr> <tr><td style="border: solid 1px #0f0;">This is a td element.</td><td style="border: solid 1px #00f;">This is a td element.</td></tr> </table>
Browser Compatibility
8 ○
7 ×
6 ×
3 and below ×
Android Browser
4.4+ ○
3 and below ×※ Version information is based on MDN.
Overview
Specifies the spacing between table cells.
For 'border-spacing' to take effect, the 'border-collapse' property must be set to 'separate'.
'border-spacing' can only be applied to table or inline-table elements.
If you find any errors or copyright issues, please contact us.