CSS Intrinsic & Extrinsic Sizing Module Level 3

Shortname: css-sizing
Level: 3
Status: ED
ED: http://dev.w3.org/csswg/css-sizing
TR: http://www.w3.org/TR/css3-sizing/
Editor: Tab Atkins, Google, http://xanthir.com/contact/
Editor: fantasai, Mozilla, http://fantasai.inkedblade.net/contact/
!Issue Tracking: W3C Bugzilla
Previous version: http://www.w3.org/TR/2012/WD-css3-sizing-20120927/">http://www.w3.org/TR/2012/WD-css3-sizing-20120927/
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.
Link Defaults: css21 (property) min-width/min-height/max-width/max-height, css21 (dfn) containing block/initial containing block/block container box
Ignored Terms: block-level box

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.

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]]

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.

Terminology

size
A one- or two-dimensional measurement: a measure and/or extent; alternatively a width and/or height.
definite size
A size that can be determined without measuring content; that is, a <length>, a size of the initial containing block, or a <percentage> that is resolved against a definite size. Additionally, the size of the containing block of an absolutely positioned element is always definite with respect to that element.
indefinite size
A size that is not definite. An indefinite available size is essentially infinite.
available size
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). An available size can alternatively be either a min-content constraint or a max-content constraint.
fill-available fit
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
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.
fill-available measure
Roughly, the measure a box would take if it filled its available measure. (See Extrinsic Size Determination.)

