CSS column-gap Property
The column-gap property specifies the spacing between adjacent columns in multi-column layouts and between items or tracks in CSS Grid and Flexbox layouts.
It creates space between layout elements without requiring margins on individual children. This helps maintain consistent spacing in articles, card layouts, navigation menus, and responsive designs.
The property was originally introduced for CSS Multi-column Layout and is now part of CSS Box Alignment, allowing it to work with multiple layout systems.
column-gap Syntax
The column-gap property accepts the keyword normal, a non-negative length, or a non-negative percentage.
selector {
column-gap: 20px;
}
General Syntax
selector {
column-gap: normal | <length-percentage [0,∞]>;
}
Default Spacing
.content {
column-gap: normal;
}
Pixel Spacing
.content {
column-gap: 30px;
}
Relative Spacing
.content {
column-gap: 2rem;
}
Percentage Spacing
.content {
column-gap: 5%;
}
Zero Spacing
.content {
column-gap: 0;
}
CSS-Wide Keywords
.content {
column-gap: inherit;
}
.content {
column-gap: initial;
}
.content {
column-gap: unset;
}
.content {
column-gap: revert;
}
.content {
column-gap: revert-layer;
}
Negative lengths and percentages are invalid. The property does not accept auto as a value.
Property Values
The column-gap property supports several spacing values that can be used across different layout systems.
| Value | Description |
|---|---|
normal |
Uses the layout system's normal gap. It generally computes to 0 in Grid and Flexbox, while multi-column layout uses approximately 1em. |
0 |
Removes the specified spacing between adjacent columns or items. |
20px |
Creates a fixed gap of 20 pixels. |
1.5rem |
Creates spacing relative to the root element's font size. |
2em |
Creates spacing relative to the element's font size. |
5% |
Creates percentage-based spacing relative to the container's applicable content-box size. |
clamp(12px, 2vw, 30px) |
Creates responsive spacing with minimum, preferred, and maximum values. |
CSS-Wide Keywords
| Value | Description |
|---|---|
inherit |
Uses the computed value from the parent element. |
initial |
Resets the property to normal. |
unset |
Resets the property to normal because it is not inherited. |
revert |
Reverts the property according to cascade origin rules. |
revert-layer |
Reverts the property according to cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | normal |
| Inherited | No |
| Applies to | Multi-column, Grid, and Flex containers |
| Computed value | Specified length or percentage, or normal |
| Animation type | Length, percentage, or calculated value |
| Percentages | Relative to the corresponding content-box dimension |
| Primary use | Creating consistent spacing between layout columns or items |
The direction in which column-gap creates spacing depends on the layout system. In Grid it separates column tracks, while in Flexbox it separates adjacent items along the main axis when the flex direction is a row.
How It Works
The column-gap property creates spacing between adjacent layout tracks or items without adding margins to the container's outer edges.
Step 1: Establish a Layout
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
Step 2: Set the Gap
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
column-gap: 20px;
}
Step 3: Calculate Available Space
The browser accounts for the gaps when determining the available space for tracks or columns.
Step 4: Position the Content
Items or content columns are arranged with the specified spacing between them.
Step 5: Adjust to Layout Changes
If the container width or number of columns changes, the browser recalculates the layout while preserving the declared gap.
Important Distinction
The property creates internal spacing between columns or items. It does not automatically add padding around the outside of the container.
normal Value
The normal value allows the browser to use the default spacing associated with the layout system.
.container {
column-gap: normal;
}
Multi-column Layout
In multi-column layout, normal produces a gap equivalent to 1em, based on the element's font size.
.article {
column-count: 3;
column-gap: normal;
}
CSS Grid
In Grid layout, normal computes to zero.
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
column-gap: normal;
}
CSS Flexbox
In Flexbox, normal also computes to zero.
.flex {
display: flex;
column-gap: normal;
}
When to Use normal
Use normal when the layout system's default spacing is appropriate. Specify a length or percentage when you need consistent, deliberate spacing.
Length Values
Length values provide explicit control over the distance between adjacent columns or items.
Pixels
.container {
column-gap: 24px;
}
Pixels are useful when a design requires a specific gap size.
Root-Relative Units
.container {
column-gap: 1.5rem;
}
The rem unit is relative to the root element's font size and can help maintain consistent spacing throughout a website.
Font-Relative Units
.container {
column-gap: 2em;
}
The em unit is relative to the element's font size.
Viewport-Relative Units
.container {
column-gap: 2vw;
}
Viewport-relative units allow spacing to change as the viewport changes.
Responsive Calculations
.container {
column-gap: clamp(12px, 2vw, 32px);
}
The clamp() function allows the gap to scale while remaining within specified minimum and maximum limits.
Zero Gap
.container {
column-gap: 0;
}
Zero removes the specified gap between adjacent columns or items.
Percentage Values
The column-gap property accepts percentages that are resolved relative to the corresponding content-box dimension of the container.
.container {
column-gap: 5%;
}
Percentage-Based Grid Gap
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
column-gap: 5%;
}
Percentage-Based Flex Gap
.flex {
display: flex;
column-gap: 4%;
}
Definite Container Size
When the relevant container size is definite, percentage gaps can be calculated from that size.
Indefinite Container Size
Percentage gaps can behave differently when the container's relevant size is indefinite, particularly during intrinsic sizing calculations.
Grid Sizing Behavior
In Grid layout, cyclic percentage gaps are resolved as zero for intrinsic size contributions, but may later resolve against the content box during layout.
Flexbox Considerations
In Flexbox, percentage gaps may resolve to zero when the corresponding container dimension is indefinite.
Practical Recommendation
Use length values such as rem or px when predictable spacing is important. Percentage values are useful when spacing should scale with a definite container size.
Multi-column Layout
In CSS Multi-column Layout, column-gap specifies the spacing between adjacent content columns.
Basic Multi-column Example
.article {
column-count: 3;
column-gap: 30px;
}
Automatic Column Count
.article {
column-width: 220px;
column-gap: 25px;
}
The browser determines how many columns fit while accounting for the requested column width and gap.
Default Spacing
.article {
column-count: 3;
column-gap: normal;
}
The default gap is approximately 1em.
Column Rule
.article {
column-count: 3;
column-gap: 30px;
column-rule: 1px solid #cccccc;
}
The column rule is drawn in the gap between columns. It does not increase the space allocated to the gap.
Column Width Calculation
The browser accounts for the total gap space when calculating the widths of the content columns.
Reading Order
Content flows sequentially from one column to the next according to the writing direction.
When to Use
Use column-gap to create clear separation between columns of flowing text and other multi-column content.
CSS Grid Layout
In CSS Grid, column-gap creates spacing between adjacent grid column tracks.
Three-Column Grid
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
column-gap: 20px;
}
Different Column Widths
.grid {
display: grid;
grid-template-columns: 200px 1fr;
column-gap: 30px;
}
Grid Items
The gap separates grid tracks, not individual item margins. Items occupying the same track arrangement share the same track spacing.
Row Spacing
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
column-gap: 24px;
row-gap: 16px;
}
Responsive Grid
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
column-gap: 20px;
}
Grid Gap Behavior
Grid gaps occupy space between tracks and are included in the layout calculations.
When to Use
Use column-gap in Grid layouts when consistent horizontal spacing is needed between tracks.
CSS Flexbox Layout
In Flexbox, column-gap controls spacing between adjacent flex items or flex lines, depending on the flex direction.
Horizontal Flex Layout
.flex {
display: flex;
flex-direction: row;
column-gap: 20px;
}
For a row-direction flex container, column-gap creates horizontal spacing between adjacent items.
Vertical Flex Layout
.flex {
display: flex;
flex-direction: column;
column-gap: 20px;
}
For a column-direction flex container, column-gap controls spacing between flex lines when wrapping occurs, rather than the vertical spacing between items within one column.
Vertical Item Spacing
.flex {
display: flex;
flex-direction: column;
row-gap: 20px;
}
Wrapping Flex Items
.flex {
display: flex;
flex-wrap: wrap;
column-gap: 20px;
row-gap: 15px;
}
Navigation Example
.navigation {
display: flex;
flex-wrap: wrap;
column-gap: 24px;
}
Flexbox Gap vs Margins
Gaps create spacing only between adjacent items or lines, while margins can also affect the outer edges of individual elements.
When to Use
Use column-gap for consistent spacing between Flexbox items without adding individual margins.
gap Shorthand
The gap shorthand sets both row-gap and column-gap.
One Value
.container {
gap: 20px;
}
A single value sets both row and column gaps to the same amount.
Two Values
.container {
gap: 15px 30px;
}
The first value sets row-gap, and the second sets column-gap.
Equivalent Longhand Properties
.container {
row-gap: 15px;
column-gap: 30px;
}
Grid Example
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 15px 25px;
}
Flexbox Example
.flex {
display: flex;
flex-wrap: wrap;
gap: 12px 20px;
}
When to Use the Shorthand
Use gap when setting both row and column spacing together. Use column-gap when only column spacing needs to be changed.
row-gap Comparison
The row-gap and column-gap properties control different spacing directions within a layout.
| Property | Purpose |
|---|---|
column-gap |
Controls spacing between column tracks in Grid, content columns in multi-column layout, or the corresponding flex items or lines in Flexbox. |
row-gap |
Controls spacing between row tracks in Grid or the corresponding flex items or lines in Flexbox. |
gap |
Sets both row-gap and column-gap. |
Grid Comparison
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
column-gap: 30px;
row-gap: 15px;
}
Flexbox Direction Matters
In Flexbox, the physical direction of each gap depends on flex-direction. The property names do not always correspond directly to horizontal and vertical spacing.
Choosing the Right Property
Use the individual properties when row and column spacing need separate values. Use gap for concise declarations when both should be controlled together.
Column Rules
In multi-column layout, column-rule adds a decorative separator between adjacent content columns.
Basic Column Rule
.article {
column-count: 3;
column-gap: 30px;
column-rule: 1px solid #cccccc;
}
Rule Position
The rule is drawn in the center of the column gap.
Rule Width
.article {
column-count: 3;
column-gap: 30px;
column-rule-width: 2px;
column-rule-style: solid;
column-rule-color: #777777;
}
Rule Does Not Change Gap Size
The width of a column rule does not increase the allocated column gap.
Wide Rules
If a rule is wider than the gap, it can extend into the content columns. Choose rule widths that fit comfortably within the available spacing.
Grid and Flexbox
The column-rule property is intended for multi-column layout. It does not automatically create separators between Grid or Flexbox items.
When to Use
Use column rules when a visible separator improves the distinction between adjacent text columns.
Responsive Spacing
Column spacing should adapt to the available screen or container width.
Desktop Spacing
.content {
column-count: 3;
column-gap: 30px;
}
Tablet Spacing
@media (max-width: 900px) {
.content {
column-count: 2;
column-gap: 20px;
}
}
Mobile Layout
@media (max-width: 600px) {
.content {
column-count: 1;
column-gap: 0;
}
}
Fluid Spacing
.content {
column-gap: clamp(12px, 2vw, 30px);
}
Responsive Grid
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
column-gap: clamp(12px, 2vw, 24px);
}
Container Queries
.component-wrapper {
container-type: inline-size;
}
.component-grid {
display: grid;
grid-template-columns: 1fr;
column-gap: 12px;
}
@container (min-width: 600px) {
.component-grid {
grid-template-columns: repeat(3, 1fr);
column-gap: 24px;
}
}
Container queries are useful when spacing should respond to the width of a component rather than the entire viewport.
Practical Uses
The column-gap property can be used in many common CSS layouts.
Multi-column Articles
.article {
column-count: 3;
column-gap: 30px;
}
Grid Cards
.card-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
column-gap: 20px;
}
Flexbox Navigation
.navigation {
display: flex;
column-gap: 24px;
}
Two-Column Content Layout
.page-layout {
display: grid;
grid-template-columns: 1fr 280px;
column-gap: 40px;
}
Responsive Card Layout
.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
column-gap: 20px;
row-gap: 20px;
}
Multi-column Lists
.link-list {
column-count: 3;
column-gap: 25px;
}
Form Layouts
.form-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
column-gap: 20px;
}
Using gaps instead of individual margins often simplifies spacing rules and avoids unwanted outer spacing around a layout.
column-gap Example
The following example compares different column-gap values in three-column Grid layouts.
Each layout uses the same number of columns and content. Only the gap between the columns changes.
<div class="column-gap-demo">
<div class="gap-example">
<h3>column-gap: 0</h3>
<div class="gap-grid no-gap">
<div>Column 1</div>
<div>Column 2</div>
<div>Column 3</div>
</div>
</div>
<div class="gap-example">
<h3>column-gap: 15px</h3>
<div class="gap-grid medium-gap">
<div>Column 1</div>
<div>Column 2</div>
<div>Column 3</div>
</div>
</div>
<div class="gap-example">
<h3>column-gap: 30px</h3>
<div class="gap-grid large-gap">
<div>Column 1</div>
<div>Column 2</div>
<div>Column 3</div>
</div>
</div>
</div>
.column-gap-demo {
display: grid;
gap: 20px;
}
.column-gap-demo .gap-example {
padding: 15px;
border: 1px solid #cccccc;
background-color: #f8f9fa;
}
.column-gap-demo h3 {
margin: 0 0 12px;
font-size: 1.125rem;
}
.column-gap-demo .gap-grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
}
.column-gap-demo .gap-grid div {
padding: 15px 5px;
background-color: #dceaf7;
border: 1px solid #8fb4d8;
text-align: center;
}
.column-gap-demo .no-gap {
column-gap: 0;
}
.column-gap-demo .medium-gap {
column-gap: 15px;
}
.column-gap-demo .large-gap {
column-gap: 30px;
}
@media (max-width: 600px) {
.column-gap-demo .large-gap {
column-gap: 10px;
}
}
column-gap: 0
column-gap: 15px
column-gap: 30px
The first layout has no gap between columns. The second uses 15 pixels of spacing, while the third uses 30 pixels.
As the gap increases, the browser reduces the available width of the grid tracks to accommodate the additional spacing.
The media query reduces the largest gap on smaller screens to help preserve usable column widths.
Accessibility
Appropriate spacing can improve readability and make related interface elements easier to distinguish.
Maintain Readable Separation
Use enough spacing to make adjacent text columns and interface items visually distinct.
Avoid Excessively Large Gaps
Large gaps can reduce the available width for content, causing unnecessary wrapping or overflow.
Responsive Spacing
Adjust gaps on smaller screens so that content remains readable without horizontal scrolling.
Preserve Reading Order
The column-gap property changes spacing but does not change the underlying HTML document order.
Interactive Controls
Use adequate spacing between buttons, links, and form controls to help users distinguish interactive targets.
Text Zoom and Reflow
Test layouts at increased text sizes and browser zoom levels to ensure that gaps do not cause content to become cramped or inaccessible.
Avoid Using Gaps as Content
Spacing should be used for visual layout, not to communicate essential information. Use semantic HTML and visible labels where needed.
Important Considerations
Keep the following points in mind when using column-gap:
- Purpose: Controls spacing between columns, tracks, or flex items and lines.
- Initial value:
normal. - Inheritance: The property is not inherited.
- Supported layouts: Multi-column, Grid, and Flexbox.
- Valid values:
normal, non-negative lengths, and non-negative percentages. - Invalid values: Negative lengths, negative percentages, and
auto. - normal in multi-column: Produces a gap equivalent to
1em. - normal in Grid and Flexbox: Computes to zero.
- Zero: Removes the specified gap.
- Length units: Pixels,
em,rem, and other CSS length units are supported. - Percentages: Depend on the corresponding container dimension and sizing context.
- Grid: Creates spacing between column tracks.
- Flexbox: Spacing direction depends on
flex-direction. - Multi-column: Creates spacing between adjacent content columns.
- column-rule: Draws a separator within the column gap without increasing its allocated size.
- gap shorthand: Sets both
row-gapandcolumn-gap. - Outer spacing: Gaps do not automatically create padding around the container.
- Responsive design: Adjust gaps to maintain comfortable content widths.
- Animation: Length and percentage values can be interpolated.
- Accessibility: Maintain readable spacing and avoid unnecessary overflow.
Use column-gap when you need consistent internal spacing between layout elements. For layouts requiring both horizontal and vertical spacing, the gap shorthand is often more convenient.
Browser Support
The column-gap property is widely supported in modern browsers, including Chrome, Edge, Firefox, and Safari.
Support is well established for multi-column and Grid layouts. Flexbox gap support was introduced later, so older browser versions may not support gaps between flex items.
Multi-column Example
.article {
column-count: 3;
column-gap: 30px;
}
Grid Example
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
column-gap: 20px;
}
Flexbox Example
.flex {
display: flex;
column-gap: 20px;
}
Compatibility Considerations
When supporting older browsers, verify Flexbox gap support and test percentage-based gaps in layouts with indefinite container sizes.
For current compatibility details, visit Can I Use? and search for column-gap.
Specifications
The column-gap property is defined in the CSS Box Alignment specification, with its use in multi-column layout also described by CSS Multi-column Layout.
CSS Box Alignment Module Level 3
CSS Multi-column Layout Module Level 1
These specifications define how gaps are sized and applied in multi-column, Grid, and Flexbox layouts.
