CSS border-collapse Property

The border-collapse property determines whether the borders of adjacent table cells remain separate or combine into a single shared border.

It accepts two values: separate and collapse. The property affects the table's border model, including spacing between cells, border conflict resolution, and how borders are drawn around rows and columns.

border-collapse Syntax

selector {
  border-collapse: collapse;
}

The property accepts one of two keywords:

.separate-table {
  border-collapse: separate;
}
.collapsed-table {
  border-collapse: collapse;
}

CSS-wide keywords are also supported:

.inherited {
  border-collapse: inherit;
}
.reset {
  border-collapse: initial;
}
.unset {
  border-collapse: unset;
}
.reverted {
  border-collapse: revert;
}
.layer-reverted {
  border-collapse: revert-layer;
}

Only one value is permitted. The values separate and collapse cannot be combined in the same declaration.

Property Values

Value Description
separate Uses the separate border model. Each table cell has its own border, and spacing may exist between adjacent cells. This is the initial value.
collapse Uses the collapsed border model. Adjacent table borders are resolved into shared borders according to conflict resolution rules.

CSS-Wide Keywords

Keyword Behavior
inherit Uses the parent's computed border-collapse value.
initial Resets the property to separate.
unset Inherits the parent's computed value because this property is inherited.
revert Reverts the property according to cascade origin rules.
revert-layer Reverts the property according to cascade layer rules.

The initial value is separate. The property is inherited, applies to table and inline-table boxes, and is animated discretely.

How It Works

HTML tables are organized into rows and cells. The border-collapse property determines whether those cells display individual borders or share borders with neighboring cells.

Separate Borders

table {
  border-collapse: separate;
}
th, td {
  border: 2px solid #1769aa;
}

Each cell retains its own border. The space between cells is controlled by border-spacing.

Collapsed Borders

table {
  border-collapse: collapse;
}
th, td {
  border: 2px solid #1769aa;
}

Adjacent cells share a single border rather than displaying two separate borders.

Comparison

Behavior separate collapse
Adjacent cell borders Remain independent Share a resolved border
border-spacing Applies Does not apply
Border conflicts No shared-border conflicts Resolved by CSS rules
empty-cells Can affect empty cells Has no effect
Common appearance Separated cell boxes Continuous table grid

Both models are valid. The appropriate choice depends on whether the design requires gaps between cells or continuous grid lines.

Separate Border Model

With border-collapse: separate, each table cell has its own border. Borders belonging to neighboring cells do not merge.

Basic Separate Borders

table {
  border-collapse: separate;
  border-spacing: 4px;
}
th, td {
  border: 1px solid #1769aa;
  padding: 10px;
}

Each cell has an individual border, with a 4-pixel gap between neighboring cells.

Removing the Gap

table {
  border-collapse: separate;
  border-spacing: 0;
}
th, td {
  border: 1px solid #1769aa;
}

Setting border-spacing to zero removes the gaps, but the borders remain separate. Two adjacent 1-pixel cell borders can appear as a 2-pixel dividing line.

Different Cell Border Colors

table {
  border-collapse: separate;
  border-spacing: 6px;
}
th {
  border: 2px solid #1769aa;
}
td {
  border: 2px solid #777;
}

Each cell retains its own border color and style without competing with neighboring cells.

Rounded Cell Corners

table {
  border-collapse: separate;
  border-spacing: 8px;
}
td {
  border: 1px solid #1769aa;
  border-radius: 8px;
  padding: 12px;
}

The separate border model allows each cell to display its own rounded border. Rounded corners are not generally applied to individual cells in the collapsed border model.

Collapsed Border Model

With border-collapse: collapse, adjacent table cells share borders. The browser determines which border is displayed when multiple declarations apply to the same edge.

Basic Collapsed Borders

table {
  border-collapse: collapse;
}
th, td {
  border: 1px solid #1769aa;
  padding: 10px;
}

The result is a continuous grid with a single border between adjacent cells.

Different Border Widths

table {
  border-collapse: collapse;
}
td {
  border: 1px solid #777;
}
td.important {
  border: 4px solid #1769aa;
}

Where a 4-pixel border competes with a 1-pixel border, the thicker border wins unless a hidden border suppresses the shared edge.

Different Border Styles

table {
  border-collapse: collapse;
}
td {
  border: 2px dashed #777;
}
td.highlight {
  border: 2px solid #1769aa;
}

