CSS Reference ยท Borders, Outlines and Shadows
The border-collapse property
Reference for the CSS border-collapse property: choose between separate and collapsed table borders, how conflicts are resolved, with live examples.
The border-collapse property chooses how the borders of a table and its cells are drawn. In the default separate model every cell has its own border and the cells are kept apart by a gap (set with border-spacing), which gives the "double lines" look. In the collapse model neighbouring cells share one border line, which is what most people expect from a table.
The property is set on the table (or any element with display: table or inline-table) and is inherited by the table's descendants, but it only has an effect on the table itself.
table { border-collapse: collapse; }
Try it
Syntax
border-collapse: separate | collapse;
- Initial value:
separate - Applies to: table and inline-table elements
- Inherited: yes
- Animatable: no (discrete)
- Computed value: as specified
Values
| Value | Description |
|---|---|
separate |
Each cell, row group and the table keep their own borders, with spacing between cells from border-spacing. Cells can have rounded corners and their own backgrounds around the gap. |
collapse |
Adjacent borders merge into one. border-spacing is ignored, and border-radius does not apply to table cells, rows or the table. |
Usage notes
- Conflict rules (collapse only). When two neighbouring borders disagree,
hiddenwins over everything, then a wider border wins over a narrower one, then the style order isdouble,solid,dashed,dotted,ridge,outset,groove,inset, andnonehas the lowest priority. If still tied, the cell beats the row, the row beats the row group, and so on. - Half the width. In a collapsed table half of each border's width lies on each neighbouring cell, so a cell is slightly larger than its content plus padding suggests.
- Rows and groups can have borders in the collapsed model; in the separate model they are ignored (only the table and cells draw borders).
- Rounded tables. For a table with rounded corners, use
separatewithborder-spacing: 0, or wrap the table in an element withborder-radiusandoverflow: hidden. - Inherited value. Setting it on
tableis enough; the value then flows into the cells. - Accessibility. The border model has no effect on semantics, but make sure the lines keep enough contrast.
Browser support
Supported in every browser.
Related
border-spacingโ the gap in the separate modeltable-layout,empty-cells,caption-sideborder-style- Lesson: Styling Tables