CSS border-collapse Property

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Box Model & Borders

What You’ll Learn

The border-collapse property controls how table cell borders interact. It helps you choose between merged borders and spaced, separate borders.

01

Table Borders

Cell border behavior.

02

collapse

Merge shared borders.

03

separate

Keep borders apart.

04

separate Default

Browser default mode.

05

On <table>

Apply to table element.

06

border-spacing

Works with separate.

Definition and Usage

The border-collapse CSS property is used to control the spacing and border styling of table elements. It determines how the borders of adjacent table cells are combined or kept separate.

This property can help create cleaner and more compact table layouts by specifying how adjacent borders should interact. Most data tables on the web use collapse for a tidy grid look.

💡
Beginner Tip

Apply border-collapse on the <table> element, then style cell borders on th and td. Without cell borders, the collapse mode may not look very different at first glance.

📝 Syntax

The syntax for border-collapse is simple. It is applied to the <table> element and accepts two keyword values.

syntax.css
table {

  border-collapse: collapse | separate;

}

Basic Example

border-collapse.css
table {

  border-collapse: collapse;

  width: 100%;

}

th, td {

  border: 1px solid black;

  padding: 8px;

}

Here, value can be either collapse or separate.

Syntax Rules

  • The initial value is separate.
  • Only applies to table and inline-table elements.
  • With collapse, adjacent cell borders merge into one shared line.
  • With separate, each cell keeps its own border box.
  • border-spacing only works when the value is separate.

⚡ Quick Reference

QuestionAnswer
Initial valueseparate
Applies totable and inline-table elements
InheritedYes
AnimatableNo
Common useHTML data tables, pricing grids, comparison charts

Default Value

The default value of border-collapse is separate. This means the borders of table cells are rendered as distinct and separate from each other unless you change the property.

💎 Property Values

The border-collapse property accepts two keyword values.

ValueDescription
collapseAdjacent cell borders are merged into a single border for a cleaner grid
separateEach cell keeps its own border; gaps can be added with border-spacing
initialSets the property to its default value
inheritInherits the property value from its parent element

collapse

AB
CD

separate + spacing

AB
CD

Table Elements Only

border-collapse only affects real table layout. It does not change how borders behave on regular div grids or flex layouts.

Works on <table>

H1H2
12

Not for div grids

A
B
C
D

collapse vs separate

ValueBorder behaviorBest for
collapseShared borders become one line; no double-thick seamsStandard data tables, admin panels, and spreadsheet-style layouts
separateEach cell border stays independent; spacing is possibleCard-like tables, spaced grids, and designs that need visible gaps
border-spacingOnly applies when collapse is separateAdding space between cells without changing border width

👀 Live Preview

A table with collapsed borders:

Header 1Header 2
Data 1Data 2
Data 3Data 4

Uses border-collapse: collapse; with 1px solid borders on th and td.

Examples Gallery

Try border-collapse with collapsed borders, separate borders, spacing, and a styled data table.

📚 Basic Table Border Modes

Compare the two core values of border-collapse on a simple HTML table.

Example 1 — Collapsed Borders

Merge adjacent cell borders into a single shared line for a clean grid.

border-collapse-collapse.html
<style>

  table {

    border-collapse: collapse;

    width: 100%;

  }

  th, td {

    border: 1px solid black;

    padding: 8px;

    text-align: center;

  }

  th {

    background-color: #f2f2f2;

  }

</style>



<table>

  <tr><th>Header 1</th><th>Header 2</th></tr>

  <tr><td>Data 1</td><td>Data 2</td></tr>

  <tr><td>Data 3</td><td>Data 4</td></tr>

</table>
Try It Yourself

How It Works

With collapse, neighboring borders share one line instead of stacking. This is the most common choice for readable data tables.

Example 2 — Separate Borders

Keep each cell border independent for a spaced, card-like table look.

border-collapse-separate.html
<style>

  table {

    border-collapse: separate;

    width: 100%;

  }

  th, td {

    border: 1px solid black;

    padding: 8px;

    text-align: center;

  }

</style>



<table>

  <tr><th>Header 1</th><th>Header 2</th></tr>

  <tr><td>Data 1</td><td>Data 2</td></tr>

</table>
Try It Yourself

How It Works