Note: 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 measure
Roughly, the narrowest measure a box could take while fitting around its contents if none of the soft wrap opportunities within the box were taken. (See 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.

min-content measure
The narrowest measure a box could take that doesn't lead to inline-dimension overflow that could be avoided by choosing a larger measure. Roughly, the measure that would fit around its contents if all soft wrap opportunities within the box were taken. (See Intrinsic Size Determination.)

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.

fit-content measure
If the available measure is finite, equal to min(preferred measure, max(min-content measure, fill-available measure)). Otherwise, equal to the max-content measure.

Note: This is called the “shrink-to-fit” width in CSS2.1§10.3.5 and CSS Multi-column Layout § 3.4.

preferred measure
A box’s “ideal” measure. Unless otherwise specified, this is the max-content measure.
fill-available extent
Roughly, the extent a box would take if it filled its available extent. (See Intrinsic Size Determination.)
max-content extent
Roughly, the extent of the content after layout.
min-content extent
Equivalent to the max-content extent.

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 extents be different, even if they are the same elsewhere.

fit-content extent
Analogous to the fit-content measure.
preferred extent
Equivalent to the max-content extent.

Same issue as min-content extent.

max-size contribution
The size that a box contributes to its containing block's max-content size.
min-size contribution
The size that a box contributes to its containing block's min-content size.
preferred-size contribution
If the box's layout mode has a defined preferred-size contribution, that. Otherwise, the box's max-size contribution.
max-size constraint
A sizing constraint imposed by the box's containing block that causes it to produce its max-size contribution.
min-size constraint
A sizing constraint imposed by the box's containing block that causes it to produce its min-size contribution.
preferred-size constraint
A sizing constraint imposed by the box's containing block that causes it to produce its preferred-size contribution.

New Sizing Keywords

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
Use the fill-available measure or fill-available extent, as appropriate to the writing mode.
max-content
Use the max-content measure or max-content extent, as appropriate to the writing mode.
min-content
Use the min-content measure or min-content extent, as appropriate to the writing mode.
fit-content
Use the fit-content measure or fit-content extent, as appropriate to the writing mode.
repudiate-floats Less stupid name?
In the inline axis, use the larger of the min-content measure, and the fill-available measure minus the size of any non-descendant floats in the same formatting context. (This is similar to the behavior of a box that establishes a formatting context next to a float.) In the block axis, this is identical to ''width/auto''.

Does this value work? Is it needed?

Right now all of these except ''width/fill'' mean the same thing for extents. This may or may not be ideal.

If the measure is ''width/auto'', we could have min-content extent imply a max-content measure, and vice versa.

Note that percentages resolved against the intrinsic sizes (''width/max-content'', ''width/min-content'', ''width/fit-content'', ''width/repudiate-floats'') will compute to ''width/auto'', as defined by CSS 2.1. [[!CSS21]]

Containing Floats

	Name: min-width, min-height
	New values: contain-floats
	
contain-floats
Equivalent to ''min-width/min-content'' except that when applied to the extent of a block box it forces the inner extent to be large enough to contain the margin boxes of any floats that originate inside the block and that participate in the same block formatting context as the block's immediate contents.

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 measure of the multi-column element.
max-content
Specifies the optimal column width as the max-content measure of the multi-column element's contents.
min-content
Specifies the optimal column width as the min-content measure of the multi-column element's contents.
fit-content
Specifies the optimal column width as min(max-content measure, max(min-content measure, fill-available measure)).

Intrinsic Size Determination

Intrinsic sizing determines sizes based on the contents of an element, without regard for its context.

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.

Intrinsic Sizes of Non-Replaced Inlines

The min-content measure of an inline box is the length of the largest unbreakable sequence of inline content. The min-measure contribution of an inline box is its min-content measure, plus any inline-axis margin, border, and padding adjacent to that sequence.

The max-content measure of an inline box is the length of the largest sequence of inline content on a single line when only forced line breaks are taken. The max-measure contribution of an inline box is its max-content measure, plus any inline-axis margin, border, and padding adjacent to that sequence.

The min-content extent, max-content extent, min-extent contribution, and max-extent contribution of an inline box are the distance from the head edge of the first line box to the foot edge of the last line box on which the inline appears.

Intrinsic Sizes of Non-Replaced Blocks

The min-content measure of a block container box is the largest min-measure contribution of its in-flow or floated children.

The max-content measure of a block container box is the measure of the box after layout, if all children are sized under a max-size constraint.

If the computed measure of a block-level box is ''width/min-content'', ''width/max-content'', or a definite size, its min-measure contribution is that size plus any inline-axis margin, border, and padding. Otherwise, if the computed measure of the block is ''width/fit-content'', ''width/auto'', or ''width/fill'', its min-measure contribution is its min-content measure plus any inline-axis margin, border, and padding.

If the computed measure of a block-level box is ''width/min-content'', ''width/max-content'', or a definite size, its max-measure contribution is that size plus any inline-axis margin, border, and padding. Otherwise, if the computed measure of the block is ''width/fit-content'', ''width/auto'', or ''width/fill'', its max-measure contribution is its max-content measure plus any inline-axis margin, border, and padding.

The min-content extent and max-content extent of a block container box is the content extent as defined (for horizontal writing modes) in CSS2.1§10.6.3 and CSS2.1§17.5.3 for elements with ''height: auto'', and analogously for vertical writing modes.

The min-extent contribution and max-extent contribution of a block-level box is the extent of the block after layout, plus any block-axis margin, border, and padding.

Intrinsic Sizes in Table Layout

???

Intrinsic Sizes in Multi-column Layout

The min-content measure of a multi-column element with a computed 'column-width' not ''auto'' is the smaller of its 'column-width' and the largest min-measure contribution of its contents.

The min-content measure of a multi-column element with a computed 'column-width' of ''auto'' is the largest min-measure contribution of its contents multiplied by its 'column-count' (treating ''auto'' as ''1'').

The max-content measure of a multi-column element with unrestrained column heights and a computed 'column-count' not ''auto'' is its 'column-count' multiplied by the larger of its 'column-width' (treating ''auto'' as 0) and the largest max-measure contribution of its contents.

The max-content measure of a multi-column element with unrestrained column heights and a computed 'column-count' of ''auto'' is its 'column-width' multiplied by the number of columns obtained by taking all allowed column breaks [[CSS3-BREAK]].

The max-content measure of a multi-column element with restrained-height columns (i.e. a specified 'height' or 'max-height', or whichever properties map to the extent of the element) is the measure that would exactly include all of its columns. It may be approximated by:

or by some more accurate method.

This approximation can result in some slack, but avoids overflow in the most common cases, where the balanced height of the columns above spanning elements are approximately equal.

In the common case of no column-spanning elements, this approximation collapses to simply doing a layout, and measuring the resulting columns.

The preferred measure of a multi-column element with non-''auto'' 'column-width' and 'column-count' is the product of the 'column-width' and 'column-count', plus the appropriate amount of column gaps. In all other cases, it is the max-content measure.

Extrinsic Size Determination

Extrinsic sizing determines sizes based on the context of an element, without regard for its contents.

The inner fill-available measure of a box is…

…less the box's inline-axis margins (after any margin collapsing, and treating ''auto'' margins as zero), borders, and padding.

The fill-available extent 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?

Acknowledgments

Special thanks go to Aaron Gustafson, L. David Baron for their contributions to this module.