Title: CSS Gap Decorations Module Level 1
Shortname: css-gaps
Level: 1
Status: ED
Prepare for TR: no
Group: csswg
Work Status: exploring
Repository: w3c/csswg-drafts
URL: https://drafts.csswg.org/css-gaps-1/
TR: https://www.w3.org/TR/css-gaps-1/
Editor: Kevin Babbitt, Microsoft, https://github.com/kbabbitt, w3cid 124689
Abstract: This module introduces several properties to add row and column gap decorations to container layout types such as grid and flex.
WPT Path Prefix: css/css-gaps/
WPT Display: open
urlPrefix: https://drafts.csswg.org/css-grid-3/; type: dfn; spec: CSS-GRID-3; text: masonry container

Introduction

This section is not normative. [[CSS-MULTICOL-1#column-gaps-and-rules]] allows for rules to be drawn between columns in a multicol container. This specification expands upon the 'column-rule-width', 'column-rule-style', and 'column-rule-color' properties, adding equivalents in the row direction, expanding their application to other container layouts, and giving advanced control over where and how gap decorations are painted.

Value Definitions

This specification follows the CSS property definition conventions from [[!CSS2]] using the value definition syntax from [[!CSS-VALUES-3]]. Value types not defined in this specification are defined in CSS Values & Units [[!CSS-VALUES-3]]. Combination with other CSS modules may expand the definitions of these value types. In addition to the property-specific values listed in their definitions, all properties defined in this specification also accept the CSS-wide keywords as their property value. For readability they have not been repeated explicitly.

Gap decorations

Various layouts in CSS such as multicol containers, flex containers, grid containers, and masonry containers position child boxes adjacent to each other with gaps, also known as gutters, between them. Each such gap may contain a gap decoration, which is a visible separator (such as a line) painted between adjacent boxes.
			.grid-with-spans {
			  display: grid;
			  grid-template: repeat(4, 100px) / repeat(4, 100px);
			  gap: 20px;
			  row-rule: 6px solid red;
			  column-rule: 6px solid blue;
			}
		
A grid with spanning items and gap decorations.
			.flex {
			  display: flex;
			  flex-wrap: wrap;
			  gap: 20px;
			  width: 500px;
			  row-rule: 6px solid red;
			  column-rule: 6px solid blue;
			}
		
A flexbox with gap decorations.
serialization/gap-decorations-properties.html

Layout and painting

This specification does not generally define the geometry of gaps in container layouts; that is left to other specifications. See [[CSS-ALIGN-3#gaps]] for definitions pertaining to multicol containers, flex containers, and grid containers. Gap decorations do not take up space. That is, the presence or width of a gap decoration will not alter the placement of anything else. If a gap decoration is wider than its gap, any adjacent boxes will overlap the decoration, and in some cases the decoration may extend outside the box of the container. Gap decorations are painted just above the border of the container. For scrollable containers, note that while the border and background of the container aren't scrolled, the decorations need to scroll along with items in the container. A gap intersection point is defined to exist in each of the following locations: The following examples illustrate the locations of gap intersection points, marked with a magenta + in each case.
			.grid {
				display: grid;
				grid-template: repeat(4, 100px) / repeat(4, 100px);
				gap: 20px;
				background: rgb(255 255 128);
			}
			.grid > * {
				border: 1px dashed black;
			}
		
Locations of gap intersection points in a grid with spanning items. Note the presence of gap intersection points even where a spanning item touches the edge of a container, and where an intersection is flanked by spanning items on either side (for example between #2 and #6, or #4 and #7).
			.flex {
				display: flex;
				flex-wrap: wrap;
				gap: 20px;
				width: 500px;
				background: rgb(255 255 128);
			}
			.flex > * {
				border: 1px dashed black;
			}
		
Locations of gap intersection points in a flexbox. Note the presence of gap intersection points at edges of the container, and the presence of two gap intersection points in close proximity where items in adjacent rows don't quite line up with each other (between #2, #3, #4, and, #5).
Note: [[CSS-ALIGN-3#column-row-gap]] defines cross-direction gaps in flex containers as being between adacent flex items in a single line. Thus, in the example above, even though the right edges of #4 and #7 line up, and the left edges of #5 and #8 line up, the spaces between those two pairs of items are two distinct gaps since they are on different lines. Therefore, the intersection between #4, #5, #7, and #8 contains two gap intersection points whose locations coincide: one at the bottom of the gap between #4 and #5, and one at the top of the gap between #7 and #8. Gap decorations are painted relative to pairs of gap intersection points, in the center of the corresponding gap and parallel to its edges. flex/flex-gap-decorations-001.html flex/flex-gap-decorations-006.html flex/flex-gap-decorations-007.html flex/flex-gap-decorations-008.html flex/flex-gap-decorations-015.html flex/flex-gap-decorations-016.html grid/grid-gap-decorations-001.html multicol/multicol-gap-decorations-001.html multicol/multicol-gap-decorations-002.html multicol/multicol-gap-decorations-003.html multicol/multicol-gap-decorations-005.html multicol/multicol-gap-decorations-006.html multicol/multicol-gap-decorations-007.html multicol/multicol-gap-decorations-013.html multicol/multicol-gap-decorations-015.html multicol/multicol-gap-decorations-016.html If the positions of one or more gaps coincide exactly due to being [=collapsed gutter|collapsed=], at most one decoration will be drawn for that set of gaps. The decoration that is drawn is selected according to the border conflict resolution rules for tables.

Breaking gap decorations into segments: The 'column-rule-break', 'row-rule-break', and 'rule-break' properties

		Name: column-rule-break, row-rule-break
		Value: ''none'' | ''spanning-item'' | ''intersection''
		Initial: ''spanning-item''
		Applies to: grid containers, flex containers, multicol containers, and masonry containers
		Inherited: no
		Animation type: discrete
	
Sets the behavior for breaking decorations within a given gap into segments at visible "T" or "cross" intersections formed by items in the container. Precise details for how to apply these values are given in the steps to determine pairs of gap decoration endpoints.
none
Gap decorations do not start or end at visible "T" or "cross" intersections. Instead, a single continuous decoration is painted from one end of the gap to the other.
spanning-item
Gap decorations start and end at visible "T" intersections but continue through visible "cross" intersections.
intersection
Gap decorations start and end at visible "T" and "cross" intersections.
Issue: Bikeshed these values.
		Name: rule-break
		Value: <<'column-rule-break'>>
		Applies to: Same as 'column-rule-break' and 'row-rule-break'
	
Sets the 'column-rule-break' and 'row-rule-break' properties to the same value. flex/flex-gap-decorations-009.html flex/flex-gap-decorations-010.html grid/grid-gap-decorations-006.html grid/grid-gap-decorations-007.html grid/grid-gap-decorations-008.html grid/grid-gap-decorations-009.html multicol/multicol-gap-decorations-014.html parsing/rule-break-computed.html parsing/rule-break-invalid.html parsing/rule-break-valid.html

Pairing gap intersection points into segments

In the context of a given |gap|, a pair of gap intersection points |a| and |b| is considered discontiguous if a line segment from |a| to |b|, with the same width as |gap|, intersects a child item in the container. Note: The primary use case for this definition is to avoid having gap decorations intersect spanning items when not intended by the author, for example when a spanning item touches the edge of the container, or when a spanning item forms a "T intersection". However, the specific phrasing of the definition is also intended to address cases such as the one below:

The four marked gap intersection points fall along a common gap centerline. However, because item 3 is slightly wider than items 1 and 5, the second and third points from the top are discontiguous. Thus, the two upper gap intersection points form a pair, and the two lower gap intersection points form a pair. (There is an additional pair of gap intersection points, slightly offset to the right of the two middle points, which are not marked. These points will form another pair.)
To determine pairs of gap decoration endpoints within a given |gap|:
  1. Let |pairs| be an empty list. Let |endpoints| be the list of gap intersection points that fall along the centerline of |gap|, ordered from start to end along |gap|'s axis. Let |break| be the used value of either 'column-rule-break' or 'row-rule-break', whichever applies to |gap|.
  2. If |endpoints| contains fewer than 2 items, return |pairs|.
  3. If |break| is other than ''column-rule-break/none'', and the first two items in |endpoints| are discontiguous, remove the first item from |endpoints|, then go back to step 2.
  4. Remove the first item from |endpoints|. Let |start| be equal to that item.
  5. Remove the first item from |endpoints|. Let |end| be equal to that item.
  6. If |endpoints| is non-empty, and any of the following conditions are true...
    1. |break| is ''column-rule-break/none''.
    2. |break| is ''column-rule-break/spanning-item'', and |start| is not discontiguous with the first item in |endpoints|.
    3. |break| is ''column-rule-break/intersection'', and |start| is not discontiguous with the first item in |endpoints|, and the intersection is flanked by spanning items on opposing sides.
    ...then go back to step 5.
  7. Compute the offset for |start| within |gap|. Offset |start| by the result, in the forward direction along |gap|'s axis.
  8. Compute the offset for |end| within |gap|. Offset |end| by the result, in the reverse direction along |gap|'s axis.
  9. Add to |pairs| a tuple consisting of |start| and |end|.
  10. Go back to step 2.
A gap decoration is painted between each pair of endpoints identified using the steps above. The following examples illustrate various settings for the *-rule-break properties. To make the differences more apparent, the *-rule-outset properties are set to ''0''.
			.break-none-grid {
				display: grid;
				grid-template: repeat(4, 100px) / repeat(4, 100px);
				gap: 20px;
				row-rule: 6px solid red;
				column-rule: 6px solid blue;
				rule-break: none;
				rule-outset: 0px;
			}
		
Grid gap decorations with no breaks. Note that the gap decorations extend "behind" items placed in the grid.
			.break-spanning-item-grid {
				display: grid;
				grid-template: repeat(4, 100px) / repeat(4, 100px);
				gap: 20px;
				row-rule: 6px solid red;
				column-rule: 6px solid blue;
				rule-break: spanning-item;
				rule-outset: 0px;
			}
		
Grid gap decorations broken at gap intersection points that are not adjacent to spanning items.
			.break-intersection-grid {
				display: grid;
				grid-template: repeat(4, 100px) / repeat(4, 100px);
				gap: 20px;
				row-rule: 6px solid red;
				column-rule: 6px solid blue;
				rule-break: intersection;
				rule-outset: 0px;
			}
		
Grid gap decorations broken at every gap intersection point that is not flanked by spanning items on opposing sides.
			.break-none-flex {
				display: flex;
				flex-wrap: wrap;
				gap: 20px;
				row-rule: 6px solid red;
				column-rule: 6px solid blue;
				rule-break: none;
				rule-outset: 0px;
			}
		
Flexbox gap decorations with no breaks. Note that each flex line has its own distinct gaps. Therefore, gap decorations in adjacent flex lines are separate from each other even if the gaps happen to line up.
Note: Because flexbox has no concept of spanning items, ''column-rule-break/spanning-item'' on a flexbox has the same effect as ''column-rule-break/none''.
			.break-intersection-flex {
				display: flex;
				flex-wrap: wrap;
				gap: 20px;
				width: 500px;
				gap: 20px;
				row-rule: 6px solid red;
				column-rule: 6px solid blue;
				rule-break: intersection;
				rule-outset: 0px;
			}
		
Flexbox gap decorations broken at every gap intersection point.

Adjusting gap decoration endpoints: The 'column-rule-outset', 'row-rule-outset', and 'rule-outset' properties

		Name: column-rule-outset, row-rule-outset
		Value: <>
		Initial: ''50%''
		Applies to: grid containers, flex containers, multicol containers, and masonry containers
		Inherited: no
		Percentages: refer to the crossing gap width
		Animation type: by computed value type
	
These properties can be used to offset the endpoints of gap decorations relative to the gap intersection points which would normally determine their endpoints. The initial value of ''50%'' places the gap decoration endpoint in the center of the intersection. With a value of ''0'', the gap decoration endpoint will coincide with the edge of the intersection. Positive values extend towards the center of the intersection; negative values recede from it. These offsets also apply at the edges of the container, where positive values may extend beyond the content bounds of the container.
		Name: rule-outset
		Value: <<'column-rule-outset'>>
		Applies to: Same as 'column-rule-outset' and 'row-rule-outset'
	
Sets the 'column-rule-outset' and 'row-rule-outset' properties to the same value.
			.outset-0px {
				column-rule-outset: 0px;
				column-rule-break: intersection;
			}
		
An outset of ''0px'' aligns the ends of gap decorations with adjacent items.
			.outset-5px {
				column-rule-outset: 5px;
				column-rule-break: intersection;
			}
		
An outset of ''5px'' extends the ends of gap decorations slightly beyond the edges of adjacent items.
			.outset-50percent {
				column-rule-outset: 50%;
				column-rule-break: intersection;
			}
		
An outset of ''50%'' - the initial value - extends each end of a gap decoration halfway into its intersection. Neighboring gap decorations "meet in the middle" to create a continuous line. Note that at the edges of the container, the crossing gap width is defined to be ''0'', so the outset value of ''50%'' resolves to ''0'' and thus the gap decoration does not extend beyond the bounds of the container. (Contrast with the previous example, which specified an outset in ''px'' units.)
			.outset-negative-5px {
				column-rule-outset: -5px;
				column-rule-break: intersection;
			}
		
An outset of ''-5px'' shortens the ends of gap decorations relative to the edges of adjacent items.
When considering the gap intersection points within a given gap, each point is assigned a crossing gap width, defined as follows:
At the content edge of the container
The crossing gap width is ''0''.
At an intersection with another gap
The crossing gap width is the used value of the 'column-gap' or 'row-gap' property, whichever applies to the intersecting gap.
To compute the offset for a given gap intersection point |point| within a given |gap|:
  1. Let |width| be the crossing gap width for |point|.
  2. Let |outset| be the computed value of either 'column-rule-outset' or 'row-rule-outset', whichever applies to |gap|. Resolve any percentages in |outset| against |width|.
  3. Let |result| be |width| multiplied by 50%. Subtract |outset| from |result|.
  4. Return |result|.
For details on how the offset is applied, see the steps to determine pairs of gap decoration endpoints. flex/flex-gap-decorations-011.html flex/flex-gap-decorations-013.html flex/flex-gap-decorations-014.html grid/grid-gap-decorations-010.html grid/grid-gap-decorations-011.html grid/grid-gap-decorations-012.html grid/grid-gap-decorations-013.html grid/grid-gap-decorations-014.html grid/grid-gap-decorations-015.html multicol/multicol-gap-decorations-008.html multicol/multicol-gap-decorations-009.html multicol/multicol-gap-decorations-010.html multicol/multicol-gap-decorations-011.html multicol/multicol-gap-decorations-012.html parsing/rule-outset-computed.html parsing/rule-outset-invalid.html parsing/rule-outset-valid.html

Gap decoration paint order: The 'rule-paint-order' property

		Name: rule-paint-order
		Value: row-over-column | column-over-row
		Initial: row-over-column
		Applies to: grid containers, flex containers, and masonry containers
		Inherited: no
		Animation type: discrete
	
Sets the paint order for gap decorations in two-dimensional containers. The following examples illustrate adjustment of gap decoration paint order using the 'rule-paint-order' property.
			.row-over-coulumn {
				rule-paint-order: row-over-column;
				row-rule: 6px solid red;
				column-rule: 6px solid blue;
			}
		
Row-over-column gap decoration paint order.
			rule-paint-order: column-over-row;
			row-rule: 6px solid red;
			column-rule: 6px solid blue;
		
Column-over-row gap decoration paint order.
flex/flex-gap-decorations-012.html grid/grid-gap-decorations-023.html parsing/rule-paint-order-computed.html parsing/rule-paint-order-invalid.html parsing/rule-paint-order-valid.html

Color, style, and width

Property definitions in this section supersede the definitions of properties with the same names in [[CSS-MULTICOL-1]].

Gap decoration color: The 'column-rule-color' and 'row-rule-color' properties

		Name: column-rule-color, row-rule-color
		Value: <> | <>
		Initial: currentcolor
		Applies to: grid containers, flex containers, multicol containers, and masonry containers
		Inherited: no
		Animation type: by computed value type
	
		<line-color-list>          = [ <> ]+

		<auto-line-color-list>     = [ <> ]*
									               <>
									               [ <> ]*

		<line-color-or-repeat>     = [ <> | <> ]

		<repeat-line-color>        = repeat( [ <> ] , [ <> ]+ )

		<auto-repeat-line-color>   = repeat( auto , [ <> ]+ )
	
<>
Sets the color of gap decorations.
grid/grid-gap-decorations-022.html grid/grid-gap-decorations-024.html grid/grid-gap-decorations-025.html grid/grid-gap-decorations-026.html grid/grid-gap-decorations-027.html grid/grid-gap-decorations-028.html parsing/gap-decorations-color-computed.html parsing/gap-decorations-color-invalid.html parsing/gap-decorations-color-valid.html

Gap decoration style: The 'column-rule-style' and 'row-rule-style' properties

		Name: column-rule-style, row-rule-style
		Value: <> | <>
		Initial: none
		Applies to: grid containers, flex containers, multicol containers, and masonry containers
		Inherited: no
		Animation type: discrete
	
		<line-style-list>          = [ <> ]+

		<auto-line-style-list>     = [ <> ]*
									               <>
									               [ <> ]*

		<line-style-or-repeat>     = [ <> | <> ]

		<repeat-line-style>        = repeat( [ <> ] , [ <> ]+ )

		<auto-repeat-line-style>   = repeat( auto , [ <> ]+ )
	
These properties set the styles of gap decorations. The <> values are interpreted as in the collapsing border model. flex/flex-gap-decorations-002.html flex/flex-gap-decorations-003.html flex/flex-gap-decorations-004.html flex/flex-gap-decorations-005.html flex/flex-gap-decorations-017.html flex/flex-gap-decorations-018.html grid/grid-gap-decorations-002.html grid/grid-gap-decorations-003.html grid/grid-gap-decorations-004.html grid/grid-gap-decorations-005.html grid/grid-gap-decorations-016.html grid/grid-gap-decorations-017.html grid/grid-gap-decorations-020.html grid/grid-gap-decorations-021.html parsing/gap-decorations-style-computed.html parsing/gap-decorations-style-invalid.html parsing/gap-decorations-style-valid.html

Gap decoration width: The 'column-rule-width' and 'row-rule-width' properties

		Name: column-rule-width, row-rule-width
		Value: <> | <>
		Initial: medium
		Applies to: grid containers, flex containers, multicol containers, and masonry containers
		Inherited: no
		Computed value: list of absolute lengths, snapped as a border width, or ''0'' under conditions described below
		Animation type: by computed value type
	
		<line-width-list>          = [ <> ]+

		<auto-line-width-list>     = [ <> ]*
									               <>
									               [ <> ]*

		<line-width-or-repeat>     = [ <> | <> ]

		<repeat-line-width>        = repeat( [ <> ] , [ <> ]+ )

		<auto-repeat-line-width>   = repeat( auto , [ <> ]+ )
	
This property sets the widths of gap decorations. Negative values are not allowed. If the computed value of ''column-rule-style'' is ''border-style/none'' or ''border-style/hidden'', then the computed value of ''column-rule-width'' is ''0''. This behavior is for backwards compatibility with [[css-multicol-1#crw]]. Issue: Should the "force to 0" behavior apply when lists of values are involved? If so, how should this be handled with unaligned lists? grid/grid-gap-decorations-018.html grid/grid-gap-decorations-019.html multicol/multicol-gap-decorations-004.html parsing/gap-decorations-width-computed.html parsing/gap-decorations-width-invalid.html parsing/gap-decorations-width-valid.html

Lists of values and the ''repeat-line-color/repeat()'' notation

Each of the properties in this section accepts a space-separated list of values. Setting multiple values in this way allows for varying gap decorations within a given container.
An author might specify alternating red and blue column rules as follows:
			column-rule-width: 1px;
			column-rule-style: solid;
			column-rule-color: red blue;
		
Such a list may contain repeat() notations. Similar to [[css-grid-1#repeat-notation]], these notations allow a series of gap decorations that exhibit a recurring pattern to be written in a more compact form. The generic form of the ''repeat-line-color/repeat()'' syntax is, approximately,
		repeat( [ <> | auto ] , <value>+ )
	
The first argument to ''repeat-line-color/repeat()'' specifies the number of repetitions.
<>
Specifies an integer repeater. An integer repeater expands out to the list of values in the second argument, repeated as many times as specified by the first argument.
An author may write:
					column-rule-color: gray red blue red blue red blue gray;
				
Or shorten to the following, which produces the same sequence of colors:
					column-rule-color: gray repeat(3, red blue) gray;
				
auto
Specfies an auto repeater. An auto repeater will be used to fill in values for gaps that would not otherwise receive values from other parts of the list. At most one ''repeat-line-color/repeat()'' in a given list of values may be an auto repeater.
Continuing from the previous example, if the author does not know how many columns will be in the final layout, they might instead write:
					column-rule-color: gray repeat(auto, red blue) gray;
				
Which will produce a gray decoration in the first and last column gaps, and alternating red and blue decorations in the in-between column gaps.
The second argument to ''repeat-line-color/repeat()'' is a space-separated list of values that would be accepted by the property in which the ''repeat-line-color/repeat()'' appears.
To assign gap decoration values to a list of |gaps| using a list of |values|:
  1. Replace any integer repeaters in |values| with their expanded-out equivalents.
  2. If the list contains no auto repeater, then:
    1. Beginning from the first item in |values| and the first item in |gaps|, assign each value to the corresponding gap. If there are fewer values than gaps, repeat beginning from the first item in |values|, as many times as needed.
    2. End this algorithm.
  3. |values| contains an auto repeater. Let |leading count| be the number of items in |values| before the auto repeater. Let |trailing count| be the number of items in |values| after the auto repeater.
  4. Partition |gaps| as follows:
    1. Let |leading gaps| contain the first |leading count| items in |gaps|.
    2. Let |trailing gaps| contain the last |trailing count| items in |gaps|, excluding any items in |leading gaps|.
    3. Let |auto gaps| contain any items in |gaps| that are not in either |leading gaps| or |trailing gaps|.
  5. If |leading gaps| is non-empty, assign gap decoration values to |leading gaps| using the first |leading count| items in |values|.
  6. If |trailing gaps| is non-empty, assign gap decoration values in reverse to |trailing gaps| using the last |trailing count| items in |values|.
  7. If |auto gaps| is non-empty, assign gap decoration values to |auto gaps| using the list of values in the second argument of the auto repeater.
To assign gap decoration values in reverse to a list of gaps using a list of values, follow the same steps as to assign gap decoration values, except that in step 2, change all instances of "first" to "last".

Gap decoration shorthands: The 'column-rule' and 'row-rule' properties

		Name: column-rule, row-rule
		Value: <> | <>
	
		<gap-rule-list>        = <>#

		<gap-auto-rule-list>   = <>#? ,
								             <> ,
								             <>#?

		<gap-rule-or-repeat>   = <> | <>

		<gap-repeat-rule>      = repeat( <> , <># )

		<gap-auto-repeat-rule> = repeat( auto , <># )

		<gap-rule>             = <> || <> || <>
	
These shorthands set the corresponding width, style, and color properties as a set.

Bi-directional gap decoration shorthands: The 'rule-color', 'rule-style', 'rule-width', and 'rule' properties

		Name: rule-color
		Value: <<'column-rule-color'>>
		Inherited: no
		Applies to: Same as 'column-rule-color' and 'row-rule-color'
	
		Name: rule-style
		Value: <<'column-rule-style'>>
		Inherited: no
		Applies to: Same as 'column-rule-style' and 'row-rule-style'
	
		Name: rule-width
		Value: <<'column-rule-width'>>
		Inherited: no
		Applies to: Same as 'column-rule-width' and 'row-rule-width'
	
		Name: rule
		Value: <<'column-rule'>>
		Inherited: no
		Applies to: Same as 'column-rule' and 'row-rule'
	
These shorthands set the corresponding column and row properties to the same values. flex/flex-gap-decorations-019.html parsing/gap-decorations-bidirectional-shorthands.html

Privacy Considerations

No new privacy considerations have been reported on this specification.

Security Considerations

No new security considerations have been reported on this specification.

Changes

Changes since the 17 April 2025 Working Draft