-
Notifications
You must be signed in to change notification settings - Fork 702
/
Copy pathOverview.bs
1492 lines (1253 loc) · 64.2 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 Sizing Module Level 3
Shortname: css-sizing
Level: 3
Status: ED
Work Status: Refining
Group: csswg
ED: https://drafts.csswg.org/css-sizing-3/
TR: https://www.w3.org/TR/css-sizing-3/
Issue Tracking: CSSWG GitHub https://github.com/w3c/csswg-drafts/issues
Editor: Tab Atkins, Google, http://xanthir.com/contact/, w3cid 42199
Editor: Elika J. Etemad / fantasai, Apple, http://fantasai.inkedblade.net/contact, w3cid 35400
Previous version: https://www.w3.org/TR/2021/WD-css-sizing-3-20210317/
Previous version: https://www.w3.org/TR/2020/WD-css-sizing-3-20201218/
Previous version: https://www.w3.org/TR/2020/WD-css-sizing-3-20201023/
Previous version: https://www.w3.org/TR/2019/WD-css-sizing-3-20190522/
Previous version: https://www.w3.org/TR/2018/WD-css-sizing-3-20180304/
Previous version: https://www.w3.org/TR/2017/WD-css-sizing-3-20170207/
Abstract: This module extends the CSS sizing properties with keywords that represent content-based "intrinsic" sizes and context-based "extrinsic" sizes, allowing CSS to more easily describe boxes that fit their content or fit into a particular layout context.
Ignored Terms: content box, border box, non-replaced
At Risk: Additions to 'column-width'
</pre>
<pre class='link-defaults'>
spec:css-page-3; type:at-rule; text:@page
spec:css-display-3; type:property; text:display
spec:css-display-3; type:dfn; text:box
spec:css2; type: property
text: min-width
text: min-height
text: max-width
text: max-height
spec:css-align-3; type:value; text:stretch; for:align-self
</pre>
<!-- Notes on stuff to do... [copy/pasted from etherpad, probably out-of-date, evaluate later]
Swap definition of preferred size in for max-content.
Define current max-content as super-max-content.
Mark an issue about whether it's a necessary concept;
I'm unsure, but I think it will show up in orthogonal flow sizing.
-->
<h2 id="intro">
Introduction</h2>
<p><em>This section is not normative.</em>
<p>
CSS layout has several different concepts of automatic sizing that are used in various layout calculations.
This section defines some more precise terminology
to help connect the layout behaviors of this spec to the calculations used in other modules,
and some new keywords for the 'width' and 'height' properties
to allow authors to assign elements the dimensions resulting from these size calculations.
Issue: This spec needs illustrations! See <a href="https://github.com/w3c/csswg-drafts/issues/1938">issue</a>.
<h3 id="placement">
Module interactions</h3>
<p>This module extends the 'width', 'height', 'min-width', 'min-height', 'max-width', 'max-height', and 'column-width'
features defined in [[!CSS2]] chapter 10 and in [[!CSS3COL]]
<p>The definition of the 'box-sizing' property in this module supersedes the one in [[CSS-UI-3]].
<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.
<!--
████████ ████████ ████████ ██ ██ ██████
██ ██ ██ ██ ███ ███ ██ ██
██ ██ ██ ██ ████ ████ ██
██ ██████ ████████ ██ ███ ██ ██████
██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██
██ ████████ ██ ██ ██ ██ ██████
-->
<h2 id="terms">
Terminology</h2>
Some key terminology related to coordinate axises and dimensions
is defined in [[css-writing-modes-3#abstract-box]].
<dl export>
<dt><dfn>size</dfn>
<dd>
A one- or two-dimensional measurement:
a <a>block size</a> and/or <a>inline size</a>;
alternatively a [=width=] and/or [=height=].
<figure>
<img style="max-width: 49%;" width=420 height=240 src="images/sizing-ltr-tb.svg"
alt="In left-to-right, top-to-bottom horizontal English,
the horizontal width and inline size are synonymous,
and vertical height and block size are synonymous."><!--
--><img style="max-width: 49%;" width=420 height=240 src="images/sizing-ttb-rl.svg"
alt="In top-to-bottom, right-to-left vertical Japanese,
the horizontal width and block size are synonymous,
and vertical height and inline size are synonymous.">
<figcaption>Whether the <a>width</a> or <a>height</a> corresponds
to an <a>inline size</a> or <a>block size</a> depends on the <a>writing mode</a>.</figcaption>
</figure>
<dt><dfn lt="inner size|inner width|inner height|inner block size|inner inline size">inner size</dfn>
<dd>
The <a href="https://www.w3.org/TR/css2/box.html#box-dimensions">content-box</a> [=size=] of a <a>box</a>.
<figure>
<img src="images/inner-size.svg" width=420 height=270 alt="">
<figcaption>Inner size</figcaption>
</figure>
<dt><dfn lt="outer size|outer width|outer height|outer block size|outer inline size">outer size</dfn>
<dd>
The <a href="https://www.w3.org/TR/css2/box.html#box-dimensions">margin-box</a> [=size=] of a <a>box</a>.
<figure>
<img src="images/outer-size.svg" width=420 height=270 alt="">
<figcaption>Outer size</figcaption>
</figure>
<dt><dfn id="definite" lt="definite|definite size">definite size</dfn>
<dd>
A size that can be determined without performing layout;
that is, a <<length>>,
a measure of text (without consideration of line-wrapping),
a size of the <a>initial containing block</a>,
or a <<percentage>> or other formula
(such the <a href="https://www.w3.org/TR/CSS2/visudet.html#blockwidth">“stretch-fit” sizing of non-replaced blocks</a> [[CSS2]])
that is resolved solely against <a>definite</a> sizes.
Additionally, the size of the <a>containing block</a> of an absolutely positioned element is always <a>definite</a>
with respect to that element.
<dt><dfn id="indefinite" lt="indefinite|indefinite size">indefinite size</dfn>
<dd>
A size that is not <a>definite</a>.
<a>Indefinite</a> <a>available space</a> is essentially infinite.
Note: [=intrinsic sizing=] keywords such as ''width/max-content'' are indefinite,
even if they can be determined without laying out the children
e.g. due to [=size containment=] or lack of children.
<dt><dfn id="available" local-lt="available" lt="available space|available inline space|available block space">available space</dfn>
<dd>
A size representing the space into which a box is laid out,
as determined by
the rules of the formatting context in which it participates.
The space available to a box is usually
either a measurement of its <a>containing block</a> (if that is <a>definite</a>)
or an infinite size (when it is <a>indefinite</a>).
<a>Available space</a> can alternatively be either a
<a>min-content constraint</a> or
a <a>max-content constraint</a>,
which forces boxes laid into it to be laid out under that constraint.
<!--
<p>
The space <a>available</a> to a box is determined by the formatting context in which it participates.
In block, table, and inline formatting contexts [[!CSS2]],
the <a>available space</a> is infinite in the block-axis dimension.
<span class="issue">What, exactly, is the available space in the inline axis??? What about other formatting models?</span>
-->
<dt><dfn>stretch fit</dfn>
<dd>
The <a>stretch fit</a> into a given size
is that size,
minus the box's computed margins (not collapsed, treating ''margin/auto'' as zero),
border, and padding in the given dimension
(such that the outer size is a perfect fit),
and flooring at zero
(so that the inner size is not negative).
<p class='note'>
Note: This is the formula used to calculate the ''width/auto'' widths
of non-replaced blocks in normal flow in <a href="https://www.w3.org/TR/CSS2/visudet.html#blockwidth">CSS2.1§10.3.3</a>.
<dt><dfn lt="fallback|fallback size">fallback size</dfn>
<dd>
Some sizing algorithms do not work well with an infinite size.
In these cases, the <a>fallback size</a> is used instead.
Unless otherwise specified,
this is the size of the <a>initial containing block</a>.
</dl>
<h3 id='auto-box-sizes'>
Auto Box Sizes</h3>
There are four types of automatically-determined sizes in CSS
(sizes resulting from ''width/auto'' sizing rules, depending on context):
<dl export>
<dt><dfn>stretch-fit size</dfn>
<dt><dfn>stretch-fit inline size</dfn>
<dt><dfn>stretch-fit block size</dfn>
<dd>
The <a>size</a> a box would take
if its <a>outer size</a> filled the <a>available space</a>
in the given axis;
in other words, the <a>stretch fit</a> into the <a>available space</a>,
if that is <a>definite</a>.
Undefined if the <a>available space</a> is <a>indefinite</a>.
Note: For the <a>inline axis</a>, this is called the “available width” in <a href="https://www.w3.org/TR/CSS2/visudet.html#float-width">CSS2.1§10.3.5</a>
and computed by the rules in <a href="https://www.w3.org/TR/CSS2/visudet.html#blockwidth">CSS2.1§10.3.3</a>.
Note: Calculations involving this size need to specify a fallback behavior
for when the <a>available space</a> is <a>indefinite</a>
if that happens to be possible.
<dt><dfn lt="max-content | max-content size">max-content size</dfn>
<dd>
A box’s “ideal” <a>size</a> in a given axis when given infinite available space.
Usually this is the smallest <a>size</a> the box could take in that axis
while still fitting around its contents,
i.e. minimizing unfilled space while avoiding overflow.
: <dfn>max-content inline size</dfn>
:: The box's “ideal” <a>size</a> in the <a>inline axis</a>.
Usually the narrowest <a>inline size</a> it could take while fitting around its contents
if <em>none</em> of the soft wrap opportunities within the box were taken.
(See [[#intrinsic]].)
Note: This is called the “preferred width” in <a href="https://www.w3.org/TR/CSS2/visudet.html#float-width">CSS2.1§10.3.5</a>
and the “maximum cell width” in <a href="https://www.w3.org/TR/CSS2/tables.html#auto-table-layout">CSS2.1§17.5.2.2</a>.
: <dfn>max-content block size</dfn>
:: The box's “ideal” <a>size</a> in the <a>block axis</a>.
Usually the <a>block size</a> of the content after layout.
<dt><dfn lt="min-content | min-content size">min-content size</dfn>
<dd>
Nominally, the smallest <a>size</a> a box could take
that doesn't lead to overflow
that could be avoided by choosing a larger <a>size</a>.
Formally, the size of the box when sized under a [=min-content constraint=],
see [[#intrinsic]].
: <dfn>min-content inline size</dfn>
:: The [=min-content size=] in the [=inline axis=].
Typically, the <a>inline size</a> that would fit around its contents
if <em>all</em> soft wrap opportunities within the box were taken.
Note: This is called the “preferred minimum width” in <a href="https://www.w3.org/TR/CSS2/visudet.html#float-width">CSS2.1§10.3.5</a>
and the “minimum content width” in <a href="https://www.w3.org/TR/CSS2/tables.html#auto-table-layout">CSS2.1§17.5.2.2</a>.
: <dfn>min-content block size</dfn>
:: The [=min-content size=] in the [=block axis=].
For [=block containers=], tables, and [=inline boxes=],
this is equivalent to the <a>max-content block size</a>.
<dt><dfn>fit-content size</dfn>
<dt><dfn>fit-content inline size</dfn>
<dt><dfn>fit-content block size</dfn>
<dd>
If the <a>available space</a> in a given axis is <a>definite</a>,
equal to <code>clamp([=min-content size=], [=stretch-fit size=], [=max-content size=])</code>
(i.e. <code>max(<a>min-content size</a>, min(<a>max-content size</a>, <a>stretch-fit size</a>))</code>).
When sizing under a [=min-content constraint=],
equal to the [=min-content size=].
Otherwise, equal to the <a>max-content size</a> in that axis.
Note: This is called the “shrink-to-fit” width in <a href="https://www.w3.org/TR/CSS2/visudet.html#float-width">CSS2.1§10.3.5</a>
and <a href="https://www.w3.org/TR/css3-multicol/#pseudo-algorithm">CSS Multi-column Layout § 3.4</a>.
<dt><dfn>intrinsic size</dfn>
<dd>
A <a>max-content size</a> or <a>min-content size</a>,
i.e. a size arising primarily from the size of the content.
(Some uses of this term may refer also to sizes
derived primarily from one of these two sizes.)
[=Replaced elements=] frequently derive their [=intrinsic size=]
from their [=natural dimensions=].
</dl>
<h3 id='contributions'>
Intrinsic Size Contributions</h3>
<dl export>
<dt><dfn lt="max-content contribution|max-content inline-size contribution|max-content block-size contribution">max-content contribution</dfn>
<dd>
The size that a box contributes to its <a>containing block</a>'s <a>max-content size</a>.
<dt><dfn lt="min-content contribution|min-content inline-size contribution|min-content block-size contribution">min-content contribution</dfn>
<dd>
The size that a box contributes to its <a>containing block</a>'s <a>min-content size</a>.
<dt><dfn>intrinsic size contribution</dfn>
<dd>
A <a>max-content contribution</a>, <a>min-content contribution</a>,
or similarly-calculated content-based size contribution.
</dl>
Intrinsic size contributions are based on the <a>outer size</a> of the box;
for this purpose ''margin/auto'' margins are treated as zero.
<h3 id='constraints' dfn export lt="intrinsic size constraint">
Intrinsic Size Constraints</h3>
<dl export>
<dt><dfn>max-content constraint</dfn>
<dd>
A sizing constraint imposed by the box's <a>containing block</a>
that causes it to produce its <a>max-content contribution</a>.
<dt><dfn>min-content constraint</dfn>
<dd>
A sizing constraint imposed by the box's <a>containing block</a>
that causes it to produce its <a>min-content contribution</a>.
<dt><dfn>preferred aspect ratio</dfn>
<dd>
A width:height ratio inherent to a box,
which biases various sizing algorithms
to produce a size consistent with that aspect ratio
insofar as possible while honoring other sizing inputs.
Unless otherwise specified,
a box’s [=preferred aspect ratio=] is its [=natural aspect ratio=] if it has one
and is applied to its [=content box=].
Most boxes do not have a [=preferred aspect ratio=].
</dl>
<!--
████████ ████████ ███████ ████████ ████████ ████████ ████████ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
████████ ████████ ██ ██ ████████ ██ ██ ██████ ██████ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ███████ ██ ████████ ████████ ██ ██████
-->
<h2 id="specifying-sizes" oldids='size-keywords'>
Specifying Box Sizes</h2>
<h3 id="sizing-properties">
Sizing Properties</h3>
This section defines the <dfn export lt="sizing property">sizing properties</dfn>
'width', 'height', 'min-width', 'min-height', 'max-width', and 'max-height'.
Their potential values are defined in the next section,
[[#sizing-values]].
Note: Additional <a>flow-relative</a> aliases to these properties are defined in [[CSS-LOGICAL-1]].
ISSUE: We would like to define shorthands for each pair of sizing properties
(e.g. 'width' and 'height')
but there is a naming conflict with the ''@page'' 'size' descriptor [[CSS-PAGE-3]],
so this has been deferred to Level 4.
Suggestions on how to resolve this problem are welcome,
see <a href="https://github.com/w3c/csswg-drafts/issues/820">discussion</a>.
<h4 id="preferred-size-properties" dfn export lt="preferred size property">
Preferred Size Properties: the 'width' and 'height' properties</h4>
<pre class=propdef>
Name: width, height
Value: auto | <<length-percentage [0,∞]>> | min-content | max-content | <nobr>fit-content(<<length-percentage [0,∞]>>)</nobr> | <<width/calc-size()>>
Initial: auto
Applies to: all elements except <a>non-replaced</a> <a>inlines</a>
Inherited: no
Logical property group: size
Percentages: relative to width/height of <a>containing block</a>
Computed Value: as specified, with <<length-percentage>> values computed
Animation type: by computed value type, recursing into ''width/fit-content()''
</pre>
The 'width' and 'height' ([=physical=]) properties specify
the <dfn export lt="preferred size">preferred</dfn>
<dfn export lt="width | preferred width">width</dfn>
and <dfn export lt="height | preferred height">height</dfn> of the box, respectively.
<h4 id="min-size-properties" dfn export lt="min size property">
Minimum Size Properties: the 'min-width' and 'min-height' properties</h4>
<pre class=propdef>
Name: min-width, min-height
Value: auto | <<length-percentage [0,∞]>> | min-content | max-content | <nobr>fit-content(<<length-percentage [0,∞]>>)</nobr> | <<min-width/calc-size()>>
Initial: auto
Applies to: all elements that accept 'width' or 'height'
Inherited: no
Logical property group: min-size
Percentages: relative to width/height of <a>containing block</a>
Computed Value: as specified, with <<length-percentage>> values computed
Animation Type: by computed value, recursing into ''min-width/fit-content()''
</pre>
The 'min-width' and 'min-height' properties specify
the <dfn export lt="min width | minimum width | min size | minimum size">minimum width</dfn> (or “min width”)
and <dfn export lt="min height | minimum height">minimum height</dfn> (or “min height”)
of the box, respectively.
Note: The initial value of ''min-width/auto'' is new;
in [[CSS2]] the initial value was zero.
<h4 id="max-size-properties" dfn export lt="max size property">
Maximum Size Properties: the 'max-width' and 'max-height' properties</h4>
<pre class=propdef>
Name: max-width, max-height
Value: none | <<length-percentage [0,∞]>> | min-content | max-content | <nobr>fit-content(<<length-percentage [0,∞]>>)</nobr> | <<max-width/calc-size()>>
Initial: none
Applies to: all elements that accept 'width' or 'height'
Inherited: no
Logical property group: max-size
Percentages: relative to width/height of <a>containing block</a>
Computed Value: as specified, with <<length-percentage>> values computed
Animation Type: by computed value, recursing into ''max-width/fit-content()''
</pre>
The 'max-width' and 'max-height' properties specify
the <dfn export lt="max width | maximum width | max size | maximum size">maximum width</dfn> (or “max width”)
and <dfn export lt="max height | maximum height">maximum height</dfn> (or “max height”)
of the box, respectively.
<h3 id="sizing-values" oldids='width-height-keywords'>
Sizing Values: the <<length-percentage [0,∞]>>, ''width/auto'' | ''max-width/none'', ''width/min-content'', ''width/max-content'', and ''width/fit-content()'' values</h3>
<dl dfn-type=value dfn-for="width, min-width, max-width, height, min-height, max-height">
<dt><dfn><<length-percentage [0,∞]>></dfn>
<dd>
Specifies the size of the box using <<length>> and/or <<percentage>>.
The 'box-sizing' property indicates whether the <a>content box</a> or <a>border box</a> is measured.
Percentages are resolved against the width/height, as appropriate,
of the box's <a>containing block</a>.
If, in a particular axis,
the <a>containing block’s</a> size depends on the box’s size,
see the relevant layout module
for special rules on how to resolve percentages.
Negative values are invalid.
<dt><dfn for="width, height, min-width, min-height">auto</dfn>
<dd>
For 'width'/'height', specifies an <dfn export dfn for>automatic size</dfn>
(<dfn export dfn for>automatic [=block size=]</dfn>/<dfn export dfn for>automatic [=inline size=]</dfn>).
See the relevant layout module for how to calculate this.
For 'min-width'/'min-height',
specifies an <dfn export dfn for>automatic minimum size</dfn>.
Unless otherwise defined by the relevant layout module,
however,
it resolves to a used value of ''0''.
For backwards-compatibility,
the <a>resolved value</a> of this keyword is zero
for boxes of all [[!CSS2]] <a>display types</a>:
block and inline boxes,
inline blocks,
and all the table layout boxes.
It also resolves to zero
when no box is generated.
<dt><dfn for="max-width, max-height">none</dfn>
<dd>
No limit on the size of the box.
<!--
<dt><dfn>stretch</dfn>
<dd>
If 'align-self' or 'justify-self' (as appropriate to the relevant axis)
is defined to apply,
size the box as if ''align-self/stretch'' were specified for that property.
(If the box does not exactly fill its <a>alignment container</a>,
the <a>box alignment properties</a> will dictate how the size differential is handled.)
Otherwise,
this value behaves as the initial value.
NOTE: For the <a>inline size</a> of a <a>block-level box</a>,
this is exactly the formula used to calculate ''width/auto'' widths
for non-replaced blocks in normal flow, see <a href="https://www.w3.org/TR/CSS2/visudet.html#blockwidth">CSS2.1§10.3.3</a>.
It allows re-using this formula for boxes that are otherwise shrink-wrapped,
like tables.
-->
<dt><dfn>min-content</dfn>
<dd>
Use the <a>min-content size</a> in the relevant axis;
for a box’s [=block size=],
unless otherwise specified,
this is equivalent to its [=automatic size=].
<dt><dfn>max-content</dfn>
<dd>
Use the <a>max-content size</a> in the relevant axis;
for a box’s [=block size=],
unless otherwise specified,
this is equivalent to its [=automatic size=].
<!--
<dt><dfn>fit-content</dfn>
<dd>
Use the <a>fit-content size</a> in the relevant axis,
i.e.
<code>min(''width/max-content'', max(''width/min-content'', ''width/stretch''))</code>.
-->
<dt><dfn function lt="fit-content()">fit-content(<<length-percentage [0,∞]>>)</dfn>
<dd>
Use the fit-content formula
with the <a>available space</a> replaced by the specified argument,
i.e.
<code>min(''width/max-content'', max(''width/min-content'', <<length-percentage>>))</code>,
where the <<length-percentage>> argument is resolved
exactly as for <<length-percentage>> values standing alone.
Negative <<length-percentage>> values are invalid.
<dt><dfn function lt="calc-size()">calc-size()</dfn>
<dd>
See <</calc-size()>>.
Note: The ''max-width/none'' keyword is
not usable within ''max-width/calc-size()''.
</dl>
In all cases,
the used value is floored to preserve a non-negative <a>inner size</a>.
Note: The ''width/min-content'', ''width/max-content'', and ''width/fit-content()'' values
are new in Level 3.
Note: The 'flex-basis' property hereby also gains these new keywords,
as its values are defined by reference to <'width'>.
Note: This section previously defined ''width/stretch'' and ''width/fit-content''
as keywords representing the <a>stretch-fit size</a> and <a>fit-content size</a>,
respectively.
These keywords have been deferred to Level 4
(along with an additional ''width/contain'' keyword that
behaves similarly to ''width/stretch''
but preserves the [=preferred aspect ratio=], if any)
to better work out the implications in situations with
<a>indefinite</a> <a>available space</a>.
<h4 id="behave-auto">
“Behaving as ''width/auto''”</h4>
<!-- THIS NEED SOME THINKING THROUGH, WE DID WEIRD THINGS WITH FLEXBOX/GRID
Note: Percentages resolved against the intrinsic sizes
(''width/max-content'', ''width/min-content'', ''width/fit-content'')
will behave as ''width/auto''.
-->
<!-- <a href="https://www.w3.org/TR/CSS2/visudet.html#the-height-property">as defined by CSS 2</a>. [[!CSS2]] -->
<!-- Restore the above when 2.1 is updated and published with the new "behaves as" text we resolved on. -->
To have a common term for both when
'width'/'height' computes to ''width/auto''
and when it is defined to behave as if ''width/auto'' were specified
(as in the case of <a href="https://www.w3.org/TR/CSS2/visudet.html#the-height-property">block percentage heights</a>
resolving against an <a>indefinite</a> size,
see <a href="https://www.w3.org/TR/CSS2/visudet.html#the-height-property">CSS2§10.5</a>),
the property is said to <dfn export lt="behave as auto|behaves as auto|behaving as auto">behave as auto</dfn>
in both of these cases.
Note: Legacy spec prose defining layout behavior, particularly in [[CSS2]],
might explicitly refer to 'width'/'height' having a computed value of ''width/auto'' as a condition;
some of these cases should be interpreted as meaning <a>behaves as auto</a>,
and reported to the CSSWG for updating.
ISSUE: Replace this section with references to the new term <a>automatic size</a>.
<h4 id='the-contain-floats-value'>
Containing or Excluding Floats</h4>
<em>This section is non-normative.</em>
Although <a>block box</a> boundaries are typically pervious to floats,
sometimes an author needs them to contain their own (descendant) floats
or to exclude floats from outside.
For Block layout,
specifying ''display: flow-root''
will make the box a <a>formatting context</a> root,
which has this behavior.
Note: Boxes participating in Flex, Grid, or Table layout will automatically have this behavior.
<!--
████████ ███████ ██ ██ ██████ ████ ████████ ████ ██ ██ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██
████████ ██ ██ ███ ███████ ██████ ██ ██ ██ ██ ██ ██ ██ ████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██ ██
████████ ███████ ██ ██ ██████ ████ ████████ ████ ██ ██ ██████
-->
<h3 id="box-sizing" caniuse="css3-boxsizing">
Box Edges for Sizing: the 'box-sizing' property</h3>
<pre class="propdef">
Name: box-sizing
Value: content-box | border-box
Initial: content-box
Applies to: all elements that accept 'width' or 'height'
Inherited: no
Percentages: N/A
Computed value: specified keyword
Animation type: discrete
</pre>
The 'box-sizing' property defines whether
fixed sizes (such as <<length>>s and <<percentage>>s)
are assigned to the <a>content box</a> or to the <a>border box</a>.
It affects the interpretation of all <a>sizing properties</a>,
including 'flex-basis'.
Values have the following meanings:
<dl dfn-type=value dfn-for=box-sizing>
<dt><dfn>content-box</dfn>
<dd>
Sizes specified on <a>sizing properties</a>
as <<length-percentage>>
represent the box’s <a>inner sizes</a>,
excluding the margins/border/padding:
they are applied to the <a>content box</a>.
The padding and border of the box
are laid out and drawn <em>outside</em> the specified 'width' and 'height'.
Note: This is the behavior of width and height as specified by CSS2.1,
and is thus the default.
<dt><dfn>border-box</dfn>
<dd>
Sizes specified on <a>sizing properties</a>
as <<length-percentage>>
represent the box’s visually-apparent sizes,
including the borders/padding (but not margin):
they are applied to the <a>border box</a>.
The padding and border of the box
are laid out and drawn <em>inside</em> the specified 'width' and 'height',
with the <a>content box</a> sized to fill the remaining space,
floored at zero.
The content width and height are calculated
by subtracting the border and padding widths of the respective sides
from the specified <<length-percentage>>.
As the content width and height
[[#sizing-values|cannot be negative]],
this computation is floored at zero.
Used values, as exposed for instance through {{getComputedStyle()}},
also refer to the border box.
</dl>
Values affected by 'box-sizing' include
both raw <<length-percentage>> values
and those used in functional notations such as ''width/fit-content()''.
In contrast,
non-quantitative values such as ''width/auto'' and ''width/min-content''
are not influenced by the 'box-sizing' property
(unless otherwise specified).
<div class=example>
For example, the following properties set
the content-box size of the box to ''100px'',
with the border-box size calculating to ''120px'':
<pre class=lang-css>
.box {
box-sizing: content-box; /* default */
width: 100px;
padding-left: 10px;
border-left: 10px solid;
}
</pre>
On the other hand, by changing to ''border-box'',
the border-box is set to ''100px'',
with the content-box size calculating to ''80px'':
<pre class=lang-css>
.box {
box-sizing: border-box;
width: 100px;
padding-left: 10px;
border-left: 10px solid;
}
</pre>
The <a>inner size</a> can't be less than zero,
so if the 'padding' + 'border' is greater than the specified border-box size,
the box will end up larger than specified.
In this case, the content-box size will floor at ''0px''
so the border-box size ends up at ''120px'',
even though ''width: 100px'' is specified for the border box:
<pre class=lang-css>
.box {
box-sizing: border-box;
width: 100px;
padding-left: 60px;
border-left: 60px solid;
/* padding + border = 120px */
}
</pre>
</div>
<div class="example">
This example uses box-sizing to evenly horizontally split
two divs with fixed size borders inside a div container,
which would otherwise require additional markup.
sample CSS:
<pre><code class="lang-css">
div.container {
width:38em;
border:1em solid black;
}
div.split {
box-sizing:border-box;
width:50%;
border:1em silver ridge;
float:left;
}
</code></pre>
sample HTML fragment:
<pre><code class="lang-markup">
<div class="container">
<div class="split">This div occupies the left half.</div>
<div class="split">This div occupies the right half.</div>
</div>
</code></pre>
demonstration of sample CSS and HTML:
<div style="max-width:38em; border:1em solid black"><div style="box-sizing:border-box; width:50%; border:1em silver ridge; float:left">This div should occupy the left half.</div><div style="box-sizing:border-box; width:50%; border:1em silver ridge; float:left">This div should occupy the right half.</div>The two divs above should appear side by side, each (including borders) 50% of the content width of their container. If instead they are stacked one on top of the other then your browser does not support 'box-sizing'.</div>
</div>
Note: Certain HTML elements,
such as <{button}>,
default to ''border-box'' behavior.
See HTML for details on which elements have this behavior.
In legacy CSS specifications,
the terms <a>width</a>, <a>height</a>,
<a lt="min width">minimum (min) width</a>,
<a lt="min height">minimum (min) height</a>,
<a lt="max width">maximum (max) width</a>, and
<a lt="max height">maximum (max) height</a>
generally refer to the <a lt="inner size">inner</a> size
(<a lt="content box">content-box</a> size)
of a <a>box</a>
unless otherwise indicated.
Refer to [[CSS-UI-3#box-sizing]] for an explicit disambiguation of these terms
for the <a href="https://www.w3.org/TR/CSS21/visudet.html">Visual formatting model details</a> section of [[CSS2]].
<div class=advisement>To avoid ambiguities,
specification authors should avoid ambiguous uses of terms such as width or height without further qualification,
and should explicitly refer and link to
the <a lt="inner size">inner</a> size,
the <a lt="outer size">outer</a> size,
the size of the <a href="https://www.w3.org/TR/css2/box.html#box-dimensions">border-box</a>,
the <a>computed value</a> of the <a>sizing properties</a>,
etc,
as appropriate for each case.
</div>
<!--
██████ ███████ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ███ ███ ███ ██
██ ██ ██ ██ ██ ██ ████ ████ ████ ██
██ ██ ██ ██ ██ ██ ██ ███ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███
██████ ███████ ████████ ███████ ██ ██ ██ ██
-->
<h3 id='column-sizing'>
New Column Sizing Values: the ''column-width/min-content'', ''column-width/max-content'', and ''column-width/fit-content()'' values</h3>
<pre class="propdef partial">
Name: column-width
New values: min-content | max-content | fit-content(<<length-percentage>>)
Computed value: as specified, with <<length-percentage>> values computed
Animation type: by computed value type
</pre>
<p>When used as values for 'column-width',
the new keywords specify the optimal column width:
<dl dfn-type=value dfn-for="column-width">
<!--
<dt><dfn>stretch</dfn>
<dd>Specifies the optimal column width as the <a>stretch-fit inline size</a>
of the multi-column container.
-->
<dt><dfn>min-content</dfn>
<dd>Specifies the optimal column width as the <a>min-content inline size</a>
of the multi-column container's contents.
<dt><dfn>max-content</dfn>
<dd>Specifies the optimal column width as the <a>max-content inline size</a>
of the multi-column container's contents.
<!--
<dt><dfn>fit-content</dfn>
<dd>Specifies the optimal column width as
<code>min(<a>max-content inline size</a>, max(<a>min-content inline size</a>, <a>stretch-fit inline size</a>))</code>.
-->
<dt><dfn>fit-content(<<length-percentage>>)</dfn>
<dd>
Specifies the optimal column width as
<code>min(<a>max-content size</a>, max(<a>min-content size</a>, <<length-percentage>>))</code>
</dl>
Note: The column width never varies by column.
When the column width is informed by the multi-column container's contents
(as in the keywords above),
all of its contents are taken under consideration
and the calculated width is shared by all the columns.
<!--
████████ ██ ██ ████████ ████████ ████ ██ ██ ██████ ████ ██████
██ ██ ██ ██ ██ ██ ██ ███ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██
██████ ███ ██ ████████ ██ ██ ██ ██ ██████ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ███ ██ ██ ██ ██ ██
████████ ██ ██ ██ ██ ██ ████ ██ ██ ██████ ████ ██████
-->
<h2 id='extrinsic'>
Extrinsic Size Determination</h2>
<p>
<dfn export>Extrinsic sizing</dfn> determines sizes based on the context of an element,
without regard for its contents.
<h3 id="percentage-sizing">
Percentage Sizing</h3>
Percentages specify sizing of a box with respect to the box’s <a>containing block</a>.
<div class="example">
For example, in the following markup:
<xmp class='lang-html'>
<article style="height: 60em">
<figure style="height: 50%;">
<img style="height: 50%;">
</figure>
</article>
</xmp>
* the <code><figure></code> would be ''30em'' tall
= 50% of the [=definite=] ''60em'' height of the <code><article></code>
* the <code><img></code> would be ''15em'' tall
= 50% of the <code><figure></code>’s height
(which is itself [=definite=] because it's a percentage resolved against a [=definite=] length)
</div>
See [[#cyclic-percentage-contribution]]
for details on how to resolve percentages
when the size of the [=containing block=] depends
on the size of its content.
<!--
████ ██ ██ ████████ ████████ ████ ██ ██ ██████ ████ ██████
██ ███ ██ ██ ██ ██ ██ ███ ██ ██ ██ ██ ██ ██
██ ████ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██
██ ██ ██ ██ ██ ████████ ██ ██ ██ ██ ██████ ██ ██
██ ██ ████ ██ ██ ██ ██ ██ ████ ██ ██ ██
██ ██ ███ ██ ██ ██ ██ ██ ███ ██ ██ ██ ██ ██
████ ██ ██ ██ ██ ██ ████ ██ ██ ██████ ████ ██████
-->
<h2 id='intrinsic'>
Intrinsic Size Determination</h2>
<p>
<dfn export>Intrinsic sizing</dfn> determines sizes based on the contents of an element,
without regard for its context.
<h3 id='intrinsic-sizes'>
Intrinsic Sizes</h3>
The <a>min-content size</a> of a box in each axis
is the size it would have if it was
a float given an ''width/auto'' [=preferred size=] in that axis
(and no <a lt="min size">minimum</a> or <a>maximum size</a> in that axis)
and if its containing block was <em>zero</em>-sized in that axis.
(In other words, the minimum size it has when sized as “shrink-to-fit”.)
The <a>max-content size</a> of a box in each axis
is the size it would have if it was
a float given an ''width/auto'' [=preferred size=] in that axis
(and no <a lt="min size">minimum</a> or <a>maximum size</a> in that axis),
and if its containing block was <em>infinitely</em>-sized in that axis.
(In other words, the maximum size it has when sized as “shrink-to-fit”.)
The [=min-content size=] and [=max-content size=] are collectively referred to
as the [=intrinsic sizes=].
Note: When the box has a [=preferred aspect ratio=],
size constraints in the opposite dimension will transfer through
and can affect the ''width/auto'' size in the considered one.
See <a href="https://www.w3.org/TR/CSS2/visudet.html">CSS2§10</a>.
This specification does not define how to determine the sizes of floats.
Please refer to [[CSS2]].
However, the [=intrinsic sizes=] of [=replaced elements=] without [=natural sizes=]
are defined below:
<dl>
<dt>If it has a [=preferred aspect ratio=]:
<dd>
For the [=min-content size=], use zero.
For the [=max-content size=]:
* If the <a>available space</a> is <a>definite</a>
in the <a>inline axis</a>,
use the <a>stretch fit</a> into that size for the inline size
and calculate the block size using the aspect ratio.
<!-- Technically undefined in CSS2, but this was recommended. -->
* Otherwise
if the box has a <<length>> as its [=computed value=]
for 'min-width' or 'min-height',
use that size and calculate the other dimension using the aspect ratio;
if both dimensions have a <<length>> minimum,
choose the one that results in the larger overall size.
Note: This case was previous calculated from a 300x150 default size,
rather than the box's min size.
This is believed to be a better behavior,
and likely to be Web-compatible,
but please send feedback to the CSSWG if there are any problems.
<!-- Brand new behavior not defined in CSS2 -->
* Otherwise
use an [=inline size=] matching
the corresponding dimension of the [=initial containing block=]
and calculate the other dimension using the aspect ratio.
<!-- More brand-new behavior, to prevent max-content size from going infinite. -->
<dt>If it has no [=preferred aspect ratio=]:
<dd>
For both the [=min-content size=] and [=max-content size=]:
* If the box has a <<length>> as its [=computed value|computed=]
[=minimum size=] ('min-width'/'min-height') in that dimension,
use that size.
Note: This author-controllable behavior is made possible
by the new ''min-width/auto'' value for the [=min size properties=].
This is believed to be a better behavior,
but it is not yet clear if it is Web-compatible,
so please send feedback to the CSSWG if there are any problems.
* Otherwise,
use ''300px'' for the width
and/or ''150px'' for the height
as needed.
<!-- Required by CSS2 (due to Web-compat). -->
</dl>
Since a block-level or inline-level replaced element
whose 'height' or 'width' <a>behaves as auto</a>
is effectively defined to use its <a>max-content size</a>
(<a href="https://www.w3.org/TR/CSS2/visudet.html#inline-replaced-width">CSS2§10.3.2</a>),
this specification applies the rules above
to the undefined case of a replaced element
whose 'height' and 'width' both <a>behave as auto</a>.
Note: This specification does not define how to determine
the size of a float.
Please refer to [[CSS2]],
the relevant CSS specification for that display type,
and/or existing implementations
for further details.
A future specification will define this in detail,
replacing the CSS2 “definition”,
such as it is.
<hr>
Although the ''width/auto'' size of text input controls
such as HTML’s <code><input type=text></code> and <code><textarea></code> elements
is typically a fixed size,
the contents of such elements can be used to determine a content-based [=intrinsic size=],