The Wayback Machine - https://web.archive.org/web/20240913212615/https://www.geeksforgeeks.org/css-border-collapse-property/
Open In App

CSS border-collapse Property

Last Updated : 23 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The border-collapse property in CSS is used to set the borders of the cell present inside the table and tells whether these cells will share a common border or not.

Syntax: 

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

Default Value: Its default value is separate. 

Property Values: 

  • separate: This property is used to set a separate border of a cell.
  • collapse: It is used to collapse adjacent cells and make a common border.
  • initial: It is used to set the border-collapse property to its default value.
  • inherit: It is used when border-collapse property inherits from its parent elements.

Example 1: In this article, we are using the above-explained property.

HTML
<!DOCTYPE html>
<html>
<head>
    <title>
        CSS border-collapse Property
    </title>

    <!-- border-collapse CSS property -->
    <style>
        table,
        td,
        th {
            border: 1px solid black;
        }

        #separateTable {
            border-collapse: separate;
        }

        #collapseTable {
            border-collapse: collapse;
        }
    </style>
</head>

<body>
    <h2>
        border-collapse: separate
    </h2>

    <table id="separateTable">
        <tr>
            <th>Author Name</th>
            <th>Contact No</th>
        </tr>
        <tr>
            <td>Geek</td>
            <td>XXXXXXXXXX</td>
        </tr>
        <tr>
            <td>GFG</td>
            <td>XXXXXXXXXX</td>
        </tr>
    </table>

    <h2>
        border-collapse: collapse
    </h2>

    <table id="collapseTable">
        <tr>
            <th>Author Name</th>
            <th>Contact No</th>
        </tr>
        <tr>
            <td>Geek</td>
            <td>XXXXXXXXXX</td>
        </tr>
        <tr>
            <td>GFG</td>
            <td>XXXXXXXXXX</td>
        </tr>
    </table>
</body>
</html>

Output: 

Example 2: Here is another example of CSS border-collapse property.

html
<!DOCTYPE html>
<html>
<head>
    <title>
        CSS border-collapse Property
    </title>

    <style>
        table,
        td,
        th {
            border: 1px solid black;
        }

        /* border spacing is used to specify the 
            width between border and adjacent cells */
        #separateTable {
            border-collapse: separate;
            border-spacing: 10px;
        }

        #collapseTable {
            border-collapse: collapse;
            border-spacing: 10px;
        }

        #initialTable {
            border-collapse: initial;
        }
    </style>
</head>

<body>
    <h2>
        border-collapse: separate
    </h2>

    <table id="separateTable">
        <tr>
            <th>Author Name</th>
            <th>Contact No</th>
        </tr>
        <tr>
            <td>Geek</td>
            <td>XXXXXXXXXX</td>
        </tr>
        <tr>
            <td>GFG</td>
            <td>XXXXXXXXXX</td>
        </tr>
    </table>

    <h2>
        border-collapse: collapse
    </h2>

    <!-- border spacing property has no
        effect on border-collapse property-->
    <table id="collapseTable">
        <tr>
            <th>Author Name</th>
            <th>Contact No</th>
        </tr>
        <tr>
            <td>Geek</td>
            <td>XXXXXXXXXX</td>
        </tr>
        <tr>
            <td>GFG</td>
            <td>XXXXXXXXXX</td>
        </tr>
    </table>

    <h2>
        border-collapse: initial
    </h2>

    <table id="initialTable">
        <tr>
            <th>Author Name</th>
            <th>Contact No</th>
        </tr>
        <tr>
            <td>Geek</td>
            <td>XXXXXXXXXX</td>
        </tr>
        <tr>
            <td>GFG</td>
            <td>XXXXXXXXXX</td>
        </tr>
    </table>
</body>
</html>

Output: 

Supported Browsers: The browser supported by border-collapse property are listed below: 

  • Google Chrome 1.0
  • Edge 12.0
  • Internet Explorer 5.0
  • Firefox 1.0
  • Opera 4.0
  • Apple Safari 1.2

CSS border-collapse Property – FAQs

What is the border-collapse property in CSS?

The border-collapse property in CSS is used in table elements to control whether the table cells share borders (collapsed) or maintain separate borders (separated).

What are the differences between border-collapse: collapse and separate?

  • collapse: Borders between table cells are merged into a single border, creating a more compact and cleaner table appearance.
  • separate: Each cell retains its own borders, resulting in a more spaced-out look.

When should I use border-collapse: collapse?

Use border-collapse: collapse when you want your table to look more streamlined, with borders shared between adjacent cells. This is often preferred for minimalist designs or when space efficiency is important.

Does border-collapse affect the padding inside table cells?

Yes, when using border-collapse: collapse, padding is applied within the collapsed borders, potentially affecting the spacing and layout of table content. In contrast, padding behaves more independently when using border-collapse: separate.

Why is my table border behaving unexpectedly with border-collapse?

