Gaps & gap decorations

Gaps are the fixed spaces between the rows and columns of grid containers, between the items and lines of flex containers, and between the columns of multi-column containers. Rules are lines drawn in those gaps. They are painted in the middle of the gap and take up no space of their own. Column rules started in multi-column layout; the row rules, the rule-* shorthands and the inset, break, visibility and overlap controls are newer and so far ship only in Chrome.

Gaps

gap

Shorthand for row-gap and column-gap: the space between rows and between columns. One value sets both; two set the row gap then the column gap. Gaps only go between tracks, items or columns, never at the outer edges.

Syntax<'row-gap'> <'column-gap'>?
InitialSee individual properties
Applies toMulti-column containers, flex containers, grid containers and grid lanes containers
InheritedNo
PercentagesRefer to the corresponding dimension of the content area
AnimationBy computed value type
SupportChrome 57 · Firefox 52 · Safari 10.1
Flex containers: Chrome 84 · Firefox 63 · Safari 14.1
Speccss-gaps-1
.cards { display: grid; gap: 1rem 2rem; }  /* rows, then columns */
1rem between rows and 2rem between columns, with no extra space at the edges.

row-gap, column-gap

The gap between rows (row-gap) or between columns (column-gap). In a flex container, column-gap separates items along a row and row-gap separates the lines of a wrapping container.

Syntaxnormal | <length-percentage [0,∞]> | <line-width>
Initialnormal
Applies toMulti-column containers, flex containers, grid containers and grid lanes containers
InheritedNo
PercentagesRefer to the corresponding dimension of the content area
AnimationBy computed value type
Supportrow-gap: Chrome 47 · Firefox 52 · Safari 10.1
column-gap: Chrome 1 · Firefox 1.5 · Safari 3
Flex containers: Chrome 84 · Firefox 63 · Safari 14.1
Speccss-gaps-1

normal is 1em in multi-column containers and 0 everywhere else.

Column rules

Column rules are drawn in the gaps between columns. In multi-column containers they have long-standing support; in grid and flex containers they are part of the newer gap decorations, which ship with the row rules in Chrome 149.

column-rule

Shorthand for column-rule-width, column-rule-style and column-rule-color, written like a border: 1px solid gray. A <gap-rule> is that width, style and colour in any order; the list forms are comma-separated rules for successive gaps, with repeat() to repeat a run of them.

Syntax<gap-rule-list> | <gap-auto-rule-list>
InitialSee individual properties
Applies toSee individual properties
InheritedSee individual properties
AnimationSee individual properties
SupportChrome 50 · Firefox 52 · Safari 9
Speccss-gaps-1
article { columns: 3; column-gap: 2rem; column-rule: 1px solid currentcolor; }
A thin line down the middle of each 2rem gap between three columns.

column-rule-width

The thickness of the column rules: a length or thin, medium or thick. A rule wider than its gap overlaps the content on either side rather than widening the gap.

Syntax<line-width-list> | <auto-line-width-list>
Initialmedium
Applies toGrid containers, flex containers, multi-column containers and grid lanes containers
InheritedNo
AnimationAs a repeatable list
SupportChrome 50 · Firefox 52 · Safari 9
Speccss-gaps-1

column-rule-style

The line style of the column rules, using the border-style keywords such as solid, dashed and dotted. The initial none draws nothing, so a rule needs a style to appear.

Syntax<line-style-list> | <auto-line-style-list>
Initialnone
Applies toGrid containers, flex containers, multi-column containers and grid lanes containers
InheritedNo
AnimationDiscrete
SupportChrome 50 · Firefox 52 · Safari 9
Speccss-gaps-1

column-rule-color

The colour of the column rules. A comma-separated list gives successive gaps their own colours.

Syntax<line-color-list> | <auto-line-color-list>
Initialcurrentcolor
Applies toGrid containers, flex containers, multi-column containers and grid lanes containers
InheritedNo
AnimationAs a repeatable list
SupportChrome 50 · Firefox 52 · Safari 9
Lists and repeat(): Chrome 149 · Firefox no · Safari no
Speccss-gaps-1