When borders have equal widths, the border style is considered. A solid border takes precedence over a dashed border.

Border Spacing Is Ignored

table {
  border-collapse: collapse;
  border-spacing: 20px;
}

The border-spacing declaration does not create gaps when the collapsed border model is active.

Table Border

table {
  border-collapse: collapse;
  border: 3px solid #1769aa;
}
th, td {
  border: 1px solid #777;
}

The table's outer border participates in the collapsed border conflict rules along its perimeter.

Border Spacing

The border-spacing property controls the distance between adjacent cell borders in the separate border model.

Equal Horizontal and Vertical Spacing

table {
  border-collapse: separate;
  border-spacing: 8px;
}

The table has 8 pixels of spacing horizontally and vertically between adjacent cells.

Different Horizontal and Vertical Spacing

table {
  border-collapse: separate;
  border-spacing: 12px 6px;
}

The first value controls horizontal spacing, and the second controls vertical spacing.

Zero Spacing

table {
  border-collapse: separate;
  border-spacing: 0;
}

Adjacent cell borders touch but do not collapse into one border.

Collapsed Borders Ignore Spacing

table {
  border-collapse: collapse;
  border-spacing: 12px;
}

The specified spacing has no effect while the collapsed border model is active.

Spacing and Table Edges

In the separate border model, spacing also exists between the table's edge and the cells along its perimeter. This contributes to the table's overall dimensions.

Use border-spacing with separate when visible gaps are required. Use collapse when adjacent cells should form a continuous grid.

Border Conflict Resolution

In the collapsed border model, a shared edge may receive border declarations from adjacent cells, rows, row groups, columns, column groups, or the table itself.

CSS uses conflict resolution rules to determine which border is drawn.

Step 1: hidden Takes Precedence

td {
  border: 2px solid #777;
}
td.no-divider {
  border-right-style: hidden;
}

A hidden border suppresses all competing borders along the shared edge.

Step 2: none Has the Lowest Priority

td {
  border: 2px solid #777;
}
td.no-border {
  border-right-style: none;
}

A competing visible border takes precedence over none. If every competing border uses none, no border is drawn.

Step 3: Wider Borders Win

td {
  border: 2px solid #777;
}
td.emphasized {
  border-right: 5px solid #1769aa;
}

The 5-pixel border wins over the 2-pixel border when they compete along the same edge.

Step 4: Border Style Breaks Width Ties

td {
  border: 3px dashed #777;
}
td.emphasized {
  border-right: 3px solid #1769aa;
}

When the competing borders have equal widths, the solid style wins over the dashed style.

Step 5: Element Origin Breaks Remaining Ties

If competing borders have the same width and style but different colors, the border associated with the more specific table element takes precedence.

The priority order is cell, row, row group, column, column group, and table.

When competing borders still have equal priority, their position within the table determines which border is used, following the writing direction and table border conflict rules.

These rules apply to the collapsed border model. Separate borders do not require shared-edge conflict resolution.

Border Style Precedence

When competing collapsed borders have equal widths, CSS compares their styles to determine which border wins.

Style Priority

Priority Border Style
1 hidden - suppresses the shared border
2 double
3 solid
4 dashed
5 dotted
6 ridge
7 outset
8 groove
9 inset
10 none - lowest priority

The hidden style is a special case that suppresses the border regardless of competing widths. The none style loses to any competing visible border.

Equal-Width Style Conflict

table {
  border-collapse: collapse;
}
td {
  border: 3px dashed #777;
}
td.highlight {
  border-left: 3px solid #1769aa;
}

Where the solid and dashed borders compete, the solid border is displayed.

Wider Border Takes Precedence

td {
  border: 6px dotted #777;
}
td.highlight {
  border-left: 2px solid #1769aa;
}

The 6-pixel dotted border wins over the 2-pixel solid border because width takes precedence over style among visible borders.

Three-Dimensional Styles

In the collapsed border model, inset is rendered like ridge, while outset is rendered like groove. Their conflict priorities remain governed by the border conflict rules.

Table Elements and Borders

Table borders can be specified on several table-related elements. Their effects depend on the active border model.

Borders on Table Cells

table {
  border-collapse: collapse;
}
th, td {
  border: 1px solid #1769aa;
}

Cell borders are the most common way to create a continuous table grid.

Borders on Table Rows

