CSS gaps

The CSS gaps module lets you specify spacing, or "gaps", between items in multi-column, flexbox, and grid layouts. The CSS multi-column layout module originally defined gaps and rules controlling the spacing between columns in multi-column containers. This module expands on these visible separators, called gap decorations, extending it to grid.

While margin and padding specify visual spacing around individual boxes, the properties in this module enable specifying the spacing between adjacent boxes within a given layout context for layouts that have gutters and gaps, when the spacing is different between sibling boxes as opposed to between the first box, last box, and the container's edge. You can show rules in every gap or in a subset of gaps, defining fully animatable rule widths, colors, and insets.

Gaps in action

In this example, the 2021 poem from the USA inauguration, The Hill We Climb, by Amanda Gorman, is displayed across multiple columns, similar to the way articles are displayed in printed newspapers. If you have JavaScript enabled, controls enable changing the column-gap, column-rule-color, column-rule-style and column-rule-width properties, as well as the preferred number of columns and whether the title and a quote should span all of the columns.

When the column rule is larger than the column gap, the decorative line appears behind the text; it doesn't change the size of the gap.

Reference

Properties

Terms and glossary definitions

Guides

Styling columns

Guide to styling columns and managing spacing between columns.

Handling content breaks in multi-column layout

Introduction to the fragmentation specification and how to control where column content breaks.

Box alignment guides

How box alignment works in the context of flexbox, grid layout, multiple-column layout, and for block, absolutely positioned and table layout.

CSS flexible box layout module

CSS grid layout module

CSS multi-column layout module

CSS box alignment

CSS box sizing module

CSS display module

Specifications

Specification
CSS Gap Decorations Module Level 1

See also