Row rules

The same as the column rules, drawn in the gaps between rows of a grid or between the lines of a wrapping flex container.

row-rule

Shorthand for row-rule-width, row-rule-style and row-rule-color, with the same values as column-rule.

Syntax<gap-rule-list> | <gap-auto-rule-list>
InitialSee individual properties
Applies toSee individual properties
InheritedSee individual properties
AnimationSee individual properties
SupportChrome 149 · Firefox no · Safari no
Speccss-gaps-1

row-rule-width

The thickness of the row rules.

Syntax<line-width-list> | <auto-line-width-list>
Initialmedium
Applies toGrid containers, flex containers, multi-column containers and grid lanes containers
InheritedNo
AnimationAs a repeatable list
SupportChrome 149 · Firefox no · Safari no
Speccss-gaps-1

row-rule-style

The line style of the row rules. The initial none draws nothing.

Syntax<line-style-list> | <auto-line-style-list>
Initialnone
Applies toGrid containers, flex containers, multi-column containers and grid lanes containers
InheritedNo
AnimationDiscrete
SupportChrome 149 · Firefox no · Safari no
Speccss-gaps-1

row-rule-color

The colour of the row rules.

Syntax<line-color-list> | <auto-line-color-list>
Initialcurrentcolor
Applies toGrid containers, flex containers, multi-column containers and grid lanes containers
InheritedNo
AnimationAs a repeatable list
SupportChrome 149 · Firefox no · Safari no
Speccss-gaps-1

Rule shorthands

rule

Sets column-rule and row-rule to the same value, so one declaration draws lines in every gap.

Syntax<'column-rule'>
InitialSee individual properties
Applies toSame as column-rule and row-rule
InheritedNo
AnimationSee individual properties
SupportChrome 149 · Firefox no · Safari no
Speccss-gaps-1
.table { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; rule: 1px solid silver; }
Lines between every row and column of the grid.

rule-width, rule-style, rule-color

Each sets the matching column-rule-* and row-rule-* property to the same value.

Syntaxrule-width: <'column-rule-width'>
rule-style: <'column-rule-style'>
rule-color: <'column-rule-color'>
InitialSee individual properties
Applies toSame as the matching column-rule-* and row-rule-* properties
InheritedNo
AnimationSee individual properties
SupportChrome 149 · Firefox no · Safari no
Speccss-gaps-1

Rule insets & behaviour

Where gaps cross, as between the cells of a grid, each rule is split into segments that meet at junctions. A segment end at a junction where other rules are present is a junction end; any other end, such as at the edge of the container, is a cap. Each segment has a start end and an end end, in the direction the gap runs.

column-rule-break, row-rule-break

Whether rules break into separate segments where they meet other gaps. A T intersection is where one gap ends against another, for example at an item spanning two columns; a cross intersection is where two gaps run straight through each other.

Syntaxnone | normal | intersection
Initialnormal
Applies toGrid containers, flex containers, multi-column containers and grid lanes containers
InheritedNo
AnimationDiscrete
SupportChrome 149 · Firefox no · Safari no
Speccss-gaps-1
ValueEffect
noneRules do not start or end at T or cross intersections.
intersectionRules start and end at every T and cross intersection.
normalDepends on the container. In grid, rules break at T intersections and continue through cross intersections. Flex containers behave as none. Multi-column containers behave as intersection for column rules and none for row rules.

rule-break

Sets column-rule-break and row-rule-break to the same value.

Syntax<'column-rule-break'>
InitialSee individual properties
Applies toSame as column-rule-break and row-rule-break
InheritedSee individual properties
AnimationSee individual properties
SupportChrome 149 · Firefox no · Safari no
Speccss-gaps-1

column-rule-visibility-items, row-rule-visibility-items

Which gap segments get a rule, depending on whether the areas either side of the segment hold items. Use it to keep rules away from the empty cells of a partly filled grid.