table {
  border-collapse: collapse;
}
tr {
  border-bottom: 2px solid #1769aa;
}

In the collapsed border model, row borders can contribute to the shared borders between rows.

Borders on Row Groups

table {
  border-collapse: collapse;
}
thead {
  border-bottom: 3px solid #1769aa;
}

The table header group can contribute a stronger divider between the header and body.

Borders on Columns

table {
  border-collapse: collapse;
}
col.highlight {
  border-right: 3px solid #1769aa;
}

Column borders can participate in collapsed border conflict resolution.

Borders on the Table

table {
  border-collapse: collapse;
  border: 3px solid #1769aa;
}

The table border participates in conflict resolution along the outer edges.

In the separate border model, row, row group, column, and column group borders do not create the same shared-border effects. For predictable separated tables, apply visible borders directly to the table and its cells.

Empty Cells

The empty-cells property controls whether borders and backgrounds are displayed for empty table cells in the separate border model.

Showing Empty Cells

table {
  border-collapse: separate;
}
td {
  border: 1px solid #1769aa;
  empty-cells: show;
}

Empty cells display their borders and backgrounds.

Hiding Empty Cells

table {
  border-collapse: separate;
}
td {
  border: 1px solid #1769aa;
  empty-cells: hide;
}

Empty cells do not display their own borders or backgrounds.

Collapsed Borders

table {
  border-collapse: collapse;
}
td {
  border: 1px solid #1769aa;
  empty-cells: hide;
}

The empty-cells property has no effect in the collapsed border model. Empty cells continue participating in the table's shared-border structure.

Use empty-cells when working with separate borders and when the appearance of empty table cells needs to be controlled.

Table Layout and Dimensions

The border model affects how a table's overall dimensions are calculated and how space is distributed around its cells.

Separate Borders and Spacing

table {
  border-collapse: separate;
  border-spacing: 10px;
}
td {
  border: 2px solid #1769aa;
  padding: 12px;
}

The table includes spacing between cells and along its edges, in addition to the cells' borders and padding.

Collapsed Borders

table {
  border-collapse: collapse;
}
td {
  border: 2px solid #1769aa;
  padding: 12px;
}

Adjacent cells share borders, and the separate-model border spacing is removed. Collapsed border widths contribute to table layout according to the collapsed border model.

Cell Padding Still Applies

table {
  border-collapse: collapse;
}
th, td {
  padding: 12px 16px;
  border: 1px solid #d0d7de;
}

Collapsing borders does not remove cell padding. Padding continues to control the space between cell content and the cell's edges.

Fixed Table Layout

table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}

The table-layout property controls how column widths are determined. The border-collapse property independently controls the border model.

Responsive Table Container

.table-wrapper {
  max-width: 100%;
  overflow-x: auto;
}
.table-wrapper table {
  width: 100%;
  border-collapse: collapse;
}

A horizontally scrollable wrapper can help preserve a table's structure when its content is wider than the available space.

Practical Uses

The border-collapse property is useful for data tables, comparison tables, schedules, and other tabular layouts.

Standard Data Table

.data-table {
  width: 100%;
  border-collapse: collapse;
}
.data-table th,
.data-table td {
  border: 1px solid #d0d7de;
  padding: 10px 14px;
  text-align: left;
}

Collapsed borders create a clean, continuous grid for displaying structured data.

Table With Separated Cells

.spaced-table {
  border-collapse: separate;
  border-spacing: 8px;
}
.spaced-table td {
  border: 1px solid #1769aa;
  border-radius: 6px;
  padding: 12px;
}

Separate borders allow individual cells to appear as distinct boxes with rounded corners.

Header Divider

.report-table {
  border-collapse: collapse;
}
.report-table th,
.report-table td {
  padding: 12px;
  border-bottom: 1px solid #d0d7de;
}
.report-table thead {
  border-bottom: 3px solid #1769aa;
}

The header group receives a stronger divider while body rows use thinner separators.

Minimal Row Separators

.minimal-table {
  width: 100%;
  border-collapse: collapse;
}
.minimal-table th,
.minimal-table td {
  padding: 12px;
  border-bottom: 1px solid #d0d7de;
}

Only horizontal borders are used, creating a less crowded appearance than a complete grid.

Comparison Table

