How to Merge Table Cell Borders with border-collapse in CSS
Give a table and its cells a border and you get double lines, with a gap between each cell. border-collapse: collapse on the table merges them into single lines, like a grid.
Syntax
<table selector> {
border-collapse: collapse;
}
| Part | What it does |
|---|---|
<table selector> | The table, such as table or a class on it. |
collapse | Merges the borders of neighboring cells into one. The default, separate, keeps each cell's own border. |
MDN's border-collapse page explains both values, and that with separate borders, the distance between cells comes from border-spacing.
The Example
The example is the same small table of holidays twice. Every table, heading cell and data cell has a 1-pixel grey border, and the second table has the class collapsed.
Step 1: Write the Code
Create a file named index.html in a text editor, such as Visual Studio Code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Border collapse</title>
<style>
table, th, td {
border: 1px solid #8a8886;
}
.collapsed {
border-collapse: collapse;
}
</style>
</head>
<body>
<table>
<tr><th>Date</th><th>Holiday</th></tr>
<tr><td>1 January</td><td>New Year's Day</td></tr>
</table>
<p></p>
<table class="collapsed">
<tr><th>Date</th><th>Holiday</th></tr>
<tr><td>1 January</td><td>New Year's Day</td></tr>
</table>
</body>
</html>
The empty paragraph between the tables only adds some space between them.
Step 2: Open It in a Browser
Double-click index.html. It opens in your browser:

The screenshot comes from Chromium 159, the open-source browser that Chrome is built on.
What Happened
- The first table has double lines. Its
border-collapseisseparate, the default: the table and each cell draw their own border, with a small gap between the cells. - The second table has single lines. With
collapse, neighboring borders merged into one, and the gaps are gone.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Putting border-collapse on the cells | It does nothing there: with td { border-collapse: collapse; }, the table stayed separate, with 2-pixel gaps between the cells | Put it on the table |
Using border-spacing on a collapsed table | It's ignored: with collapse, the gap stayed 0 | Use border-spacing only with separate |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The table still has double lines | border-collapse is on the cells, or the selector doesn't match the table | Put it on the table |
| The gap between cells doesn't change | The table is collapsed | Switch to separate to space the cells |
FAQ
How do I change the space between cells?
Keep the borders separate and set border-spacing. With border-spacing: 10px, the cells were 10 pixels apart. On a collapsed table, the same rule left them touching.
Why does the browser use double lines by default?
The default is separate, where every cell is its own box with its own border. Chromium also adds 2 pixels of spacing between the cells.
Conclusion
Give the table and its cells their borders, then add border-collapse: collapse to the table for clean single lines. Keep separate when you want space between the cells.
Additional Resources
- border-collapse, on MDN.
- border-spacing, on MDN.
