The HTML DOM borderSpacing property is used for setting or returning the space between table cells.
Following is the syntax for −
Setting the borderSpacing property −
object.style.borderSpacing = "length length|initial|inherit"
The above properties are explained as follows −
Value | Description |
---|---|
length length | It is used for specifying the space between cells. If only one value is given then it is set to both horizontal and vertical spacing otherwise the first value is for horizontal spacing and the second for vertical. Its default value is set to 0. |
Initial | For setting this property to initial value. |
Inherit | To inherit the parent property value |
Let us look at an example for the borderSpacing property −
Example
<!DOCTYPE html> <html> <head> <style> div { display: flex; float: left; } table { border: 3px solid black; } td { border: 3px solid lightgreen; } th { border: 3px solid lightblue; } </style> <script> function IncreaseBorderSpacing(){ document.getElementById("t1").style.borderSpacing="10px 10px"; document.getElementById("Sample").innerHTML="The table border spacing is now increased "; } </script> </head> <body> <table id="t1"> <tr> <th>FRUITS</th> <th>PRICE </th> </tr> <tr> <td>MANGO </td> <td>40</td> </tr> <tr> <td>APPLE</td> <td>50</td> </tr> </table> <p>Increase the above table border spacing by clicking the below button</p> <button onclick="IncreaseBorderSpacing()">Increase Border Spacing</button> <p id="Sample"></p> </body> </html>
Output
On clicking the “Increase Border Spacing” button& −