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

cellPadding property (table)

Browser support:
Specifies or returns the amount of space between the border of a cell and its contents in a table.
Use the cellSpacing property if you want to set the space between cells.

Syntax:

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

Possible values:

Sets or retrieves the amount of space between the border of the cell and its contents.
One of the following values:
offset in pixels
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 cellPadding attribute:
Table, with 10px cellpadding:
<table border="3px" cellpadding="10px">
    <tr>
        <td>Apple</td>
        <td>Pear</td>
        <td>Peach</td>
    </tr>
</table>

<br /><br />

Table, without cellpadding:
<table border="3px" cellpadding="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 cellPadding property:
<head>
    <script type="text/javascript">
        function SetCellPadding () {
            var input = document.getElementById ("myInput");
            var table = document.getElementById ("myTable");
            table.cellPadding = input.value;
        }
    </script>
</head>
<body>
    <table id="myTable" border="3px" cellpadding="10px">
        <tr>
            <td>Apple</td>
            <td>Pear</td>
            <td>Peach</td>
        </tr>
    </table>

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

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content