1. Introduction
This section is not normative.
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.
1.1. Module interactions
This module extends the width, height, min-width, min-height, max-width, max-height, and column-width features defined in [CSS21] chapter 10 and in [CSS3COL]
1.2. Values
This specification follows the CSS property definition conventions from [CSS21]. Value types not defined in this specification are defined in CSS Level 2 Revision 1 [CSS21]. Other CSS modules may expand the definitions of these value types: for example [CSS3COLOR], when combined with this module, expands the definition of the <color> value type as used in this specification.
In addition to the property-specific values listed in their definitions, all properties defined in this specification also accept the inherit keyword as their property value. For readability it has not been repeated explicitly.
2. Terminology
- size#sizeReferenced in:2.1. Auto Box Sizes (2) (3) (4) (5) (6) (7)
- A one- or two-dimensional measurement: a block size and/or inline size; alternatively a width and/or height.
- inner size
- The content-box size of a box.
- outer size#outer-sizeReferenced in:2.2. Intrinsic Size Contributions
- The margin-box size of a box.
- definite size#definiteReferenced in:2. Terminology (2) (3) (4)5.1. Fill-available Sizing
- A size that can be determined without measuring content; that is, a <length>, a size of the initial containing block, or a <percentage> or other formula (such the “fill-available” sizing of non-replaced blocks [CSS21]) that is resolved solely against definite sizes. Additionally, the size of the containing block of an absolutely positioned element is always definite with respect to that element.
- indefinite size#indefiniteReferenced in:2. Terminology (2)5.2. Percentage Sizing
- A size that is not definite. An indefinite available size is essentially infinite.
- available space#availableReferenced in:2. Terminology (2)2.1. Auto Box Sizes (2)
- The space into which a box is laid out. Unless otherwise specified, this is either a measurement of its containing block (if that is definite) or an infinite size (when it is indefinite). Available space can alternatively be either a min-content constraint or a max-content constraint.
- fill-available fit#fill-available-fitReferenced in:2. Terminology
-
The fill-available fit into a given size
is that size,
minus the element’s computed margins (not collapsed, treating auto as zero),
border, and padding in the given dimension.
Note: This is the formula used to calculate the auto widths of non-replaced blocks in normal flow in CSS2.1§10.3.3.
- fallback size#fallbackReferenced in:2. Terminology
- Some sizing algorithms do not work well with an infinite size. In these cases, the fallback size is used instead. Unless otherwise specified, this is the size of the initial containing block.
2.1. Auto Box Sizes
-
fill-available size#fill-available-sizeReferenced in:2.1. Auto Box Sizes
fill-available inline size#fill-available-inline-sizeReferenced in:3.1. New Keywords for width and height3.3. Column Sizing Keywords (2)5.1. Fill-available Sizing (2)
fill-available block size#fill-available-block-sizeReferenced in:3.1. New Keywords for width and height5.1. Fill-available Sizing
-
Roughly, the size a box would take if it filled its available space in the given axis. (See §5 Extrinsic Size Determination.)
Note: For the inline axis, this is called the “available width” in CSS2.1§10.3.5 and computed by the rules in CSS2.1§10.3.3.
-
max-content size#max-contentReferenced in:2.1. Auto Box Sizes (2)2.2. Intrinsic Size Contributions4.1. Intrinsic Sizes of Replaced Elements4.2. Intrinsic Sizes of Other Boxes
-
A box’s “ideal” size in a given axis when given infinite available space. Usually this is the smallest size the box could take in that axis while still fitting around its contents, i.e. minimizing unfilled space while avoiding overflow.
-
max-content inline size#max-content-inline-sizeReferenced in:3.1. New Keywords for width and height3.3. Column Sizing Keywords (2)5.1. Fill-available Sizing
-
The box’s “ideal” size in the inline axis. Usually the narrowest inline size it could take while fitting around its contents if none of the soft wrap opportunities within the box were taken. (See §4 Intrinsic Size Determination.)
Note: This is called the “preferred width” in CSS2.1§10.3.5 and the “maximum cell width” in CSS2.1§17.5.2.2.
-
max-content block size#max-content-block-sizeReferenced in:2.1. Auto Box Sizes3.1. New Keywords for width and height
-
The box’s “ideal” size in the block axis. Usually the block size of the content after layout.
-
-
min-content size#min-contentReferenced in:2.1. Auto Box Sizes2.2. Intrinsic Size Contributions4.1. Intrinsic Sizes of Replaced Elements4.2. Intrinsic Sizes of Other Boxes
-
The smallest size a box could take that doesn’t lead to overflow that could be avoided by choosing a larger size. (See §4 Intrinsic Size Determination.)
-
min-content inline size#min-content-inline-sizeReferenced in:3.1. New Keywords for width and height3.3. Column Sizing Keywords (2)5.1. Fill-available Sizing
-
The narrowest inline size a box could take that doesn’t lead to inline-dimension overflow that could be avoided by choosing a larger inline size. Roughly, the inline size that would fit around its contents if all soft wrap opportunities within the box were taken.
Note: This is called the “preferred minimum width” in CSS2.1§10.3.5 and the “minimum content width” in CSS2.1§17.5.2.2.
-
min-content block size#min-content-block-sizeReferenced in:3.1. New Keywords for width and height
-
Equivalent to the max-content block size.
Or should this be the minimum between allowed break points? It might make sense in multi-col contexts to have min-content and max-content block-sizes be different, even if they are the same elsewhere.
-
-
fit-content inline size#fit-content-inline-sizeReferenced in:3.1. New Keywords for width and height
fit-content block size#fit-content-block-sizeReferenced in:3.1. New Keywords for width and height
-
If the available space in a given axis is finite, equal to
min(max-content size, max(min-content size, fill-available size))
. Otherwise, equal to the max-content size in that axis.Note: This is called the “shrink-to-fit” width in CSS2.1§10.3.5 and CSS Multi-column Layout § 3.4.
2.2. Intrinsic Size Contributions
- max-content contribution#max-content-contributionReferenced in:2.3. Intrinsic Size Constraints4.3. Intrinsic Contributions
- The size that a box contributes to its containing block’s max-content size.
- min-content contribution#min-content-contributionReferenced in:2.3. Intrinsic Size Constraints4.3. Intrinsic Contributions
- The size that a box contributes to its containing block’s min-content size.
Intrinsic size contributions are based on the outer size of the box; for this purpose auto margins are treated as zero.
2.3. Intrinsic Size Constraints
- max-content constraint#max-content-constraintReferenced in:2. Terminology
- A sizing constraint imposed by the box’s containing block that causes it to produce its max-content contribution.
- min-content constraint#min-content-constraintReferenced in:2. Terminology
- A sizing constraint imposed by the box’s containing block that causes it to produce its min-content contribution.
3. New Sizing Keywords
3.1. New Keywords for width and height
Name: | width, min-width, max-width, height, min-height, max-height |
---|---|
New values: | fill | max-content | min-content | fit-content |
There are four types of automatically-determined sizes in CSS (which are represented in the width and height properties by the keywords defined above):
- fill#valdef-width-fillReferenced in:3.1. New Keywords for width and height (2)
- Use the fill-available inline size or fill-available block size, as appropriate to the writing mode.
- max-content#valdef-width-max-contentReferenced in:3.1. New Keywords for width and height5.2. Percentage Sizing
- Use the max-content inline size or max-content block size, as appropriate to the writing mode.
- min-content#valdef-width-min-contentReferenced in:3.1. New Keywords for width and height5.2. Percentage Sizing
- Use the min-content inline size or min-content block size, as appropriate to the writing mode.
- fit-content#valdef-width-fit-contentReferenced in:3.1. New Keywords for width and height5.2. Percentage Sizing
- Use the fit-content inline size or fit-content block size, as appropriate to the writing mode.
Is fill stable enough or should we defer to L4? Is the name clear enough, or should it be reverted to fill-available (or changed to something else)?
Note: To size an element such that it avoids overlapping sibling floats, make sure it’s a formatting context root. For some layout modes, such as Grid and Flexbox, this is true automatically. For Block layout, this means using display: flow-root;.
Right now all of these except fill mean the same thing for block-sizes. This may or may not be ideal.
If the inline-size is auto, we could have min-content block-size imply a max-content inline-size, and vice versa.
Note that percentages resolved against the intrinsic sizes (max-content, min-content, fit-content) will compute to auto, as defined by CSS 2.1. [CSS21]
3.2. Containing Floats
Note: To ensure that a container sizes itself to contain any descendant floats, make sure it’s a formatting context. For some layout modes, such as Grid and Flexbox, this is true automatically. For Block layout, this means using display: flow-root;.
3.3. Column Sizing Keywords
Name: | column-width |
---|---|
New values: | fill | max-content | min-content | fit-content |
When used as values for column-width, the new keywords specify the optimal column width:
- fill
- Specifies the optimal column width as the fill-available inline size of the multi-column element.
- max-content
- Specifies the optimal column width as the max-content inline size of the multi-column element’s contents.
- min-content
- Specifies the optimal column width as the min-content inline size of the multi-column element’s contents.
- fit-content
- Specifies the optimal column width as
min(max-content inline size, max(min-content inline size, fill-available inline size))
.
4. Intrinsic Size Determination
Intrinsic sizing determines sizes based on the contents of an element, without regard for its context.
4.1. Intrinsic Sizes of Replaced Elements
For replaced elements, the min-content size and max-content size are equivalent and correspond to the appropriate dimension of the concrete object size returned by the default sizing algorithm [CSS3-IMAGES] of the element, calculated with an unconstrained specified size.
4.2. Intrinsic Sizes of Other Boxes
The min-content size of a box is the size it would have as an auto-sized float in a zero-sized containing block. (In other words, the minimum size it has when sized as “shrink-to-fit”.)
The max-content size of a box is the size it would have as an auto-sized float in an infinitely-sized containing block. (In other words, the maximum size it has when sized as “shrink-to-fit”.)
Note: This specification does not define how to determine these sizes. Please refer to [CSS21], the relevant CSS specification for that display type, and/or existing implementations for further details.
4.3. Intrinsic Contributions
A box’s min-content contribution/max-content contribution in each axis is the size of the content box of a hypothetical auto-sized float that contains only that box, if that hypothetical float’s containing block is zero-sized/infinitely-sized.
Note: This specification does not define how to determine these sizes. Please refer to [CSS21], the relevant CSS specification for that display type, and/or existing implementations for further details.
5. Extrinsic Size Determination
Extrinsic sizing determines sizes based on the context of an element, without regard for its contents.
5.1. Fill-available Sizing
The inner fill-available inline size of a box is…
- If the box is the root or is absolutely-positioned, the inline-size of its containing block, else
-
max(min-content inline size|0, min(max-content inline size|infinity, inline size|fill-available inline size))
where the sizes are inner inline-sizes of the element establishing the box’s containing block, and where the first value is used if it is definite and the second value otherwise.
…less the box’s inline-axis margins (after any margin collapsing, and treating auto margins as zero), borders, and padding.
The fill-available block size of a box is defined analogously, but in the other dimension.
This definition might end up skipping further up the ancestor chain than we’d like in some cases. Example. Maybe it should stop at each formatting root, or something similar?
5.2. Percentage Sizing
Percentages specify sizing of a box with respect to the box’s containing block.
Although this may require an additional layout pass to re-resolve percentages in some cases, the auto, min-content, max-content, and fit-content values of min-width and min-height do not prevent the resolution of percentage sizes of the box’s contents. However, in order to prevent cyclic sizing in the general case, percentages do not otherwise resolve against indefinite sizes, and instead are treated as auto.
Note: See definition of percentage width and height in [CSS21].
Changes
Changes since the 10 May 2016 version.
- Removed normative definitions of the various sizes, deferring to CSS2.1’s “undefined” for floats. (We will restore these details in a Level 4 draft.)
Acknowledgments
Special thanks go to Aaron Gustafson, L. David Baron for their contributions to this module.