Tables

border-collapse

border-collapse decides whether table cells draw their own separate borders or share a single border with their neighbors.

Syntax

separate | collapse

Preview

果物の数
個数
りんご3
みかん5
Presets
Drag the bottom-right corner to resize

Code

.box {
  border-collapse: collapse;
}

Controls

border-collapsecollapse
border-collapse
果物の数
個数
りんご3
みかん5

About

Values

  • separate: the initial value. Each cell draws its own borders, and cells are spaced apart by border-spacing (at 0, neighboring borders touch and show as two lines).
  • collapse: borders of neighboring cells are merged into one. At the outer edge, the table's border merges with the cells' borders too. The table's border-spacing and padding, and the border-radius of the table and its cells, are then ignored.

Which border wins

When borders are collapsed, one of the overlapping borders is picked in this order.

  1. A border whose border-style is hidden wins, and no border is drawn.
  2. The wider border wins.
  3. At the same width, the style that comes first in double, solid, dashed, dotted, ridge, outset, groove, inset, none wins.
  4. If that still ties, the cell's border wins over the table's.

Where to write it

border-collapse is inherited, but the browser's default styles set separate on HTML table elements, so writing it on an element around the table does not reach the table. Write it on the table element itself. Note that Tailwind CSS's reset (Preflight) sets tables to collapse.

The preview places a table inside the box and gives the table inherit so it takes the value written on the box. The table's border (black) is wider than the cells' borders (blue), so with collapse the table's border wins on the outside.

Comments