CSS Reference ยท Flexbox
The column-gap property
Reference for the CSS column-gap property: set the space between columns in grid, flexbox and multi-column text layouts, with live examples and usage notes.
The column-gap property sets the space between columns. It works in three layouts: between column tracks in a grid, between items on the same line in a flex container, and between the columns of multi-column text. It is one half of the gap shorthand, together with row-gap.
CSS
.cards { display: flex; column-gap: 1rem; } .article { column-count: 2; column-gap: 2rem; }
Try it
Syntax
CSS
column-gap: normal | <length-percentage>;
- Initial value:
normal - Applies to: multi-column containers, flex containers and grid containers
- Inherited: no
- Animatable: yes, as a length or percentage
- Computed value: as specified, with lengths made absolute
Values
| Value | Description |
|---|---|
<length> |
A non-negative length such as 2rem or 24px. |
<percentage> |
A percentage of the container's content-box width. |
normal |
1em in multi-column layout; no gap in grid and flex layout. |
Usage notes
- Different defaults. Multi-column text has a built-in
1emgap becausenormalmeans1emthere. Grid and flex containers start with no gap, so you must set one. - Column rules. A
column-ruleis drawn centered in the gap, so the gap must be wide enough to hold the line. - Flexbox. The gap goes between items on a line and is not added at the line edges. It does not collapse and does not replace margin on the container.
- Equal tracks. In a grid with
1frcolumns, gaps are subtracted first, then the rest is shared among the columns. - Old name.
grid-column-gapis an alias from early grid drafts; usecolumn-gap.
Browser support
Supported in all current browsers for multi-column, grid and flexbox layouts.
Related
gapโ shorthand for both gapsrow-gapโ spacing between rowsgrid-template-columnsโ defines the column tracks- Lesson: Grid Tracks