separate is the default. Adjacent borders do not merge, which can create a double-thick look where cells meet unless you add spacing.

📏 Spacing and Styled Tables

Combine separate with border-spacing, or style a modern collapsed data table.

Example 3 — Separate Borders with Spacing

Add gaps between cells using border-spacing while keeping borders separate.

border-collapse-spacing.css
table {

  border-collapse: separate;

  border-spacing: 8px;

  width: 100%;

}

td {

  border: 1px solid #2563eb;

  padding: 8px;

  background: #eff6ff;

  text-align: center;

}
Try It Yourself

How It Works

border-spacing adds space between cell borders. It is ignored when border-collapse is set to collapse.

Example 4 — Styled Data Table with Collapse

Build a modern zebra-striped table using collapsed borders and row background colors.

border-collapse-styled.css
.data-table {

  border-collapse: collapse;

  width: 100%;

  font-size: 0.875rem;

}

.data-table th, .data-table td {

  border: 1px solid #cbd5e1;

  padding: 0.65rem;

  text-align: left;

}

.data-table th {

  background: #1e293b;

  color: #fff;

}

.data-table tr:nth-child(even) td {

  background: #f8fafc;

}
Try It Yourself

How It Works

Collapsed borders keep the grid lines clean while row styling adds readability. This pattern works well for dashboards and report tables.

🧠 How border-collapse Works

1

You style the table

Set border-collapse on the <table> element.

Table rule
2

You add cell borders

Apply borders to th and td so the grid is visible.

Cell styling
3

The browser merges or separates

With collapse, shared borders become one line. With separate, each cell keeps its own border.

Border model
=

Clean table layout

Your table gets the border behavior you chose for readable rows and columns.

Universal Browser Support

The border-collapse property is widely supported across all major browsers, including Chrome, Firefox, Safari, Edge, Opera, and Internet Explorer. It is a reliable choice for HTML table styling.

Baseline · All browsers

Consistent table borders on every platform

Chrome, Firefox, Safari, Edge, and Opera all support border-collapse consistently.

100% Universal support
Google Chrome69+ · Desktop & Mobile
Full support
Mozilla Firefox66+ · Desktop & Mobile
Full support
Apple Safari12.1+ · macOS & iOS
Full support
Microsoft Edge79+ · Chromium
Full support
Opera56+ · Modern versions
Full support
border-collapse property 100% supported

Bottom line: Use border-collapse freely in any project with HTML tables. It works consistently across all browsers.

Conclusion

The border-collapse property is essential for managing the visual presentation of table borders. By choosing between collapse and separate, you control whether borders are merged or kept distinct.

Experiment with both values to achieve the layout that best suits your needs. For most data tables, collapse gives the cleanest result, while separate pairs well with border-spacing for spaced designs.

💡 Best Practices

✅ Do

  • Use collapse for standard data tables and admin dashboards
  • Apply the property on the <table> element, not individual cells
  • Style borders on th and td for a visible grid
  • Use separate with border-spacing when you want gaps between cells
  • Test table rendering in multiple browsers for complex border colors

❌ Don’t

  • Expect border-collapse to work on non-table layouts
  • Use border-spacing when the table is set to collapse
  • Forget cell borders and wonder why the table looks unchanged
  • Assume separate always looks cleaner without adjusting spacing
  • Mix table borders with border-radius on cells without testing carefully

Key Takeaways

Knowledge Unlocked

Five things to remember about border-collapse

Use these points when styling HTML table borders.

5
Core concepts
⚙️02

separate Default

Cells stay apart.

Default
📝03

collapse

Merges shared lines.

Values
📏04

border-spacing

Works with separate.

Related
🔄05

On <table>

Not for div grids.

Scope

❓ Frequently Asked Questions

The border-collapse property controls whether adjacent table cell borders are merged into one border or kept separate. It is applied on the table element.
The initial value is separate. Each cell keeps its own distinct border by default.
Use collapse for clean data tables where shared borders should look like one line. Use separate when you want visible gaps between cells with border-spacing.
No. border-collapse only applies to table and inline-table elements. Regular block elements use normal border box behavior.
border-spacing only has an effect when border-collapse is separate. When you set collapse, border-spacing is ignored.

Practice in the Live Editor

Open the HTML editor, try border-collapse, and preview table border behavior instantly.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful