HTML DOM Style borderSpacing Property


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 −

ValueDescription
length lengthIt 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.
InitialFor setting this property to initial value.
InheritTo inherit the parent property value

Let us look at an example for the borderSpacing property −

Example

 Live Demo

<!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& −

Updated on: 23-Oct-2019

36 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements