HTML - DOM Style Object borderCollapse Property



HTML DOM Style Object borderCollapse property specifies whether table cell elements should have separate borders or share a single border that is collapsed into a single border.

Syntax

Given below are the syntax to get or set the borderCollapse property.

Set the borderCollapse property:
object.style.borderCollapse= "separate | collapse | initial | inherit" ;
Get the borderCollapse property:
object.style.borderCollapse;

Property Values

ValueDescription
separateIt specifies table cell elements will have separate borders. It is the default value.
collapseIt specifies table cell elements will have single border or collapsed into one border.
initialIt is used to set this property to it's default value.
inheritIt is used to inherit the property of it's parent element.

Return Value

It returns a string value which represents border of table.

Example of HTML DOM Style Object 'borderCollapse' Property

The following example sets border collapse and separate property values.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object borderCollapse Property
    </title>
    <style>
        table {
            border: aqua 2px solid;
        }
    </style>
</head>
<body>
    <p>
        Click to collapse or separate table Border.
    </p>
    <button onclick="fun()">Collapse</button>
    <button onclick="funtwo()">Separate</button>
    <br><br><br><br>
    <table id="border" border="1">
        <tr>
            <td>This is</td>
            <td>is</td>
        </tr>
        <tr>
            <td>an example</td>
            <td>table</td>
        </tr>
        <tr>
            <td>for</td>
            <td>collapse</td>
        </tr>
    </table>
    <script>
        function fun() {
            document.getElementById("border")
                .style.borderCollapse = "collapse";
        }
        function funtwo() {
            document.getElementById("border")
                .style.borderCollapse = "separate";
        }
    </script>
</body>
</html>

Supported Browsers

PropertyChromeEdgeFirefoxSafariOpera
borderCollapseYes 1Yes 12Yes 1Yes 1.2Yes 4
html_dom.htm