.comparison-table {
  width: 100%;
  border-collapse: collapse;
}
.comparison-table th,
.comparison-table td {
  border: 1px solid #b8c6d1;
  padding: 12px;
}
.comparison-table thead {
  background-color: #e8f2fb;
}

The collapsed model keeps the grid lines consistent between rows and columns.

border-collapse Example

The following example compares separate and collapsed table borders using the same cell content and border widths.

<div class="border-collapse-demo">
  <div class="table-example">
    <h3>Separate Borders</h3>
    <table class="separate">
      <tr>
        <th scope="col">Property</th>
        <th scope="col">Value</th>
      </tr>
      <tr>
        <td>color</td>
        <td>blue</td>
      </tr>
      <tr>
        <td>display</td>
        <td>grid</td>
      </tr>
    </table>
  </div>
  <div class="table-example">
    <h3>Collapsed Borders</h3>
    <table class="collapsed">
      <tr>
        <th scope="col">Property</th>
        <th scope="col">Value</th>
      </tr>
      <tr>
        <td>color</td>
        <td>blue</td>
      </tr>
      <tr>
        <td>display</td>
        <td>grid</td>
      </tr>
    </table>
  </div>
</div>
.border-collapse-demo {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
}
.border-collapse-demo .table-example {
  flex: 1 1 240px;
  min-width: 0;
}
.border-collapse-demo h3 {
  margin-bottom: 12px;
  font-size: 1rem;
}
.border-collapse-demo table {
  width: 100%;
}
.border-collapse-demo th,
.border-collapse-demo td {
  border: 2px solid #1769aa;
  padding: 10px;
  text-align: left;
}
.border-collapse-demo th {
  background-color: #e8f2fb;
}
.border-collapse-demo .separate {
  border-collapse: separate;
  border-spacing: 6px;
}
.border-collapse-demo .collapsed {
  border-collapse: collapse;
}
Browser Result

Separate Borders

Property Value
color blue
display grid

Collapsed Borders

The first table uses border-collapse: separate with 6 pixels of spacing. Each cell retains its own border, creating visible gaps between cells.

The second table uses border-collapse: collapse. Adjacent cells share a single border, producing a continuous grid without cell spacing.

Both tables use the same border thickness and cell padding. The difference comes from the border model.

Important Considerations

Keep the following points in mind when using border-collapse:

  • Initial value: The initial value is separate.
  • Inheritance: The property is inherited.
  • Supported values: Only separate and collapse are accepted, apart from CSS-wide keywords.
  • Table-specific behavior: The property controls the border model of table and inline-table boxes.
  • Separate borders: Adjacent cells retain their individual borders.
  • Collapsed borders: Adjacent cells share borders resolved by CSS conflict rules.
  • Border spacing: border-spacing applies only in the separate border model.
  • Zero spacing: Setting border-spacing: 0 does not make separate borders collapse.
  • Border conflicts: In collapsed tables, width, style, and element origin determine the winning border.
  • hidden: The hidden border style suppresses competing collapsed borders.
  • none: The none border style has the lowest priority in collapsed border conflicts.
  • Empty cells: The empty-cells property has no effect in the collapsed border model.
  • Rounded corners: Separate borders are generally preferable when individual cells need rounded corners.
  • Cell padding: Collapsing borders does not remove cell padding.
  • Table dimensions: The border model affects spacing and border contributions to table layout.
  • Border rendering: Complex collapsed border intersections may show minor browser differences.
  • Animation: Changes between separate and collapse are discrete.
  • Accessibility: Use semantic table markup, including appropriate header cells, rather than relying on borders alone to communicate relationships.

Use border-collapse: collapse for continuous table grids and border-collapse: separate when individual cell borders or spacing are required.

Browser Support

The border-collapse property is widely supported across Chrome, Edge, Firefox, Safari, and other major browsers, including older browser versions.

Both separate and collapse are standard CSS values and do not require vendor prefixes.

Separate Borders

table {
  border-collapse: separate;
  border-spacing: 6px;
}

Collapsed Borders

table {
  border-collapse: collapse;
}

Both declarations are supported in modern browsers. Complex collapsed border conflict rendering can vary slightly between implementations.

Visit Can I Use? and search for border-collapse to review browser compatibility.

Specifications

The border-collapse property is defined in the CSS Tables Module Level 3 specification.

CSS Tables Module Level 3

The separate and collapsed border models are also described in the CSS 2.2 table formatting specification.

CSS 2.2: Table Borders