You are here: Reference > JavaScript > client-side > HTML DOM > properties > cellSpacing (table)

cellSpacing property (table)

Browser support:
Sets or retrieves the amount of space between the border of the cells in a table.
Use the cellPadding property if you want to set the space between the border and contents of the cell.

Syntax:

object.cellSpacing;
You can find the related objects in the Supported by objects section below.
This property is read/write.
HTML page for this property: cellSpacing

Possible values:

Sets or retrieves the amount of space between cells.
One of the following values:
pixel offset
Integer with or without a px (pixel) designator.
percentage
Integer higher than or equal to 0 , with a % designator.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the cellSpacing attribute:
Table, with 10px cellspacing:
<table border="3px" cellspacing="10px">
    <tr>
        <td>Apple</td>
        <td>Pear</td>
        <td>Peach</td>
    </tr>
</table>

<br /><br />

Table, without cellspacing:
<table border="3px" cellspacing="0px">
    <tr>
        <td>Apple</td>
        <td>Pear</td>
        <td>Peach</td>
    </tr>
</table>
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the cellSpacing property:
<head>
    <script type="text/javascript">
        function SetCellSpacing () {
            var input = document.getElementById ("myInput");
            var table = document.getElementById ("myTable");
            table.cellSpacing = input.value;
        }
    </script>
</head>
<body>
    <table id="myTable" border="3px" cellspacing="10px">
        <tr>
            <td>Apple</td>
            <td>Pear</td>
            <td>Peach</td>
        </tr>
    </table>

    <input id="myInput" type="text" value="20" />
    <button onclick="SetCellSpacing ();">Set cellSpacing!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content