CSS border-spacing Property

You are Here:

CSS border-spacing Property

CSS border-spacing property sets the distance between the borders of adjacent <table> cells.

Note: This property applies only when border-collapse is separate.


HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <head> <style> table, td, th{ border: 1px solid black; } table{ border-spacing: 20px 10px; } </style> </head> <body> <h1>CSS border-spacing Property</h1> <table> <tr> <th>Name</th> <th>Age</th> </tr> <tr> <td>Jos</td> <td>28</td> </tr> <tr> <td>Alex</td> <td>34</td> </tr> </table> </body> </html>


Using CSS

element{ border-spacing: 10px; }

Using Javascript



Yes, border-spacing property is animatable. CSS Animatable Properties Reference.

Default Value

Default value for CSS border-spacing property is 2px.

Property Value

The following table provides a list of values for CSS border-spacing property.

length lengthAllows you to define the spacing of the border in any CSS length unit.
  • Negative values are not allowed.
  • If two values are specified, the first sets the horizontal spacing and the second sets the vertical spacing.
  • If one value is specified, it defines both the horizontal and vertical spacing between cells.

Using JavaScript

In the following example, we will demonstrate how to change the CSS border-spacing property of an element using JavaScript.


HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <head> <style> table, td, th{ border: 1px solid black; } </style> </head> <body> <h1>CSS border-spacing Property</h1> <table> <tr> <th>Name</th> <th>Age</th> </tr> <tr> <td>Jos</td> <td>28</td> </tr> <tr> <td>Alex</td> <td>34</td> </tr> </table> <button onclick="myFunction()">Click Me</button> <script> var x = document.getElementsByTagName("table")[0]; function myFunction(){ x.style.borderSpacing = "20px 10px"; } </script> </body> </html>


Hi Developers, we almost covered 98.7% of CSS Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in CSS.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author