Usage of CSS border-collapse property

The border-collapse CSS property controls how adjacent table cell borders are displayed. It determines whether borders should merge together or remain separate.

Syntax

border-collapse: collapse | separate | initial | inherit;

Values

Value Description
collapse Adjacent borders are merged into a single border
separate Each cell maintains its own borders (default)
initial Sets to default value (separate)
inherit Inherits from parent element

Example

Here's a comparison showing both collapse and separate values:

<html>
    <head>
        <style>
            table.one {
                border-collapse: collapse;
                margin: 10px 0;
            }
            table.two {
                border-collapse: separate;
                margin: 10px 0;
            }
            td.a {
                border-style: dotted;
                border-width: 2px;
                border-color: #000000;
                padding: 20px;
            }
            td.b {
                border-style: solid;
                border-width: 2px;
                border-color: #333333;
                padding: 20px;
            }
        </style>
    </head>
    <body>
        <table class="one">
            <caption>Border Collapse</caption>
            <tr><td class="a">India</td></tr>
            <tr><td class="b">Australia</td></tr>
        </table>
        
        <table class="two">
            <caption>Border Separate</caption>
            <tr><td class="a">India</td></tr>
            <tr><td class="b">Australia</td></tr>
        </table>
    </body>
</html>

How It Works

With border-collapse: collapse, adjacent cell borders merge into a single line. The browser chooses the "winning" border style based on width, style priority, and color.

With border-collapse: separate, each cell maintains its individual borders, creating double borders where cells meet.

Common Use Cases

  • Data tables: Use collapse for clean, professional-looking tables
  • Layout grids: Use separate when you want distinct cell boundaries
  • Form layouts: collapse creates seamless input field arrangements

Conclusion

The border-collapse property is essential for table styling. Use collapse for clean data tables and separate when you need distinct cell borders.

Updated on: 2026-03-15T23:18:59+05:30

84 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements