-
Notifications
You must be signed in to change notification settings - Fork 672
/
Overview.bs
2674 lines (2291 loc) · 114 KB
/
Overview.bs
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 Box Alignment Module Level 3
Shortname: css-align
Level: 3
Group: csswg
Status: ED
Work Status: Refining
ED: https://drafts.csswg.org/css-align/
TR: https://www.w3.org/TR/css-align-3/
Editor: Elika J. Etemad / fantasai, Apple, http://fantasai.inkedblade.net/contact, w3cid 35400
Editor: Tab Atkins Jr., Google, http://xanthir.com/contact/, w3cid 42199
Abstract: This module contains the features of <a href="https://www.w3.org/TR/CSS/">CSS</a> relating to the alignment of boxes within their containers in the various CSS box layout models: block layout, table layout, flex layout, and grid layout. (The alignment of text and inline-level content is defined in [[CSS-TEXT-3]] and [[CSS-INLINE-3]].)
Ignored Terms: table cell, stretch
At Risk: ''[ first | last ]? baseline''
At Risk: the <<overflow-position>> keywords
At Risk: the scrollable-area safety trigger into ''safe'' mode when no <<overflow-position>> is specified
At Risk: the ''legacy'' keyword for 'justify-items'
At Risk: the effect of the <a>box alignment properties</a> on absolutely-positioned boxes with ''left/auto'' offsets
</pre>
<pre class=link-defaults>
spec:css2; type:property;
text:vertical-align
text:max-width
text:max-height
text:min-width
text:min-height
spec:css-cascade-3; type:value; text:initial
spec:css-display-3; type:property; text:display
spec:css-flexbox-1; type:dfn;
text:flex line
spec:css-grid-1; type:dfn;
text:collapsed gutter
spec:css-inline-3; type:property;
text:dominant-baseline
text:alignment-baseline
spec:css-multicol-1; type:dfn;
text:multi-column container
text:column box
spec:css-overflow-3; type:dfn; text:scroll container
spec:css-position-3; type:property; text:left
spec:css-writing-modes-3; type:dfn;
text:dominant baseline
text:start
text:end
spec:selectors-3; type:dfn; text:first formatted line
spec:css2; type:dfn; text:line box
</pre>
<style>
.issue th:first-child { text-align: left !important; }
[rowspan] > img { float: right; }
[rowspan] { vertical-align: middle; }
table small { display: block; }
table.align-details { width: 100%; }
.align-details th {
font: inherit;
font-style: italic;
white-space: nowrap; width: 1em;
vertical-align: baseline; }
.align-details td { vertical-align: baseline; }
</style>
<h2 id="intro">
Introduction</h2>
CSS Levels 1 and 2 allowed for the alignment of text via 'text-align'
and the alignment of blocks by balancing ''margin/auto'' margins.
However, except in table cells,
vertical alignment was not possible.
As CSS adds further capabilities,
the ability to align boxes in various dimensions becomes more critical.
This module attempts to create a cohesive and common box alignment model to share among all of CSS.
Note: The alignment of text and inline-level content is defined in [[CSS-TEXT-3]] and [[CSS-INLINE-3]].
Note: This specification is not intended to change any of the behavior
defined in <a href="https://www.w3.org/TR/CSS2/">CSS2.1</a>
when the properties defined here are set to their initial values.
If implementors or anyone else notices a discrepancy,
please report this to the CSSWG as an error.
<em>This section (above) is not normative.</em>
<h3 id="placement">
Module Interactions</h3>
This module adds some new alignment capabilities
to the block layout model described in [[!CSS2]] <a href="https://www.w3.org/TR/CSS2/visuren.html">chapters 9</a>
and <a href="https://www.w3.org/TR/CSS2/visudet.html">10</a>,
<a href="#justify-block">redefines how overconstrained block-level box margins are resolved</a>,
and defines the interaction of these new alignment properties
with the alignment of table cell content using 'vertical-align',
as defined in [[!CSS2]] <a href="https://www.w3.org/TR/CSS2/tables.html#height-layout">chapter 17</a>.
The interaction of these properties with
Grid Layout [[!CSS-GRID-1]]
and Flexible Box Layout [[!CSS-FLEXBOX-1]]
is defined in their respective modules.
The property definitions here supersede those in [[!CSS-FLEXBOX-1]]
(which have a smaller, earlier subset of permissible values).
No properties in this module apply to the <code>::first-line</code>
or <code>::first-letter</code> pseudo-elements.
<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.
<h3 id="partial">
Partial Implementations</h3>
Since it is expected that support for the features in this module
will be deployed in stages corresponding to the various layout models affected,
it is hereby clarified that
the <a href="https://www.w3.org/TR/CSS/#partial">rules for partial implementations</a>
that require treating as invalid any unsupported feature
apply to any alignment keyword
which is not supported across all layout modules to which it applies
for layout models in which the implementation supports the property in general.
For example,
if an implementation supports 'align-self' in [[CSS-GRID-1]] and [[CSS-FLEXBOX-1]],
then it must treat ''align-content/start'' as invalid
unless it is supported in both grid and flex containers.
However if that same implementation does not support 'align-self' for block-level elements at all,
then a lack of implementation of ''align-self: start''
does not trigger this requirement to treat it as invalid.
<h2 id="overview">
Overview of Alignment Properties</h2>
The <dfn export>box alignment properties</dfn> in CSS are a set of 6 properties
that control alignment of boxes within other boxes.
They can be described along two axises:
<ul>
<li>which dimension they apply to ([=main axis|main=]/[=inline axis|inline=] vs. [=cross axis|cross=]/[=block axis|block=]), and
<li>whether they control the position of the box within its parent, or the box's content within itself.
</ul>
Note: This specification uses the terms “justify” and “align” to distinguish
between alignment in the main/inline and cross/block dimensions, respectively.
The choice is somewhat arbitrary, but having the two terms allows for
a consistent naming scheme that works across all of CSS's layout models
(including [[css-flexbox-1#box-model]])
The following table summarizes the <a>box alignment properties</a>
and the display types they can apply to.
<table class=data>
<colgroup span=1></colgroup>
<colgroup span=2></colgroup>
<colgroup span=1></colgroup>
<thead>
<tr>
<th>Common
<th>Axis
<th>Aligns
<th>Applies to
<tbody>
<tr>
<th>'justify-content'
<td>main/inline
<td rowspan=2>
<img src="images/content-example.svg" width=106 height=106 alt="">
content within element
<small>(effectively adjusts padding)</small>
<td rowspan=2>[=block containers=], <a>flex containers</a>, and <a>grid containers</a>
<tr>
<th>'align-content'
<td>cross/block
<tbody>
<tr>
<th>'justify-self'
<td>inline
<td rowspan=2>
<img src="images/self-example.svg" width=106 height=106 alt="">
element within parent
<small>(effectively adjusts margins)</small>
<td>block-level boxes, absolutely-positioned boxes, and <a>grid items</a>
<tr>
<th>'align-self'
<td>cross/block
<td>absolutely-positioned boxes, <a>flex items</a>, and <a>grid items</a>
<tbody>
<tr>
<th>'justify-items'
<td>inline
<td rowspan=2>
<img src="images/items-example.svg" width=106 height=106 alt="">
items inside box
<small>(controls child items’ ''align/justify-self: auto'')</small>
<td>[=block containers=] and <a>grid containers</a>
<tr>
<th>'align-items'
<td>cross/block
<td><a>flex containers</a> and <a>grid containers</a>
</table>
Note: The '*-items' properties don't affect the element itself.
When set on a container,
they specify the interpretation of any ''*-self: auto'' used on children of the container element.
<h2 id='terms'>
Alignment Terminology</h2>
Since this module defines alignment properties for all layout modes in CSS,
some abstract terminology is introduced:
<dl>
<dt><dfn export>alignment subject</dfn>
<dd>
The <a>alignment subject</a> is the thing or things being aligned by the property.
For 'justify-self' and 'align-self',
the <a>alignment subject</a> is the margin box of the box the property is set on,
and assumes the <a>writing mode</a> of that box.
For 'justify-content' and 'align-content',
the <a>alignment subject</a> is defined by the layout mode
and refers to some aspect of its contents;
it also assumes the <a>writing mode</a> of the box the property is set on.
<dt><dfn export>alignment container</dfn>
<dd>
The <a>alignment container</a> is the rectangle that the <a>alignment subject</a> is aligned within.
This is defined by the layout mode,
but is usually the <a>alignment subject</a>’s containing block,
and assumes the [=writing mode=] of the box establishing the containing block.
<dt><dfn export>fallback alignment</dfn>
<dd>
Some alignments can only be fulfilled in certain situations
or are limited in how much space they can consume;
for example, ''space-between'' can only operate when there is more than one <a>alignment subject</a>,
and baseline alignment, once fulfilled, might not be enough to absorb all the excess space.
In these cases a fallback alignment takes effect
(as defined below)
to fully consume the excess space.
</dl>
<h2 id='alignment-values'>
Alignment Keywords</h2>
All of the alignment properties use a common set of keyword values,
which are defined in this section.
Keywords fall into three categories:
<dl>
<dt><a href="#positional-values">positional alignment</a>
<dd>These keywords define alignment as an absolute position within the <a>alignment container</a>.
<dt><a href="#baseline-values">baseline alignment</a>
<dd>These keywords define alignment as a relationship
among the baselines of multiple [=alignment subjects=] within an <a>alignment context</a>.
<dt><a href="#distribution-values">distributed alignment</a>
<dd>These keywords define alignment as a distribution of space among <a>alignment subjects</a>.
</dl>
<h3 id='positional-values'>
Positional Alignment: the ''center'', ''start'', ''end'', ''self-start'', ''self-end'', ''flex-start'', ''flex-end'', ''left'', and ''right'' keywords</h3>
The <dfn>positional alignment</dfn> keywords specify a position for an <a>alignment subject</a>
with respect to its <a>alignment container</a>.
Values have the following meanings:
<dl dfn-type="value">
<dt><dfn for="<self-position>, <content-position>, justify-self, align-self, justify-content, align-content">center</dfn> <small>([[#self-alignment|self]], [[#content-distribution|content]])</small>
<dd>Centers the <a>alignment subject</a> within its <a>alignment container</a>.
<dt><dfn for="<self-position>, <content-position>, justify-self, align-self, justify-content, align-content">start</dfn> <small>([[#self-alignment|self]], [[#content-distribution|content]])</small>
<dd>Aligns the <a>alignment subject</a> to be flush with the <a>alignment container</a>’s start edge in the appropriate axis.
<dt><dfn for="<self-position>, <content-position>, justify-self, align-self, justify-content, align-content">end</dfn> <small>([[#self-alignment|self]], [[#content-distribution|content]])</small>
<dd>Aligns the <a>alignment subject</a> to be flush with the <a>alignment container</a>’s end edge in the appropriate axis.
<dt><dfn for="<self-position>, justify-self, align-self">self-start</dfn> <small>([[#self-alignment|self]])</small>
<dd>Aligns the <a>alignment subject</a> to be flush with the edge of the <a>alignment container</a>
corresponding to the <a>alignment subject</a>’s start side in the appropriate axis.
<dt><dfn for="<self-position>, justify-self, align-self">self-end</dfn> <small>([[#self-alignment|self]])</small>
<dd>Aligns the <a>alignment subject</a> to be flush with the edge of the <a>alignment container</a>
corresponding to the <a>alignment subject</a>’s end side in the appropriate axis.
<dt><dfn for="<self-position>, <content-position>, justify-self, align-self, justify-content, align-content">flex-start</dfn> <small>([[#self-alignment|self]], [[#content-distribution|content]])</small>
<dd><strong>Only used in flex layout.</strong> [[!CSS-FLEXBOX-1]]
Aligns the <a>alignment subject</a> to be flush with the edge of the <a>alignment container</a>
corresponding to the <a>flex container</a>’s main-start or cross-start side, as appropriate.
When used outside of a <a>flex formatting context</a>, this value behaves as ''start''.
That is, on boxes that are not <a>flex items</a>
(or pretending to be <a>flex items</a>,
such as when determining the [=static position=] of an absolutely-positioned box
that is a child of a <a>flex container</a>),
this value behaves as ''start'' when used in the <a>self-alignment properties</a>,
and on boxes that are not <a>flex containers</a>,
this value behaves as ''start'' when used in the <a>content-distribution properties</a>.
<dt><dfn for="<self-position>, <content-position>, justify-self, align-self, justify-content, align-content">flex-end</dfn> <small>([[#self-alignment|self]], [[#content-distribution|content]])</small>
<dd><strong>Only used in flex layout.</strong>
Aligns the <a>alignment subject</a> to be flush with the edge of the <a>alignment container</a>
corresponding to the <a>flex container</a>’s main-end or cross-end side, as appropriate.
When used outside of a <a>flex formatting context</a>, this value behaves as ''end''.
That is, on boxes that are not <a>flex items</a>
(or pretending to be <a>flex items</a>,
such as when determining the [=static position=] of an absolutely-positioned box
that is a child of a <a>flex container</a>),
this value behaves as ''end'' when used in the <a>self-alignment properties</a>,
and on boxes that are not <a>flex containers</a>,
this value behaves as ''end'' when used in the <a>content-distribution properties</a>.
<dt><dfn for="justify-content, justify-self, justify-items">left</dfn> <small>(only 'justify-*')</small>
<dd>Aligns the <a>alignment subject</a> to be flush with
the <a>alignment container</a>’s <a href="https://www.w3.org/TR/css3-writing-modes/#line-left">line-left</a>
or <a>physical left</a> edge,
whichever is in the appropriate axis.
If the property's axis is not parallel with either left↔right axis,
this value behaves as ''start''.
<span class=note>Currently, the only case where the property's axis
is not parallel with either left↔right axis
is in a column flexbox.</span>
<dt><dfn for="justify-content, justify-self, justify-items">right</dfn> <small>(only 'justify-*')</small>
<dd>Aligns the <a>alignment subject</a> to be flush with
the <a>alignment container</a>’s <a href="https://www.w3.org/TR/css3-writing-modes/#line-right">line-right</a>
or <a>physical right</a> edge,
whichever is in the appropriate axis.
If the property's axis is not parallel with either left↔right axis,
this value behaves as ''start''.
<span class=note>Currently, the only case where the property's axis
is not parallel with either left↔right axis
is in a column flexbox.</span>
</dl>
Two grammar terms are used to denote certain subsets of these values:
<dl>
<dt><<self-position>>
<dd>
This set is used by 'justify-self' and 'align-self'
to align the box within its <a>alignment container</a>,
and also by 'justify-items' and 'align-items'
(to specify default values for 'justify-self' and 'align-self').
<pre class='prod'>
<dfn><self-position></dfn> = center | start | end | self-start | self-end |
flex-start | flex-end
</pre>
<dt><<content-position>>
<dd>
This set is used by 'justify-content' and 'align-content'
to align the box's contents within itself.
<pre class='prod'>
<dfn><content-position></dfn> = center | start | end | flex-start | flex-end
</pre>
</dl>
Note: ''left'' and ''right'' are excluded from <<self-position>> and <<content-position>>,
despite being valid [=positional alignment=] values for 'justify-content'/'justify-self'/'justify-items',
because they are not allowed in the 'align-*' properties.
They are instead explicitly included in the 'justify-*' properties’ grammars.
<aside class=example>
The ''<self-position>/start'' and ''<self-position>/end'' keywords
are <a>flow-relative</a>:
they use the <a>writing mode</a> to determine which side to align to.
<figure>
<img src="images/start-inline-tb.svg"
width="199" height="125"
style="background: white; padding: 8px;"
title="inline-axis 'start' alignment in various writing systems"
alt="Inline-axis 'start' alignment:
Horizontal Latin and Chinese are left-aligned,
while Arabic and Hebrew are right-aligned.">
<img src="images/end-inline-tb.svg"
width="199" height="125"
style="background: white; padding: 8px;"
title="inline-axis 'end' alignment in various writing systems"
alt="Inline-axis 'end' alignment:
Horizontal Latin and Chinese are right-aligned,
while Arabic and Hebrew are left-aligned.">
<figcaption>
''<self-position>/start'' vs ''<self-position>/end'' in the <a>inline axis</a>
(<a href="#flexbox-exception">typically<sup>†</sup></a> 'justify-*')
</figcaption>
</figure>
The ''justify-self/left'' and ''justify-self/right'' keywords
are absolute (not <a>flow-relative</a>).
<figure>
<img src="images/left-inline-tb.svg"
width="175" height="125"
style="background: white; padding: 8px;"
title="'left' alignment in various writing systems"
alt="Inline-axis 'left' alignment:
Horizontal text is left-aligned, regardless of writing system.">
<img src="images/right-inline-tb.svg"
width="176" height="125"
style="background: white; padding: 8px;"
title="'right' alignment in various writing systems"
alt="Inline-axis 'right' alignment:
Horizontal text is right-aligned, regardless of writing system.">
<figcaption>
''justify-self/left'' vs ''justify-self/right''
</figcaption>
</figure>
The ''<self-position>/start'' and ''<self-position>/end'' keywords
have meaning in both the <a lt="inline axis">inline</a> and <a lt="block axis">block</a> axes:
''<self-position>/start'' always orients to the start of the text
(top left for left-to-right/top-to-bottom languages like English)
while ''<self-position>/end'' always orients to the end of the text.
<figure>
<img src="images/start-block-tb.svg"
width="183" height="125"
style="background: white; padding: 8px; padding-bottom: calc(8px + 23px);"
title="block-axis 'start' alignment in various writing systems"
alt="Block-axis 'start' alignment:
Horizontal text is top-aligned in the vertical axis.">
<img src="images/end-block-tb.svg"
width="183" height="125"
style="background: white; padding: 8px; padding-top: calc(8px + 23px);"
title="block-axis 'end' alignment in various writing systems"
alt="Block-axis 'bottom' alignment:
Horizontal text is bottom-aligned in the vertical axis.">
<figcaption>
''<self-position>/start'' vs ''<self-position>/end'' in the <a>block axis</a>
(<a href="#flexbox-exception">typically<sup>†</sup></a> 'align-*')
</figcaption>
</figure>
The ''<self-position>/start'' and ''<self-position>/end'' keywords
use the <a>writing mode</a> of the <a>alignment container</a>,
to help keep things consistent.
But if alignment using the <a>alignment subject</a>’s <a>writing mode</a> is needed,
the ''<self-position>/self-start'' and ''<self-position>/self-end'' keywords can be used.
<figure>
<img src="images/self-v-context-start-tb.svg"
width="204" height="193"
style="background: white; padding: 8px;"
title="inline-axis 'start' alignment with LTR context"
alt="Inline-axis 'start' alignment in an LTR container:
Alignment uses the context’s start direction, so
the (RTL) Arabic and Hebrew items
are left-aligned alongside the (LTR) Latin and Chinese.">
<img src="images/self-v-context-self-start-tb.svg"
width="229" height="193"
style="background: white; padding: 8px;"
title="inline-axis 'self-start' alignment with LTR context"
alt="Inline-axis 'self-start' alignment in an LTR container:
Horizontal Latin and Chinese items are right-aligned,
while Arabic and Hebrew items are left-aligned.">
<figcaption>
''<self-position>/start'' vs ''<self-position>/self-start'' on the individual items
</figcaption>
</figure>
</aside>
<aside class=example>
The behavior of the alignment keywords is analogous in <a>vertical writing modes</a>:
''<self-position>/start'' and ''<self-position>/end''
are relative to the start/end of the text in the relevant axis.
The ''justify-self/left'' and ''justify-self/right'' keywords
are interpreted as <a>line-left</a> and <a>line-right</a>,
relative to the “left” and “right” sides of LTR/RTL text.
<figure>
<img src="images/start-inline-rl.svg"
width="125" height="200"
style="background: white; padding: 8px;"
title="inline-axis 'start' alignment in various writing systems"
alt="Inline-axis 'start' alignment in vertical-rl writing:
Vertical Latin and Chinese are top-aligned,
while Arabic and Hebrew are bottom-aligned.">
<img src="images/end-inline-rl.svg"
width="125" height="200"
style="background: white; padding: 8px;"
title="inline-axis 'end' alignment in various writing systems"
alt="Inline-axis 'end' alignment in vertical-rl writing:
Vertical Latin and Chinese are top-aligned,
while Arabic and Hebrew are bottom-aligned.">
<figcaption>
''<self-position>/start'' vs ''<self-position>/end'' in the <a>inline axis</a>
(<a href="#flexbox-exception">typically<sup>†</sup></a> 'justify-*')
</figcaption>
</figure>
<figure>
<img src="images/left-inline-rl.svg"
width="126" height="174"
style="background: white; padding: 8px; padding-bottom: calc(8px + 23px);"
title="'left' alignment in various writing systems"
alt="Inline-axis 'left' alignment in vertical-rl writing:
Vertical text is top-aligned, regardless of writing system.">
<img src="images/right-inline-rl.svg"
width="125" height="180"
style="background: white; padding: 8px; padding-top: calc(5px + 23px); padding-bottom: 5px;"
title="'right' alignment in various writing systems"
alt="Inline-axis 'right' alignment in vertical-rl writing:
Vertical text is bottom-aligned, regardless of writing system.">
<figcaption>
''justify-self/left'' vs ''justify-self/right''
</figcaption>
</figure>
<figure>
<img src="images/start-block-rl.svg"
width="123" height="183"
style="background: white; padding: 8px;"
title="block-axis 'start' alignment in various writing systems"
alt="Block-axis 'start' alignment in vertical-rl writing:
Vertical text is top-aligned in the vertical axis.">
<img src="images/end-block-rl.svg"
width="125" height="183"
style="background: white; padding: 8px;"
title="block-axis 'end' alignment in various writing systems"
alt="Block-axis 'bottom' alignment in vertical-rl writing:
Vertical text is bottom-aligned in the vertical axis.">
<figcaption>
''<self-position>/start'' vs ''<self-position>/end'' in the <a>block axis</a>
(<a href="#flexbox-exception">typically<sup>†</sup></a> 'align-*')
</figcaption>
</figure>
<figure>
<img src="images/self-v-context-start-rl.svg"
width="162" height="210"
style="background: white; padding: 8px; padding-bottom: calc(8px + 30px);"
title="inline-axis 'start' alignment with LTR context"
alt="Inline-axis 'start' alignment in a vertical-rl LTR container:
Alignment uses the context’s start direction, so
the (RTL) Arabic and Hebrew items
are top-aligned alongside the (LTR) Latin and Chinese.">
<img src="images/self-v-context-self-start-rl.svg"
width="162" height="240"
style="background: white; padding: 8px;"
title="inline-axis 'self-start' alignment with LTR context"
alt="Inline-axis 'self-start' alignment in a vertical-rl LTR container:
Horizontal Latin and Chinese items are top-aligned,
while Arabic and Hebrew items are bottom-aligned.">
<figcaption>
''<self-position>/start'' vs ''<self-position>/self-start'' on the individual items
</figcaption>
</figure>
</aside>
<div class=note id=flexbox-exception>
For most layout models (block, table, grid, etc),
the 'justify-*' properties always align things in the <a>inline axis</a>,
while the 'align-*' properties always align things in the <a>block axis</a>.
Flexbox, on the other hand, has 'justify-*' align things in the <a>main axis</a>
and 'align-*' align things in the <a>cross axis</a>.
This depends on the value of 'flex-direction':
when 'flex-direction' is ''flex-direction/row'' or ''flex-direction/row-reverse'',
it matches the other layout modes
(<a>inline axis</a> with 'justify-*', <a>block axis</a> with 'align-*');
when 'flex-direction' is ''flex-direction/column'' or ''flex-direction/column-reverse'',
it has the opposite correspondence.
</div>
<p class='issue'>
Make it easier to understand the dual-axis nature of "start" and "end" wrt orthogonal flows.
<h3 id='baseline-values'>
Baseline Alignment: the ''baseline'' keyword and ''first''/''last'' modifiers</h3>
See [[css-writing-modes-3#intro-baselines]].
<dfn export>Baseline alignment</dfn> is a form of positional alignment
that aligns multiple <a>alignment subjects</a>
within a <a>shared alignment context</a>
(such as cells within a row)
by matching up their <a>alignment baselines</a>.
If the position of the <a>alignment subjects</a> within a <a>baseline-sharing group</a>
is not fully constrained by <a>baseline alignment</a>
(i.e., they could be shifted within their respective <a>alignment containers</a>
while maintaining baseline-alignment),
they are [=fallback alignment|fallback-aligned=] insofar as possible while preserving their <a>baseline alignment</a>.
The baseline alignment keywords are represented with the <<baseline-position>> grammar term:
<pre class='prod'>
<dfn><baseline-position></dfn> = [ first | last ]? && baseline
</pre>
The ''first'' and ''last'' values give a box a <dfn export>baseline alignment preference</dfn>:
either “first” or “last”, respectively,
defaulting to “first”.
Values have the following meanings:
<dl dfn-type=value dfn-for="justify-self, justify-items, align-content, align-self, align-items, <baseline-position>">
<dt><dfn>baseline</dfn>
<dd>
Computes to ''first baseline'', defined below.
<dt><dfn lt="first baseline | first">first baseline</dfn>
<dd>
Specifies participation in <dfn dfn for export>first-baseline alignment</dfn>:
aligns the <a>alignment baseline</a> of the box's <a>first baseline set</a>
with the corresponding baseline
of its [=baseline-sharing group=].
See [[#align-by-baseline]] for more details.
The <a>fallback alignment</a> for ''first baseline'' is
''safe self-start'' (for [=self-alignment=])
or ''safe start'' (for [=content-distribution=]).
<dt><dfn lt="last baseline | last">last baseline</dfn>
<dd>
Specifies participation in <dfn dfn for export>last-baseline alignment</dfn>:
aligns the <a>alignment baseline</a> of the box's <a>last baseline set</a>
with the corresponding baseline
of its [=baseline-sharing group=].̣
See [[#align-by-baseline]] for more details.
The <a>fallback alignment</a> for ''last baseline'' is
''safe self-end'' (for [=self-alignment=])
or ''safe end'' (for [=content-distribution=]).
</dl>
When specified for 'align-content',
these values trigger <a>baseline content-alignment</a>,
shifting the content of the box within its content box,
and may also affect the sizing of the box itself.
See [[#baseline-align-content]].
When specified for 'align-self'/'justify-self',
these values trigger <a>baseline self-alignment</a>,
shifting the entire box within its container,
which may affect the sizing of its container.
See [[#baseline-align-self]].
When [=baseline self-alignment=] is specified on a box,
[=content distribution=] is performed first,
then the resulting box and its contents
are [=baseline self-alignment|self-aligned=]
However, if the box also has [=baseline content-alignment=] in the same axis
or if its [=content-distribution property=] in the same axis is ''align-content/normal'',
its [=used value|used=] [=content-distribution property=] in that axis
is ''align-content/start'' or ''safe end''
for a [=baseline alignment preference=] of its [=baseline self-alignment=]
of “first” or “last”, respectively.
<p class='issue'>Add example images here.
If a box does not belong to a <a>shared alignment context</a>,
then the <a>fallback alignment</a> is used.
For example, ''align-content: baseline'' on a block box
falls back to ''align-content/start'' alignment.
The [=fallback alignment=] is also used to align the [=baseline-sharing group=]
within its [=alignment container=].
Note: Because they are equivalent, and ''baseline'' is shorter,
the CSSOM serializes ''first baseline'' as ''baseline''.
See [[cssom-1#serializing-css-values]].
Note: For the somewhat-related 'vertical-align' property,
due to inconsistent design decisions in CSS2.1,
''baseline'' is not equivalent to ''first baseline''
as an inline-level box’s <a>baseline alignment preference</a> depends on 'display'.
(E.g., ''inline-block'' uses its last baseline by default,
while ''inline-table'' uses its first baseline by default.)
<h3 id='distribution-values'>
Distributed Alignment: the ''<content-distribution>/stretch'', ''space-between'', ''space-around'', and ''space-evenly'' keywords</h3>
The <dfn export>distributed alignment</dfn> values are used by 'justify-content' and 'align-content'
to disperse a container’s extra space among its <a>alignment subjects</a>.
<figure>
<img src="images/distribute.svg" alt="space-between | space-around | space-evenly | stretch" width="504" height="218">
<figcaption>The <a>distributed alignment</a> values</figcaption>
</figure>
When space cannot be distributed in this way,
these values behave as their <a>fallback alignment</a>.
Each distribution value has an associated default <a>fallback alignment</a>.
(A future level of this module may allow the <a>fallback alignment</a> to be specified explicitly.)
<dl dfn-type="value" dfn-for="align-content, justify-content, <content-distribution>">
<dt><dfn>space-between</dfn>
<dd>
The <a>alignment subjects</a> are evenly distributed in the <a>alignment container</a>.
The first <a>alignment subject</a> is placed flush with the start edge of the <a>alignment container</a>,
the last <a>alignment subject</a> is placed flush with the end edge of the <a>alignment container</a>,
and the remaining <a>alignment subjects</a> are distributed so that the spacing between any two adjacent <a>alignment subjects</a> is the same.
<figure>
<img src="images/space-between.svg"
width="504" height="56"
alt="For example, given three items, all excess space is split in two and distributed: one half between the first two and one half between the last two items.">
</figure>
The default [=fallback alignment=] for this value is ''safe flex-start''.
<span class='note'>(For layout modes other than flex layout, ''flex-start'' is identical to ''start''.)</span>
<dt><dfn>space-around</dfn>
<dd>
The <a>alignment subjects</a> are evenly distributed in the <a>alignment container</a>,
with a half-size space on either end.
The <a>alignment subjects</a> are distributed so that the spacing between any two adjacent <a>alignment subjects</a> is the same,
and the spacing before the first and after the last <a>alignment subject</a> is half the size of the other spacing.
<figure>
<img src="images/space-around.svg"
width="504" height="56"
alt="For example, given three items, all excess space is split into sixths and distributed: one sixth at the start, one at the end, and two sixths (one third) each between the first two and between the last two items.">
</figure>
The default [=fallback alignment=] for this value is ''safe center''.
<dt><dfn>space-evenly</dfn>
<dd>
The <a>alignment subjects</a> are evenly distributed in the <a>alignment container</a>,
with a full-size space on either end.
The <a>alignment subjects</a> are distributed so that the spacing between any two adjacent <a>alignment subjects</a>,
before the first <a>alignment subject</a>,
and after the last <a>alignment subject</a>
is the same.
<figure>
<img src="images/space-evenly.svg"
width="504" height="56"
alt="For example, given three items, all excess space is split into fourths and distributed: to the start, to the end, to between the first two, and to between the last two items.">
</figure>
The default [=fallback alignment=] for this value is ''safe center''.
<dt><dfn>stretch</dfn>
<dd>
If the combined size of the <a>alignment subjects</a> is less than the size of the <a>alignment container</a>,
any <css>auto</css>-sized <a>alignment subjects</a> have their size increased equally (not proportionally),
while still respecting the constraints imposed by 'max-height'/'max-width'
(or equivalent functionality),
so that the combined size exactly fills the <a>alignment container</a>.
<figure>
<img src="images/space-stretch.svg"
width="504" height="56"
alt="For example, given three items, all excess space is split into thirds and distributed: one third to each item.">
</figure>
The default [=fallback alignment=] for this value is ''flex-start''.
<span class='note'>(For layout modes other than flex layout, ''flex-start'' is identical to ''start''.)</span>
Note: This `align-content/stretch` definition applies to the [=content-distribution properties=];
the [=self-alignment properties=] 'justify-self'/'align-self' have their own ''justify-self/stretch'' value,
which can grow <em>or shrink</em> the [=alignment subject=]
to ensure it exactly fits the [=alignment container=].
</dl>
These values are represented with the <<content-distribution>> grammar term:
<pre class='prod'>
<dfn><content-distribution></dfn> = space-between | space-around | space-evenly | stretch
</pre>
<h3 id='overflow-values'>
Overflow Alignment: the ''safe'' and ''unsafe'' keywords and scroll safety limits</h3>
When the <a>alignment subject</a> is larger than the <a>alignment container</a>,
it will overflow.
Some alignment modes, if honored in this situation,
may cause data loss:
for example, if the contents of a sidebar are centered,
when they overflow they may send part of their boxes past the viewport's start edge,
which can't be scrolled to.
<div class='example'>
The figure below illustrates the difference in “safe” versus “unsafe” centering,
using a column flexbox as an example:
<figure>
<style>
.cross-auto-figure > div {
margin: 0 auto;
width: 70px;
background: #888;
padding: 0 .5em;
border-radius: 1em;
border: 1px solid transparent;
}
.cross-auto-figure > div > div {
border-spacing: 0;
display: table;
background: #ddd;
color: black;
text-align: center;
margin: .5em auto;
padding: .5em;
border-radius: .5em;
}
</style>
<div style="display:table; margin: 0 auto 1em;">
<div style="display:table-cell; padding-right: 70px;" class='cross-auto-figure'>
<div>
<div>About</div>
<div style="white-space: nowrap;">Authoritarianism</div>
<div>Blog</div>
</div>
</div>
<div style="display:table-cell; padding-left: 70px;" class='cross-auto-figure'>
<div>
<div>About</div>
<div style="white-space: nowrap; margin-left: -31px;">Authoritarianism</div>
<div>Blog</div>
</div>
</div>
</div>
<figcaption>
An example of "safe" (on the left)
vs "unsafe" (on the right)
centering,
when the centered item is larger than its container.
</figcaption>
</figure>
The items in the figure on the left are centered unless they overflow,
in which case all the overflow goes off the end edge,
while those in the figure on the right are are all strictly centered,
even if the one that is too long to fit overflows on both sides.
If the container was placed
against the left edge of the page,
the “safe” behavior would be more desirable,
as the long item would be fully readable,
rather than clipped by the left edge of the screen.
In other circumstances,
the “unsafe” centering behavior might be better,
as it correctly centers all the items.
</div>
To control this situation,
an <dfn export>overflow alignment</dfn> mode can be explicitly specified.
“Unsafe” alignment honors the specified alignment mode in overflow situations, even if it causes data loss,
while “safe” alignment changes the alignment mode in overflow situations in an attempt to avoid data loss.
The default behavior is to contain the alignment subject within the scrollable area,
though at the time of writing this safety feature is not yet implemented.
<pre class='prod'><dfn><overflow-position></dfn> = unsafe | safe</pre>
<dl dfn-type="value" dfn-for="<overflow-position>">
<dt><dfn>safe</dfn>
<dd>
If the size of the <a>alignment subject</a> overflows the <a>alignment container</a>,
the <a>alignment subject</a> is instead aligned as if the alignment mode were ''start''.
<dt><dfn>unsafe</dfn>
<dd>
Regardless of the relative sizes of the <a>alignment subject</a> and <a>alignment container</a>,
the given alignment value is honored.
<dt>(no value specified)
<dd>
If the <a>overflow alignment</a> isn't explicitly specified,
the default <a>overflow alignment</a> is a blend of “safe” and “unsafe”.
See [[#auto-safety]] for details.
</dl>
<h4 id=auto-safety>
Automatic Overflow Alignment Safety</h4>
If no [=overflow alignment=] mode is specified for a property,
the default behavior lies somewhere between ''safe'' and ''unsafe'',
and also varies by layout mode.
<h5 id=auto-safety-scroll>
Content Distribution for Scroll Containers</h5>
The default [=overflow alignment=] behavior
for [=content distribution=] on [=scroll containers=] is ''unsafe''.
Non-''justify-content/normal'' values of the [=content-distribution properties=] instead
alter the [=scrollable overflow area=] in order to allow access to the overflowing content.
See [[#overflow-scroll-position]].
<h5 id=auto-safety-position>
Self-Alignment for Absolutely Positioned Boxes</h5>
For [=absolutely positioned=] [=alignment subjects=]
whose relevant [=self-alignment property=] is not ''justify-self/normal'',
the default [=overflow alignment=] behavior is as follows:
<div algorithm="default overflow self-alignment for abspos">
1. Let the |default overflow rect| be the bounding rectangle
of the [=alignment subject's=] [=inset-modified containing block=]
and its [=original containing block=].
2. If the [=alignment subject=] overflows its [=inset-modified containing block=]
(its normal [=alignment container=]),
but does not overflow |default overflow rect|
align as specified (''unsafe'').
3. If the <em>size</em> of the [=alignment subject=]
fits within the |default overflow rect|,
but its specified alignment would cause it to overflow the |default overflow rect|,
it is instead shifted the minimum amount
to stay within the |default overflow rect|
while honoring the alignment as much as possible
(i.e., flush with the edge of the [=original containing block=]
it was trying to overflow over).
4. If the size of the [=alignment subject=]
overflows the |default overflow rect|,
it is instead start-aligned within the |default overflow rect|
(similar to ''safe'').
</div>
(For [=absolutely-positioned=] [=alignment subjects=] that fail the above condition,
see [[#auto-safety-default]].)
<h5 id=auto-safety-default>
All Other Alignment</h5>
For all other elements:
1. If the [=alignment subject=] overflows its [=alignment container=],
align as specified (''unsafe'').
2. If the [=alignment subject=] would overflow
the [=scrollable overflow area=] of its nearest ancestor [=scroll container=],
(thus extending into the “unscrollable” region),
then its overflow in that direction is limited
by biasing any remaining overflow to the opposite side.
Issue: It may not be Web-compatible to implement the “smart” default behavior
(though we hope so, and believe it to be likely),
so UAs should pass any feedback on this point to the WG.
UAs that have not implemented the “smart” default behavior
must behave as ''safe'' for 'align-content' on [=block containers=]
and ''unsafe'' otherwise.
<!-- Big Text: *-content
███▌ ███▌ █ █▌ █████▌ █████▌ █ █▌ █████▌
█ █ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌
█ █ █▌ █▌ █▌ ██▌ █▌ █▌ █▌ ██▌ █▌ █▌
███████ ████▌ █▌ █▌ █▌ █▌▐█ █▌ █▌ ████ █▌▐█ █▌ █▌
█ █ █▌ █▌ █▌ █▌ ██▌ █▌ █▌ █▌ ██▌ █▌
█ █ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌
███▌ ███▌ █▌ ▐▌ █▌ █████▌ █▌ ▐▌ █▌
-->
<h2 id='content-distribution'>
Content Distribution: Aligning a Box’s Contents Within Itself</h2>
<dfn export id="content-distribute" lt="content distribution | content-distribution">Content distribution</dfn> controls alignment of the box's content within its content box.
It is specified by the <dfn export>content-distribution properties</dfn> 'align-content' and 'justify-content'
(and their 'place-content' shorthand).
<div class="figure">
<img alt="Diagram showing that the alignment of the content within the element is affected." src="images/content-example.svg" width=212 height=212>
</div>
<h3 id='align-justify-content'>
The 'justify-content' and 'align-content' Properties</h3>
<pre class="propdef">
Name: align-content
Value: normal | <<baseline-position>> | <<content-distribution>> | <<overflow-position>>? <<content-position>>
Initial: normal
Applies to: block containers, multicol containers, flex containers, and grid containers
Inherited: no
Percentages: n/a
Computed value: specified keyword(s)
Animation type: discrete
</pre>
<pre class="propdef">
Name: justify-content
Value: normal | <<content-distribution>> | <<overflow-position>>? [ <<content-position>> | left | right ]
Initial: normal
Applies to: multicol containers, flex containers, and grid containers
Inherited: no
Percentages: n/a
Computed value: specified keyword(s)
Animation type: discrete
</pre>
Aligns the contents of the box as a whole (as the <a>alignment subject</a>)
within the box itself (as the <a>alignment container</a>):
along the inline/row/main axis of the box (for 'justify-content')
or the block/column/cross axis of the box (for 'align-content').