forked from w3c/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverview.bs
More file actions
2725 lines (2391 loc) · 109 KB
/
Overview.bs
File metadata and controls
2725 lines (2391 loc) · 109 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<pre class='metadata'>
Title: CSS Gaps Module Level 1
Shortname: css-gaps
Level: 1
Status: ED
Prepare for TR: no
Group: csswg
Work Status: revising
Repository: w3c/csswg-drafts
URL: https://drafts.csswg.org/css-gaps-1/
TR: https://www.w3.org/TR/css-gaps-1/
Previous Version: https://www.w3.org/TR/2026/WD-css-gaps-1-20260227/
Previous Version: https://www.w3.org/TR/2025/WD-css-gaps-1-20250417/
Editor: Kevin Babbitt, Microsoft, https://github.com/kbabbitt, w3cid 124689
Abstract: This module defines properties to specify spacing ("gaps") between items in container layouts. It also introduces properties for painting visible separators within those gaps.
WPT Path Prefix: css/css-gaps/
WPT Display: open
</pre>
<pre class='anchors'>
urlPrefix: https://drafts.csswg.org/css-grid-3/; type: dfn; spec: CSS-GRID-3; text: grid lanes container
</pre>
<pre class='link-defaults'>
spec:css-backgrounds-3; type:property; text:border-style
spec:css-backgrounds-3; type:type; text:<line-style>
spec:css-backgrounds-3; type:type; text:<line-width>
spec:css-backgrounds-3; type:value; for:<line-style>; text:hidden
spec:css-backgrounds-3; type:value; for:<line-style>; text:none
spec:css-color-5; type:type; text:<color>
</pre>
<h2 id="intro">
Introduction</h2>
<em>This section is not normative.</em>
[[CSS-MULTICOL-1#column-gaps-and-rules]] defined properties that allow
authors to control the spacing between columns in a [=multicol container=],
and to paint visible separators such as lines in those spaces.
We refer to these visible separators as [=gap decorations=].
This specification expands upon the previously defined properties.
It adds equivalent properties for the row direction,
applies the full set of properties to other container types,
and gives additional control over where and how gap decorations are painted.
<h3 id="values">
Value Definitions</h3>
This specification follows the <a href="https://www.w3.org/TR/CSS2/about.html#property-defs">CSS property definition conventions</a> from [[!CSS2]]
using the <a href="https://www.w3.org/TR/css-values-3/#value-defs">value definition syntax</a> 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 <a>CSS-wide keywords</a> as their property value.
For readability they have not been repeated explicitly.
<!-- Big Text: Gaps
███▌ ███▌ ████▌ ███▌
█▌ █▌ ▐█ ▐█ █▌ █▌ █▌ █▌
█▌ █▌ █▌ █▌ █▌ █▌
█▌ ██▌ █▌ █▌ ████▌ ███▌
█▌ █▌ █████▌ █▌ █▌
█▌ █▌ █▌ █▌ █▌ █▌ █▌
███▌ █▌ █▌ █▌ ███▌
-->
<h2 id='gaps'>
Gaps Between Boxes</h2>
While 'margin' and 'padding' can be used to specify visual spacing around individual boxes,
it's sometimes more convenient to globally specify spacing
<em>between</em> adjacent boxes within a given layout context,
particularly when the spacing is different between sibling boxes
as opposed to between the first/last box and the container's edge.
The 'gap' property,
and its 'row-gap' and 'column-gap' sub-properties,
provide this functionality for
<a href="http://www.w3.org/TR/css3-multicol/">multi-column</a>,
<a href="http://www.w3.org/TR/css-flexbox/">flex</a>,
and <a href="http://www.w3.org/TR/css-grid/">grid layout</a>.
A <dfn>gap</dfn> is either a <dfn>column gap</dfn> or <dfn>row gap</dfn>,
whose definitions vary by type of container:
<dl>
<dt id="gap-multicol"><a>multi-column containers</a>
<dd>
A [=column gap=] is the [=gutter=] between adjacent <a>column boxes</a>,
see [[CSS-MULTICOL-1]].
A [=row gap=] is the [=gutter=] between the rows of [=column boxes=] established by 'column-height',
see [[CSS-MULTICOL-2]].
<dt id="gap-flex"><a>flex containers</a>
<dd>
When applied to the <a>main axis</a>
(e.g. [=column gap=] in a ''flex-flow/row'' <a>flex container</a>),
refers to the [=gutter=] between items
(as if an additional fixed-size margin were inserted
between adjacent <a>flex items</a>
in a single line).
When applied to the <a>cross axis</a>
(e.g. [=row gap=] in a ''flex-flow/row'' <a>flex container</a>),
refers to the [=gutter=] between adjacent <a>flex lines</a>.
<dt id="gap-grid"><a>grid containers</a>
<dd>
[=Row gap=] and [=column gap=],
in the context of a <a>grid container</a>,
refer to the [=gutters=] between <a>grid rows</a> and <a>grid columns</a>,
respectively.
See [[css-grid-1#gutters]] for precise details.
</dl>
Gutters effect a minimum spacing between items:
additional spacing may be added by 'justify-content'/'align-content'.
Such additional space increases the size of the corresponding [=gaps=].
In all cases, the [=gap=] disappears when it coincides with
a [=fragmentation break=]. [[CSS-BREAK-3]]
Note: Table boxes do not use the 'gap' properties
to specify separation between their cells.
Instead, they use the 'border-spacing' property,
which has slightly different functionality:
it inherits,
and it also specifies the additional spacing between the outermost cells
and the border of the table
(similar to ''space-evenly'' rather than ''space-between'').
<div class="example">
<figure>
<img alt="" src="images/multicol-gaps-2.png">
<figcaption>
[=Column gaps=] in orange in a multicol container with a spanner element.
Note that [=column gaps=] break when they encounter the spanner.
</figcaption>
</figure>
</div>
<div class="example">
<figure>
<img alt="" src="images/multicol-gaps.png">
<figcaption>
Gaps in a multicol container with `column-wrap: wrap`; [=column gaps=] in orange and [=row gaps=] in blue).
Note that [=column gaps=] in multicol containers do not overlap [=row gaps=], similar to flex.
</figcaption>
</figure>
</div>
<div class="example">
<figure>
<img alt="" src="images/grid-gaps.png">
<figcaption>
Gaps in a grid container; [=column gaps=] in orange and [=row gaps=] in blue.
Note the shaded areas where gaps overlap.
</figcaption>
</figure>
</div>
<div class="example">
<figure>
<img alt="" src="images/flex-gaps.png">
<figcaption>
Gaps in a flex container; [=column gaps=] in orange and [=row gaps=] in blue.
Note that, unlike in grid, gaps in flex do not overlap.
</figcaption>
</figure>
</div>
<h3 id='column-row-gap'>
Row and Column Gutters: the 'row-gap' and 'column-gap' properties</h3>
<pre class='propdef'>
Name: row-gap, column-gap
Value: normal | <<length-percentage [0,∞]>> | <<line-width>>
Initial: normal
Applies to: <a>multi-column containers</a>, <a>flex containers</a>, <a>grid containers</a>
Inherited: no
Percentages: see [[#gap-percent]]
Computed value: specified keyword, else a computed <<length-percentage>> value
Animation type: by computed value type
</pre>
These properties specify fixed-length <dfn export lt="gutter">gutters</dfn>
between items in the container,
adding space between them--
in a manner similar to the ''justify-content/space-between'' keyword
of the <a>content-distribution properties</a>,
but of a fixed size instead of as a fraction of remaining space.
The 'column-gap' property specifies spacing between “columns”,
separating boxes in the container's <a>inline axis</a>
similar to <a>inline-axis</a> margin;
while 'row-gap' indicates spacing between “rows”,
separating boxes in the container's <a>block axis</a>.
Values have the following meanings:
<dl dfn-type=value dfn-for="row-gap, column-gap, gap">
: <<length-percentage [0,∞]>>
: <<line-width>>
::
Specifies a [=row gap=] or [=column gap=]
as defined by the layout modes to which it applies.
Negative values are invalid.
For percentages,
see [[#gap-percent]].
: <dfn>normal</dfn>
:: The value ''gap/normal'' represents
a used value of ''1em'' on <a>multi-column containers</a>,
and a used value of ''0px'' in all other contexts.
</dl>
<h3 id='gap-shorthand'>
Gap Shorthand: the 'gap' property</h3>
<pre class='propdef'>
Name: gap
Value: <<'row-gap'>> <<'column-gap'>>?
Initial: see individual properties
Applies to: <a>multi-column containers</a>, <a>flex containers</a>, <a>grid containers</a>
Inherited: no
Percentages: refer to corresponding dimension of the content area
Computed value: see individual properties
Animation type: by computed value type
</pre>
This property is a <a>shorthand</a> that sets 'row-gap' and 'column-gap' in one declaration.
If <<'column-gap'>> is omitted,
it's set to the same value as <<'row-gap'>>.
<div class='example'>
<figure>
<img src="images/gutters-gaps.svg" alt="A diagram showing how margins and padding add to the visible gutter size" width="500" height="616">
</figure>
Note: The 'gap' property is only one component of the visible “gutter” or “alley” created between boxes.
Margins, padding, or the use of distributed alignment
may increase the visible separation between boxes
beyond what is specified in 'gap'.
</div>
<h3 id='gap-percent'>
Percentages In 'gap' Properties</h3>
In general,
gaps introduced by the 'gap' properties
are intended to act like an empty item/track/etc
with the gap's size;
in other words,
an author should be able to reproduce the effects of 'gap'
by just inserting additional empty items/tracks/etc
into the container.
'gap' always resolves percentages against
the corresponding size of the [=content box=]
of the element.
When this size is definite,
the behavior is well-defined
and consistent across layout modes.
But since different layout modes treat [=cyclic percentage sizes=] for items/tracks/etc differently,
'gap' does as well:
: In Grid Layout
::
<a href="https://www.w3.org/TR/css-sizing-3/#percentage-sizing">As in the min size properties and margins/paddings</a> [[CSS-SIZING-3]],
[=cyclic percentage sizes=] resolve against zero
for determining intrinsic size contributions,
but resolve against the box’s content box
when laying out the box’s contents.
: In Flex Layout
::
[=Cyclic percentage sizes=] resolve against zero in all cases.
<h3 id='gap-legacy'>
Legacy Gap Properties: the 'grid-row-gap', 'grid-column-gap', and 'grid-gap' properties</h3>
The Grid Layout module was originally written with its own set of [=gutter=] properties,
before all such properties were unified into the existing 'row-gap'/'column-gap' naming.
For compatibility with legacy content,
these grid-prefixed names must be supported as follows:
* <dfn property>grid-row-gap</dfn> as a [=legacy name alias=] of the 'row-gap' property
* <dfn property>grid-column-gap</dfn> as a [=legacy name alias=] of the 'column-gap' property
* <dfn property>grid-gap</dfn> as a [=legacy name alias=] of the 'gap' property
<!-- Big Text: Decorations
████▌ █████▌ ███▌ ███▌ ████▌ ███▌ █████▌ ████ ███▌ █ █▌ ███▌
█▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ ▐█ ▐█ █▌ ▐▌ █▌ █▌ █▌ █▌ █▌ █▌
█▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ ▐▌ █▌ █▌ ██▌ █▌ █▌
█▌ █▌ ████ █▌ █▌ █▌ ████▌ █▌ █▌ █▌ ▐▌ █▌ █▌ █▌▐█ █▌ ███▌
█▌ █▌ █▌ █▌ █▌ █▌ █▌▐█ █████▌ █▌ ▐▌ █▌ █▌ █▌ ██▌ █▌
█▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ ▐█ █▌ █▌ █▌ ▐▌ █▌ █▌ █▌ █▌ █▌ █▌
████▌ █████▌ ███▌ ███▌ █▌ █▌ █▌ █▌ █▌ ████ ███▌ █▌ ▐▌ ███▌
-->
<h2 id="gap-decorations">
Gap decorations</h2>
[=Gaps=] may contain a <dfn>gap decoration</dfn>,
which is a visible separator (such as a line) painted between adjacent boxes.
<a>Gap decorations</a> do not take up space.
That is, the presence or width of a <a>gap decoration</a> will not alter the placement of anything else.
If a <a>gap decoration</a> 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.
<a>Gap decorations</a> 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.
[=Gap decorations=] follow the definitions of "column" and "row" laid out by the container to which the properties are applied.
They depend on the container type taking [=writing mode=] into account when determining the meanings of these terms.
For examples, see:
[[CSS-MULTICOL-2#the-multi-column-model]],
[[CSS-FLEXBOX-1#flex-direction-property]],
and
[[CSS-GRID-1#grid-concepts]].
Properties in this specification whose names begin with "column" apply to [=column gaps=],
and properties in this specification whose names begin with "row" apply to [=row gaps=].
<!--
<div class="example">
<pre>
.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;
}
</pre>
<figure>
<img alt="" src="images/example-grid-with-spans.png">
<figcaption>A grid with spanning items and gap decorations.</figcaption>
</figure>
</div>
<div class="example">
<pre>
.flex {
display: flex;
flex-wrap: wrap;
gap: 20px;
width: 500px;
row-rule: 6px solid red;
column-rule: 6px solid blue;
}
</pre>
<figure>
<img alt="" src="images/example-flex.png">
<figcaption>A flexbox with gap decorations.</figcaption>
</figure>
</div>
-->
<!-- Big Text: Geometry
███▌ █████▌ ███▌ █ █ █████▌ █████▌ ████▌ █ ▐▌
█▌ █▌ █▌ █▌ █▌ ██ ██ █▌ █▌ █▌ █▌ ▐▌ █
█▌ █▌ █▌ █▌ █▌█ █▐█ █▌ █▌ █▌ █▌ █ ▐▌
█▌ ██▌ ████ █▌ █▌ █▌ █ ▐█ ████ █▌ ████▌ ▐▌█
█▌ █▌ █▌ █▌ █▌ █▌ ▐█ █▌ █▌ █▌▐█ █▌
█▌ █▌ █▌ █▌ █▌ █▌ ▐█ █▌ █▌ █▌ ▐█ █▌
███▌ █████▌ ███▌ █▌ ▐█ █████▌ █▌ █▌ █▌ █▌
-->
<h3 id="geometry">
Geometry</h3>
[=Gap decorations=] are painted within a [=gap=] as one or more [=gap decoration segments=].
<h4 id="segment-endpoints">
Segment endpoints</h4>
A <dfn>segment endpoint</dfn> is a point on a [=gap's=] centerline where a <a>gap decoration segment</a>
may start or end.
There are two endpoint types:
<ul>
<li><dfn>start segment endpoint</dfn>: Point closest to the [=start=] side of the [=gap=].
<li><dfn>end segment endpoint</dfn>: Point closest to the [=end=] side of the [=gap=].
</ul>
<div algorithm="create segment endpoints">
To <dfn>create segment endpoints</dfn> for a gap |G|:
<ol>
<li>Bounds of a Gap:
<p>Create endpoints at |G|'s two bounds:
<ul>
<li>At the centerpoint of |G|'s start edge, create a <a>start segment endpoint</a>.
<li>At the centerpoint of |G|'s end edge, create an <a>end segment endpoint</a>.
</ul>
<p class="note">When a gap runs to the content boundary, these endpoints coincide with the corresponding content edge.
<li>Within a Gap:
<p>A <dfn>gap junction</dfn> is a region of |G|
where one or more [=gaps=] abut or overlap |G|.
Two [=segment endpoints=] are created for each [=gap junction=]:
<ul>
<li>Entering a [=gap junction=]: At the point where a cross gap appears on at least one side of |G|, create an <a>end segment endpoint</a>.
<li>Exiting a [=gap junction=]: At the point where no cross gap exists on either side of |G|, create a <a>start segment endpoint</a>.
</ul>
<p class="note">This ordering (end segment endpoint, start segment endpoint) reflects that the [=gap junction=] corresponds to
the end of one track/item/column and the beginning of another.
</ol>
</div>
The following examples illustrate the locations of <a>segment endpoints</a>,
with a purple <span style="color:#72C">+</span> for <a> start segment endpoints</a> and a
green <span style="color:#285">+</span> for <a> end segment endpoints</a> in each case.
[=Gap junctions=] are shown with a dashed box.
<div class="example">
<pre>
.grid-with-spans {
display: grid;
grid-template: repeat(4, 100px) / repeat(4, 100px);
gap: 20px;
background: rgb(255 255 128);
}
.grid > * {
border: 1px dashed black;
}
</pre>
<figure>
<img alt="" src="images/example-grid-segment-endpoints.png">
<figcaption>
Locations of <a>segment endpoints</a> and [=gap junctions=] in a grid with spanning items.
[=Segment endpoints=] are created at the bounds of each gap (which coincide with the edges of the container),
and within each gap in an end-start manner where the row and column gaps overlap.
</figcaption>
</figure>
</div>
<div class="example">
<pre>
.flex {
display: flex;
flex-wrap: wrap;
gap: 20px;
width: 500px;
background: rgb(255 255 128);
}
.flex > * {
border: 1px dashed black;
}
</pre>
<figure>
<img alt="" src="images/flex-and-segment-endpoints.png">
<figcaption>Locations of <a>segment endpoints</a> and [=gap junctions=] in a flex container.
Column gaps create endpoints at their bounds; some bounds coincide with the container edges
(like the start of the gaps between #1 and #2, and #2 and #3 which coincide with the top edge of the container,
and the end of the gap between #7 and #8 which coincides with the bottom edge of the container).
Row gaps (between flex lines) create endpoints at their bounds,
which coincide with the left and right edges of the container.
Where column gaps abut row gaps, two endpoints are created in an end-start manner.
</figcaption>
</figure>
</div>
<div class="example">
<pre>
.multi-column {
column-count: 3;
column-width: 100px;
column-height: 50px;
column-wrap: wrap;
gap: 20px;
background: rgb(255 255 128);
}
.multi-column > * {
height: 100px;
border: 1px dashed black;
}
</pre>
<figure>
<img alt="" src="images/multi-col-segment-endpoints.png">
<figcaption>Locations of <a>segment endpoints</a> and [=gap junctions=] in a multi-column container.
Column gaps (between column boxes) create endpoints at their bounds; some bounds coincide with the container edges
(like the starts of the first 2 column gaps which coincide with the top edge,
and the ends of the last 2 column gaps which coincide with the bottom edge).
The row gap (between rows of column boxes) creates endpoints at its bounds,
which coincide with the left and right edges of the container.
Where column gaps abut the row gap, two endpoints are created in an end-start manner.
</figcaption>
</figure>
</div>
<h4 id="segments">
Gap decoration segments</h4>
<h5 class="no-toc no-num" id="segments-definitions">
Definitions</h5>
A <dfn>gap decoration segment</dfn> is formed by pairing a [=start segment endpoint=] with an [=end segment endpoint=].
Each [=gap=] forms a collection of [=gap decoration segments=].
In this section, we represent a [=gap decoration segment=] |s| as
<code>|s| = [|s|.start, |s|.end]</code>,
where <code>|s|.start</code> is the <a>start segment endpoint</a> of the segment,
and <code>|s|.end</code> is the <a>end segment endpoint</a> of the segment.
Let <dfn>UNION</dfn>(|s1|, |s2|) be equal to [|s1|.start, |s2|.end].
A [=gap decoration segment=] is <dfn>flanked by spanning items</dfn> if, for
every [=gap junction=] between its endpoints, there exist items on opposing sides of
the gap that span across all perpendicular [=gaps=] contributing to that junction.
In the context of a given [=gap=], a pair of <a>segment endpoints</a> |a| and |b| is considered <dfn>discontiguous</dfn>
if a line segment from |a| to |b|, with the same width as the [=gap=], intersects a child item in the container.
<h5 class="no-toc no-num" id="segments-algorithms">
Algorithms</h5>
<div algorithm>
To <dfn>determine gap decoration segments</dfn> for a given [=gap=] |G|:
<ol>
<li>
Let |S| be an empty list.
</li>
<li>
Let |endpoints| be the result of [=creating segment endpoints=] for |G|,
ordered by their position along |G|'s centerline from start to end.
Note: This list is guaranteed to contain an even number of elements that strictly alternate
between [=start segment endpoint=] and [=end segment endpoint=], beginning with a [=start segment endpoint=].
</li>
<li>
If |endpoints| is empty, return |S|.
</li>
<li>
Let |break| be the used value of either 'column-rule-break' or 'row-rule-break', whichever applies to the gap.
</li>
<li>If |break| is ''column-rule-break/none'':
<ol>
<li>Let |first| be the first item in |endpoints|.
<li>Let |last| be the last item in |endpoints|.
<li>Create a [=gap decoration segment=] |segment| = [|first|, |last|].
<li>[=Apply offsets to a segment|Apply offsets to=] |segment|, then append it to |S|.
<li>Return |S|.
</ol>
</li>
<li><em>Empty Check:</em> If |endpoints| is empty, return |S|.
<li>Create a [=gap decoration segment=] |s| from the first two items in |endpoints|. Remove them both from the list.
<li>If |s|'s endpoints are <a>discontiguous</a>, go back to <em>Empty Check</em>.
<li>While |endpoints| is not empty:
<ol>
<li>Create a [=gap decoration segment=] |next| from the first two items in |endpoints|, leaving them both in the list.
<li>Let |candidate| be <a>UNION</a>(|s|, |next|).
<li>If |candidate|'s endpoints are <a>discontiguous</a>, exit this loop.
<li>If |break| is ''column-rule-break/intersection'' and |candidate| is not <a>flanked by spanning items</a>, exit this loop.
<li>Remove the first two items from |endpoints|.
<li>Set |s| to <a>UNION</a>(|s|, |next|).
</ol>
</li>
<li>[=Apply offsets to a segment|Apply offsets to=] |s|, then append it to |S|.
<li>Go back to <em>Empty Check</em>.
</ol>
</div>
<div algorithm>
To <dfn>apply offsets to a segment</dfn> |s| = [|start|, |end|]:
<ol>
<li>Offset |start| by the used value of the applicable [[#inset|rule-inset]] property.
<li>Offset |end| by the used value of the applicable [[#inset|rule-inset]] property.
<li>Update |s| with the adjusted [|start|, |end|].
</ol>
</div>
<div class="example">
<figure>
<img alt="" src="images/grid-gap-decoration-segments.png">
<figcaption>
Illustration of <a>gap decoration segments</a> (blue and red rectangles) in a grid container.
The segments are drawn between pairs of <a>segment endpoints</a>,
with <a>start segment endpoints</a> marked with purple crosses and <a>end segment endpoints</a> marked with green crosses.
</figcaption>
</figure>
</div>
<div class="example">
<figure>
<img alt="" src="images/flex-gap-decoration-segments.png">
<figcaption>
Illustration of <a>gap decoration segments</a> (blue and red rectangles) in a flex container.
The segments are drawn between pairs of <a>segment endpoints</a>,
with <a>start segment endpoints</a> marked with purple crosses and <a>end segment endpoints</a> marked with green crosses.
</figcaption>
</figure>
</div>
<div class="example">
<figure>
<img alt="" src="images/multicol-gap-decoration-segments.png">
<figcaption>
Illustration of <a>gap decoration segments</a> (blue and red rectangles) in a multicol container (with column-wrap: wrap).
The segments are drawn between pairs of <a>segment endpoints</a>,
with <a>start segment endpoints</a> marked with purple crosses and <a>end segment endpoints</a> marked with green crosses.
</figcaption>
</figure>
</div>
<div class="example" id="example-unpaired-endpoints-1">
<figure>
<img alt="" src="images/flex-negative-gap-decoration-segments.png">
<figcaption>
Illustration of <a>gap decoration segments</a> (blue and red rectangles) in a flex container.
The segments are drawn between pairs of <a>segment endpoints</a>,
with <a>start segment endpoints</a> marked with purple crosses and <a>end segment endpoints</a> marked with green crosses.
</figcaption>
</figure>
</div>
<div class="example" id="example-unpaired-endpoints-2">
<figure>
<img alt="" src="images/flex-negative-gap-decoration-segments-example-2.png">
<figcaption>
Illustration of <a>gap decoration segments</a> (blue and red rectangles) in a flex container.
The segments are drawn between pairs of <a>segment endpoints</a>,
with <a>start segment endpoints</a> marked with purple crosses and <a>end segment endpoints</a> marked with green crosses.
</figcaption>
</figure>
</div>
<wpt>
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
flex/flex-gap-decorations-020.html
flex/flex-gap-decorations-021.html
flex/flex-gap-decorations-022.html
flex/flex-gap-decorations-023.html
flex/flex-gap-decorations-024.html
flex/flex-gap-decorations-025.html
flex/flex-gap-decorations-026-crash.html
flex/flex-gap-decorations-027.html
flex/flex-gap-decorations-032.html
flex/flex-gap-decorations-033.html
flex/flex-gap-decorations-039.html
flex/flex-gap-decorations-040.html
flex/flex-gap-decorations-041.html
flex/flex-gap-decorations-042.html
flex/flex-gap-decorations-043.html
flex/flex-gap-decorations-044.html
flex/flex-gap-decorations-045.html
flex/flex-gap-decorations-046.html
flex/flex-gap-decorations-047.html
flex/flex-gap-decorations-048.html
flex/flex-gap-decorations-049.html
flex/flex-gap-decorations-056.html
flex/flex-gap-decorations-057.html
flex/flex-gap-decorations-058.html
flex/flex-gap-decorations-059.html
flex/flex-gap-decorations-060.html
flex/flex-gap-decorations-061.html
flex/flex-gap-decorations-repaint-on-child-resize.html
flex/flex-gap-decorations-writing-mode.html
grid/grid-gap-decorations-001.html
grid/grid-gap-decorations-029.html
grid/grid-gap-decorations-030.html
grid/grid-gap-decorations-031.html
grid/grid-gap-decorations-032.html
grid/grid-gap-decorations-033.html
grid/grid-gap-decorations-034.html
grid/grid-gap-decorations-035.html
grid/grid-gap-decorations-036.html
grid/grid-gap-decorations-037.html
grid/grid-gap-decorations-041-crash.html
grid/grid-gap-decorations-042.html
grid/grid-gap-decorations-043-crash.html
grid/grid-gap-decorations-044-crash.html
grid/grid-gap-decorations-045.html
grid/grid-gap-decorations-046.html
grid/grid-gap-decorations-047.html
grid/grid-gap-decorations-066.html
grid/grid-gap-decorations-repaint-on-child-resize.html
grid/grid-gap-decorations-repaint-on-item-position-change.html
grid/grid-gap-decorations-repaint-on-item-span-change.html
grid/grid-gap-decorations-writing-mode.html
grid/subgrid/subgrid-gap-decorations-001.html
grid/subgrid/subgrid-gap-decorations-002.html
grid/subgrid/subgrid-gap-decorations-003.html
grid/subgrid/subgrid-gap-decorations-009.html
grid/subgrid/subgrid-gap-decorations-010.html
grid/subgrid/subgrid-gap-decorations-011.html
grid/subgrid/subgrid-gap-decorations-012.html
grid/subgrid/subgrid-gap-decorations-013.html
grid/subgrid/subgrid-gap-decorations-014.html
grid/subgrid/subgrid-gap-decorations-015.html
grid/subgrid/subgrid-gap-decorations-016.html
grid/subgrid/subgrid-gap-decorations-018.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
multicol/multicol-gap-decorations-018.html
multicol/multicol-gap-decorations-024.html
multicol/multicol-gap-decorations-040.html
multicol/multicol-gap-decorations-repaint-on-content-resize.html
multicol/multicol-gap-decorations-writing-mode.html
</wpt>
<!-- Big Text: Breaks
████▌ ████▌ █████▌ ███▌ █▌ █▌ ███▌
█▌ █▌ █▌ █▌ █▌ ▐█ ▐█ █▌ █▌ █▌ █▌
█▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌█▌ █▌
█████ ████▌ ████ █▌ █▌ ██ ███▌
█▌ █▌ █▌▐█ █▌ █████▌ █▌█▌ █▌
█▌ █▌ █▌ ▐█ █▌ █▌ █▌ █▌ █▌ █▌ █▌
████▌ █▌ █▌ █████▌ █▌ █▌ █▌ █▌ ███▌
-->
<h3 id="break">
Break behaviors at intersections: The 'column-rule-break', 'row-rule-break', and 'rule-break' properties</h3>
<pre class='propdef'>
Name: column-rule-break, row-rule-break
Value: ''none'' | ''normal'' | ''intersection''
Initial: ''normal''
Applies to: <a>grid containers</a>, <a>flex containers</a>, <a>multicol containers</a>, and <a>grid lanes containers</a>
Inherited: no
Animation type: discrete
</pre>
These properties set 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 gap decoration segments=].
<dl dfn-type="value" dfn-for="column-rule-break, row-rule-break">
<dt><dfn>none</dfn>
<dd>
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.
</dd>
<dt><dfn>normal</dfn>
<dd>
Behavior depends on the type of container.
<dl>
<dt><a>Grid containers</a>
<dd>
Gap decorations start and end at visible "T" intersections
but continue through visible "cross" intersections.
</dd>
<dt><a>Flex containers</a>
<dd>
Behaves the same as ''column-rule-break/none''.
</dd>
<dt><a>Multicol containers</a>
<dd>
On 'column-rule-break', behaves the same as ''column-rule-break/intersection''.
On 'row-rule-break', behaves the same as ''row-rule-break/none''.
</dd>
</dl>
</dd>
<dt><dfn>intersection</dfn>
<dd>
Gap decorations start and end at visible "T" and "cross" intersections.
</dd>
</dl>
<wpt>
flex/flex-gap-decorations-009.html
flex/flex-gap-decorations-010.html
flex/flex-gap-decorations-028.html
flex/flex-gap-decorations-031.html
flex/flex-gap-decorations-034.html
flex/flex-gap-decorations-035.html
flex/flex-gap-decorations-036.html
flex/flex-gap-decorations-037.html
flex/flex-gap-decorations-050.html
flex/flex-gap-decorations-051.html
flex/flex-gap-decorations-052.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
grid/grid-gap-decorations-040.html
grid/subgrid/subgrid-gap-decorations-004.html
grid/subgrid/subgrid-gap-decorations-005.html
grid/subgrid/subgrid-gap-decorations-006.html
multicol/multicol-gap-decorations-014.html
multicol/multicol-gap-decorations-020.html
multicol/multicol-gap-decorations-025.html
multicol/multicol-gap-decorations-026.html
multicol/multicol-gap-decorations-034.html
</wpt>
<pre class='propdef shorthand'>
Name: rule-break
Value: <<'column-rule-break'>>
Applies to: Same as 'column-rule-break' and 'row-rule-break'
</pre>
This [=shorthand property=] sets 'column-rule-break' and 'row-rule-break' to the same value.
<wpt>
parsing/rule-break-computed.html
parsing/rule-break-invalid.html
parsing/rule-break-shorthand.html
parsing/rule-break-valid.html
</wpt>
The following examples illustrate various settings for the <a href="#break">*-rule-break</a> properties.
<div class="example">
<pre>
.break-normal-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: normal;
}
</pre>
<figure>
<img alt="" src="images/example-break-normal-grid.png">
<figcaption>
Default break behavior for [=gap decorations=] in a grid.
Each decoration stops when it encounters an item spanning across the gap.
</figcaption>
</figure>
</div>
<div class="example">
<pre>
.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;
}
</pre>
<figure>
<img alt="" src="images/example-break-none-grid.png">
<figcaption>
Grid <a>gap decorations</a> with no breaks.
Note that the <a>gap decorations</a> extend "behind" items placed in the grid.
</figcaption>
</figure>
</div>
<div class="example">
<pre>
.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;
}
</pre>
<figure>
<img alt="" src="images/example-break-intersection-grid.png">
<figcaption>
Grid <a>gap decorations</a> contained within each [=gap decoration segment=]
that is not flanked by spanning items on opposing sides.
</figcaption>
</figure>
</div>
<div class="example">
<pre>
.break-normal-multicol {
column-width: 150px;
column-height: 300px;
gap: 1em;
row-rule: 4px solid red;
column-rule: 4px solid blue;
rule-break: normal;
}
</pre>
<figure>
<img alt="" src="images/example-break-normal-multicol.png">
<figcaption>
Multicol [=gap decorations=] with rule-break set to ''column-rule-break/normal''.
Note that in the column direction it behaves as if rule-break were set to ''intersection'',
while in the row direction it behaves as if rule-break were set to ''none''.
</figcaption>
</figure>
</div>
<div class="example">
<pre>
.break-intersection-multicol {
column-width: 150px;
column-height: 300px;
gap: 1em;
row-rule: 4px solid red;
column-rule: 4px solid blue;
rule-break: intersection;
}
</pre>
<figure>
<img alt="" src="images/example-break-intersection-multicol.png">
<figcaption>
Multicol <a>gap decorations</a> with rule-break set to ''intersection''.
</figcaption>
</figure>
</div>
<div class="example">
<pre>
.break-normal-flex {
display: flex;
flex-wrap: wrap;
gap: 20px;
row-rule: 6px solid red;
column-rule: 6px solid blue;
rule-break: normal;
}
</pre>
<figure>
<img alt="" src="images/example-break-normal-flex.png">
<figcaption>
Default break behavior for [=gap decorations=] in a flex container.
</figcaption>
</figure>
Note that each flex line has its own distinct [=gaps=] between items.
This has two implications:
<ol>
<li>[=Gap decorations=] in adjacent flex lines are separate from each other even if the gaps happen to line up.
<li>''column-rule-break/none'' would have the same visual effect as ''column-rule-break/normal''.
</ol>
</div>
<div class="example">
<pre>
.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;
}
</pre>
<figure>
<img alt="" src="images/example-break-intersection-flex.png">
<figcaption>
Flexbox <a>gap decorations</a> contained within each [=gap decoration segment=].
</figcaption>
</figure>
</div>
<!-- Big Text: Insets
████ █ █▌ ███▌ █████▌ █████▌ ███▌
▐▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌
▐▌ ██▌ █▌ █▌ █▌ █▌ █▌
▐▌ █▌▐█ █▌ ███▌ ████ █▌ ███▌
▐▌ █▌ ██▌ █▌ █▌ █▌ █▌
▐▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌
████ █▌ ▐▌ ███▌ █████▌ █▌ ███▌
-->
<h3 id="inset">
Adjusting gap decoration endpoints: The 'rule-inset' properties</h3>
<pre class='propdef'>
Name: 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
Value: <<inset-value>>
Initial: ''0''
Applies to: <a>grid containers</a>, <a>flex containers</a>, <a>multicol containers</a>, and <a>grid lanes containers</a>
Inherited: no
Percentages: refer to the <a>crossing gap width</a>
Animation type: by computed value type
</pre>