Syntaxall | around | between | normal
Initialnormal
Applies toGrid containers and multi-column containers
InheritedNo
AnimationDiscrete
SupportChrome 149 · Firefox no · Safari no
Speccss-gaps-1
ValueEffect
allA rule in every segment, whether or not items are next to it.
aroundA rule where at least one of the two neighbouring areas holds an item.
betweenA rule only where both neighbouring areas hold items.
normalIn grid, behaves as all. In multi-column containers, column rules behave as between and row rules as all.

rule-visibility-items

Sets column-rule-visibility-items and row-rule-visibility-items to the same value.

Syntax<'column-rule-visibility-items'>
InitialSee individual properties
Applies toSame as column-rule-visibility-items and row-rule-visibility-items
InheritedSee individual properties
AnimationSee individual properties
SupportChrome 149 · Firefox no · Safari no
Speccss-gaps-1

rule-overlap

Which rules are painted on top where row and column rules cross: row-over-column paints row rules above column rules, and column-over-row the reverse.

Syntaxrow-over-column | column-over-row
Initialrow-over-column
Applies toGrid containers, flex containers and grid lanes containers
InheritedNo
AnimationDiscrete
SupportChrome 149 · Firefox no · Safari no
Speccss-gaps-1

column-rule-inset, row-rule-inset

Shorthand for all four insets of one direction's rules. The values before the slash set the cap insets; the values after it set the junction insets.

Syntax<'column-rule-inset-cap'> [ / <'column-rule-inset-junction'> ]?
InitialSee individual properties
Applies toSame as the cap and junction inset properties
InheritedSee individual properties
AnimationSee individual properties
SupportChrome 149 · Firefox no · Safari no
Speccss-gaps-1

column-rule-inset-cap, column-rule-inset-junction, row-rule-inset-cap, row-rule-inset-junction

Shorthands for the start and end insets of one kind of segment end: the -cap ones for ends at the container's edges, the -junction ones for ends where rules meet.

Syntax<inset-value> <inset-value>?
InitialSee individual properties
Applies toSame as the inset longhands
InheritedSee individual properties
AnimationSee individual properties
SupportChrome 149 · Firefox no · Safari no
Speccss-gaps-1

column-rule-inset-start, column-rule-inset-end, row-rule-inset-start, row-rule-inset-end

Shorthands that set the cap and junction insets of one end of each segment to the same value.

Syntax<inset-value>
InitialSee individual properties
Applies toSame as the inset longhands
InheritedSee individual properties
AnimationSee individual properties
SupportChrome 149 · Firefox no · Safari no
Speccss-gaps-1

column-rule-inset-cap-start, column-rule-inset-cap-end, column-rule-inset-junction-start, column-rule-inset-junction-end, row-rule-inset-cap-start, row-rule-inset-cap-end, row-rule-inset-junction-start, row-rule-inset-junction-end

Moves one end of each rule segment. A positive value pulls the end inwards and shortens the segment; a negative value pushes it outwards. An <inset-value> is a length, a percentage or the keyword overlap-join, which carries a junction end into the crossing gap so that it meets the crossing rule neatly; at a cap it counts as 0.

Syntax<inset-value>
Initial0
Applies toGrid containers, flex containers, multi-column containers and grid lanes containers
InheritedNo
PercentagesRefer to the crossing gap width
AnimationBy computed value type
SupportChrome 149 · Firefox no · Safari no
Speccss-gaps-1

rule-inset, rule-inset-cap, rule-inset-junction, rule-inset-start, rule-inset-end

Each sets the matching column and row inset properties to the same value.

Syntaxrule-inset: <'column-rule-inset'>
rule-inset-cap: <'column-rule-inset-cap'>
rule-inset-junction: <'column-rule-inset-junction'>
rule-inset-start: <'column-rule-inset-start'>
rule-inset-end: <'column-rule-inset-end'>
InitialSee individual properties
Applies toSame as the matching column and row inset properties
InheritedSee individual properties
AnimationSee individual properties
SupportChrome 149 · Firefox no · Safari no
Speccss-gaps-1
rule-inset: 0 / 0.25rem;
Rules run right to the container's edges but stop a little short where they meet other rules.