CSS propertyInteraction and more
border-collapse
Merges adjacent table cell borders into a single line or keeps them separate.
- Initial value
separate- Inherited
- Yes
- Animatable
- no
- Applies to
- tables (display: table)
- JavaScript
element.style.borderCollapse = "collapse"
Example
#CSS
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border-bottom: 1px solid #333;
padding: 8px 12px;
text-align: left;
}Example HTML
<table style="border-collapse: collapse; width: 100%;">
<tr><th style="border-bottom: 1px solid #555; padding: 8px 12px; text-align: left;">Student</th><th style="border-bottom: 1px solid #555; padding: 8px 12px; text-align: left;">EXP</th></tr>
<tr><td style="border-bottom: 1px solid #333; padding: 8px 12px;">Anna</td><td style="border-bottom: 1px solid #333; padding: 8px 12px;">1240</td></tr>
<tr><td style="border-bottom: 1px solid #333; padding: 8px 12px;">Jake</td><td style="border-bottom: 1px solid #333; padding: 8px 12px;">980</td></tr>
</table>Preview
Definition and usage
#By default (separate) every table cell has its own border, so double lines with a gap are visible between cells. The collapse value merges adjacent borders into one line.
In practice, border-collapse: collapse is the first line you add to the styles of a data table. The table then looks clean and tidy.
With separate, you set the gap between cells with the border-spacing property, and with collapse that property has no effect.
Syntax
#Syntax
border-collapse: separate | collapse;Values
#Values in practice
#separate
Double lines with gaps between cells.
.demo { border-collapse: separate; }collapse
Single, shared lines.
.demo { border-collapse: collapse; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Start data tables with
border-collapse: collapseand lines only under the rows. They look lighter than a full grid. - With
collapse,border-radiuson the table doesnโt work. Wrap the table in an element withoverflow: hidden.
Related entries
#Spotted a mistake or missing an example? Write to us.