Unexpected behavior sometimes arises from conflicting styles between border-spacing, border-width, or cell padding when border-collapse: collapse is applied. Carefully review these settings to achieve the desired look.



Previous Article
Next Article

Similar Reads

How to implement the border-collapse Property in CSS ?
The border-collapse property in CSS is used to control the border model for table elements. It determines whether adjacent table cell borders and spacing should be collapsed into a single border or if they should be kept separate. Note: The border-collapse property can take values like collapse and separate. Syntax:/* Collapsing table borders and s
1 min read
Tailwind CSS Border Collapse
This class accepts lots of value in tailwind CSS in which all the properties are covered in class form. This class is used to set the borders of the cell present inside the table and tells whether these cells will share a common border or not. In CSS, we can do that by using CSS border-collapse property. Syntax: &lt;element class="border-collapse"
1 min read
CSS Margin Collapse
The CSS margin property is used to set a margin on all four sides of an element. When two elements are next to each other on a page vertically, one of the elements might lose its vertical margin. This means the top and bottom margins of elements are sometimes combined into a single margin. The single margin is equal to the largest of the two margin
2 min read
What are the rules of margin collapse in CSS ?
In this article we will learn the rules of margin collapse in CSS, Margin collapsing is a behavior of CSS where the vertical margins of block-level elements are combined into one i.e. to the margin of the element with the largest value. Sometimes when we assigned margins to elements it does not work in the way we think it to and that creates confus
5 min read
Foundation CSS XY Grid Collapse Cells
Foundation CSS is an open-source &amp; responsive front-end framework built by ZURB foundation in September 2011, that makes it easy to layout stunning responsive websites, apps, and emails that appear amazing &amp; can be accessible to any device. In this article, we will discuss the XY Block Grid in Foundation CSS. The XY Grid Collapse Cells is u
2 min read
Foundation CSS Flex Grid Collapse/Uncollapse Rows
Foundation CSS is an open-source and free front-end framework that helps us in making responsive web designs. It is one of the most advanced CSS frameworks and it works on all devices providing us with a responsive grid and HTML and CSS UI components, templates, etc. It also gives some optional functionality provided by JavaScript Extensions. It al
7 min read
Which one should we use 'border: none' or 'border: 0 '?
In this article, we will learn the validity of CSS border properties. We can specify the no border property using CSS border: none, border-width : 0, border : 0 properties. Syntax: border: none | 0 Differences: border: noneborder : 0For this property, the browser does not render.For this property, the browser renders border-color and border-width p
1 min read
Bootstrap 5 Collapse
Bootstrap 5 is the latest major release by Bootstrap in which they have revamped the UI and made various changes. Collapse is used to toggle the visibility of content across your project with a few classes and the JavaScript plugins which comes with Bootstrap 5. The working of collapse component is based on class changes which are applied. For exam
3 min read
How to make a Bootstrap 4 accordion collapse when clicking the whole header div ?
In Bootstrap 4, Accordion collapse when anchor or button tag is clicked but lets see how to make a Bootstrap 4 accordion collapse when clicking the whole header with the help of following simple approach. First you have to remove anchor tag and button tag within div of class="card-header" except card title. Now add class collapsed and card-link to
2 min read
Web API Selection collapse() Method
The collapse() method is used to collapse the current selection to a single position. The collapse() method does not modify the document. Syntax: collapse(node) collapse(node, offset) Parameters: This method accepts two parameters. node: The caret location within the node. You can also pass a null in this parameter. If null specifies the method wil
2 min read
Collect.js | collapse() Method
Collect.js is a fluent and convenient wrapper for working with arrays and objects. The JavaScript array is first transformed into a collection and then the function is applied to the collection. The collapse() method convert collection of arrays into a single flat array. Installation: Collect.js can be installed via NPM: npm install --save collect.
2 min read
HTML DOM Range collapse() Method
The collapse() method collapses the Range to one of its boundary points. A collapsed Range is an empty range and doesn't contain any content. Syntax: range.collapse(boolean); Parameters: This method takes boolean value as parameter. true: Collapses the Range to its start.false: Collapses the Range to its end. Return value: This method has no return
1 min read
How to always show first two rows in dynamic collapse using Bootstrap ?
Bootstrap is an open-source front-end CSS framework used widely for the development of interactive websites. Bootstrap with HTML and JavaScript adds interactivity to the user interface. jQuery is a JS library used for the manipulation of HTML DOM, event handling, CSS animations, and Ajax. jQuery is also a free open source library used by more than
6 min read
jQuery UI menu collapse() Method
jQuery UI consists of GUI widgets, visual effects, and themes implemented using jQuery, CSS, and HTML. jQuery UI is great for building UI interfaces for the webpages. jQuery UI menu is a themeable menu that is used with mouse and keyboard interactions for navigating between pages. In this article, we will use the collapse option to collapse the act
1 min read
ReactJS UI Ant Design Collapse Component
Ant Design Library has this component pre-built, and it is very easy to integrate as well. The collapse component is used as a content area that can be collapsed and expanded. We can use the following approach in ReactJS to use the Ant Design Collapse Component. Collapse Props: accordion: It is used to collapse renders as Accordion if this value is
3 min read
Angular ngx Bootstrap Collapse Component
Angular ngx bootstrap is a bootstrap framework used with angular to create components with great styling and this framework is very easy to use and is used to make responsive websites. In this article, we will learn how to use collapse in angular ngx bootstrap. Collapse is used to make a button that will collapse by clicking on it. Installation syn
2 min read
Angular ng Bootstrap Collapse Component
Angular ng bootstrap is a bootstrap framework used with angular to create components with great styling and this framework is very easy to use and is used to make responsive websites. In this article we will know how to use Collapse in angular ng bootstrap. Collapse is used to make a button that will be collapsed by clicking on it. Installation syn
2 min read
jQWidgets jqxTabs collapse() Method
jQWidgets is a JavaScript framework for making web-based applications for PC and mobile devices. It is a very powerful and optimized framework, platform-independent, and widely supported. The jqxTabs represents a jQuery Tab widget that is used for breaking the content into multiple sections. The &lt;li&gt; elements are used for tab title and &lt;di
2 min read
jQWidgets jqxExpander collapse() Method
jQWidgets is a JavaScript framework for making web-based applications for PC and mobile devices. It is a very powerful and optimized framework, platform-independent, and widely supported. The jqxExpander represents a jQuery widget that displaying the header and content sections. Click on the header section to expand or collapse the content. The col
2 min read
jQWidgets jqxWindow collapse() Method
jQWidgets is a JavaScript framework for making web-based applications for PC and mobile devices. It is a very powerful, optimized, platform-independent, and widely supported framework. The jqxWindow is used for entering data or viewing information in an application. The collapse() method is used to collapse the contents of the current window. Synta
1 min read
jQWidgets jqxTree collapse Event
jQWidgets is a JavaScript framework for making web-based applications for pc and mobile devices. It is a very powerful, optimized, platform-independent, and widely supported framework. The jqxTree represents a jQuery widget that is used to display a hierarchical collection of items. To display the collection of items, we can populate from 'UL' or b
2 min read
jQWidgets jqxWindow collapse Event
jQWidgets is a JavaScript framework for making web-based applications for PC and mobile devices. It is a very powerful, optimized, platform-independent, and widely supported framework. The jqxWindow is used for entering data or viewing information in an application. The collapse event is triggered when the window is collapsed. Syntax: $('#jqxWindow
1 min read
jQWidgets jqxResponsivePanel collapse Event
jQWidgets is a JavaScript framework for making web-based applications for PC and mobile devices. It is a very powerful, optimized, platform-independent, and widely supported framework. The jqxResponsivePanel is a jQuery widget that is used to represent a panel widget with responsive behavior. The responsive panel is used to display the content in a
2 min read
jQWidgets jqxSplitter collapse() Method
jQWidgets is a JavaScript framework for making web-based applications for PC and mobile devices. It is a very powerful, optimized, platform-independent, and widely supported framework. The jqxSplitter is used for representing a widget that consists of a moveable split bar(s) that divides the display area of the container into two or more resizable
2 min read
jQuery Mobile Collapsible collapse Events
jQuery Mobile is a web-based technology used to make responsive content that can be accessed on all smartphones, tablets, and desktops. In this article, we will be using the jQuery Mobile Collapsible collapse event to trigger when a collapsible widget is collapsed. Syntax: Initialize the collapsible with the collapse callback specified: $( ".select
1 min read
jQuery Mobile Collapsible collapse() Method
jQuery Mobile is a web-based technology that can be used to make responsive content for websites that can be accessed on all types of smartphones, tablets, and desktops. In this article, we will be using the jQuery Mobile Collapsible collapse() method to collapse the collapsible. It does not accept any parameter. Syntax: $( ".selector" ).collapsibl
1 min read
React.js Blueprint Collapse Component Props
BlueprintJS is a React-based UI toolkit for the web. This library is very optimized and popular for building interfaces that are complex data-dense for desktop applications. Collapse Component provides a way for users to show and hide content with a built-in slide-in/out animation. In this article, we will create a UI that will showcase React.js Bl
3 min read
Angular PrimeNG OrganizationChart Expand/Collapse State
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. It provides a lot of templates, components, theme design, an extensive icon library, and much more. In this article, we will see the Angular PrimeNG O
4 min read
React MUI Collapse API
The Material-UI is an open-source library for Creating user interfaces with Material Design principles in React. Material Design is a design language that provides a consistent look and feel on all platforms and devices. Material-UI provides a set of pre-built components, making it easier for developers to create beautiful and consistent UI. The Ma
5 min read
Bootstrap 5 Collapse SASS
Bootstrap5 Collapse SASS can be used to change the default value of transition duration and transition timing of the height property collapsible component. SASS variables of Collapse:$transition-collapse: This variable provides the transition duration and the transition timing function in which the transition is displayed. By default, the height pr
3 min read