Open In App

HTML <table> cellspacing Attribute

The HTML <table> cellspacing Attribute is used to specify the space between the cells. The cellspacing attribute is set in terms of pixels. If the cellspacing attribute is not explicitly set, most browsers will apply a default spacing of 1 pixel.

Note: The <table> cellspacing Attribute is not supported by HTML 5.



Syntax:

<table cellspacing="pixels">

Attribute Values:

Attribute Value

Description

pixels

It sets the space between the cells in terms of pixels.

Example: The implementation of table cellspacing attribute with an example.




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML table cellspacing Attribute
    </title>
    <style>
        body {
            text-align: center;
        }
 
        table {
            margin: 0 auto;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green;">
      GeeksforGeeks
      </h1>
 
    <h2>HTML table cellspacing Attribute</h2>
 
    <table border="1" cellspacing="15">
        <caption>
          Author Details
          </caption>
 
        <tr>
            <th>NAME</th>
            <th>AGE</th>
            <th>BRANCH</th>
        </tr>
        <tr>
            <td>BITTU</td>
            <td>22</td>
            <td>CSE</td>
        </tr>
        <tr>
            <td>RAM</td>
            <td>21</td>
            <td>ECE</td>
        </tr>
    </table>
</body>
 
</html>

Output:



Example 2: The implementation of table cellspacing attribute with an example.




<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0">
    <title>Cellspacing Example</title>
    <style>
        body {
            text-align: center;
        }
 
        table {
            margin: 0 auto;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green;">
      GeeksforGeeks
      </h1>
 
    <h2>Table with Cellspacing</h2>
 
    <table border="1" cellspacing="10">
        <tr>
            <td>Row 1, Cell 1</td>
            <td>Row 1, Cell 2</td>
        </tr>
        <tr>
            <td>Row 2, Cell 1</td>
            <td>Row 2, Cell 2</td>
        </tr>
    </table>
 
</body>
 
</html>

Output:

Supported Browsers:


Article Tags :