Proposal for properties to set intrinsic inline sizes

A Collection of Interesting Ideas,

This version:
https://dbaron.github.io/css-intrinsic-isize-props/
Issue Tracking:
GitHub
Inline In Spec
Editor:
L. David Baron (Mozilla)

Abstract

This document proposes additions to [CSS-SIZING-4] to add properties to CSS that let CSS authors override the intrinsic inline size calculations done in CSS.

1. Introduction

Traditional document layout, and many of the formatting primitives in CSS, are based on the model where sizes in the inline dimension (in Latin text, widths) are the input to the layout algorithm and sizes in the block dimension (in Latin text, heights) are the output. For example, when laying out a newspaper article, the width of the column is the input, and the words then fill a certain height, which is the output. In a layout algorithm based on a tree structure like HTML or XML, this means that inline sizes (widths) are computed from the top of the tree down to the leaves, and block sizes (heights) are computed from the leaves back up to the root.

However, there are cases where layout algorithms want to use widths that are derived from the content. For example, table layout should size the table columns so that the ones with more content consume more of the space, or figures floated (with float) to the side of the layout should use the width that the figure requires.

For this purpose, CSS describes two intrinsic inline-sizes (widths). These are the min-content size, which is intended to be the smallest inline-size that an element can become without overflowing, and the max-content size, which is intended to be the largest inline-size that an element can be without wasting extra space that was allocated to it. The rules for calculating these sizes vary between the layout primitives in CSS (roughly corresponding to the values of display). These are calculated while traversing the tree from leaves towards the root: the intrinsic sizes of an element depend on those of its descendants, but not those of its ancestors. These sizes can be computed prior to the layout algorithm, which sometimes depends on them. Thus the overall process of layout could be thought of as an upward pass over the tree to compute intrinsic inline sizes, followed by a downward pass over the tree to compute final inline sizes, and then an upward pass over the tree to compute final block sizes. (This is a simplification, and doesn’t apply to all formatting primitives.)

The rules for calculating intrinsic sizes do not always produce the results that the CSS author wants. Sometimes this is because the rules are approximations; other times this is because the intrinsic sizes are used in specific ways that the author would like to modify, without modifying properties that affect the final layout of the element.

Therefore, I propose adding properties that allow CSS authors to modify the intrinsic sizes directly, without having other effects on layout.

2. Assigning Intrinsic Inline Sizes

Name: min-content-inline-size, max-content-inline-size
Value: auto | [ [ <length> | contents ] && use-inline-size? && use-min-inline-size? && use-max-inline-size? ]
Initial: auto
Applies to: all elements but non-replaced inline elements, table rows, and table row groups, and table column groups
Inherited: no
Percentages: n/a
Media: visual
Computed value: as specified, with lengths made absolute
Canonical order: per grammar
Animation type: length or discrete The animation type needs to be more formal
auto
Equivalent to contents use-inline-size use-min-inline-size use-max-inline-size.
<length>
Use the given length as the min-content inline size or the max-content inline size of the element.
contents
Compute the min-content inline size or the max-content inline size of the element as normal. (This is the normal behavior.)
use-inline-size
When computing the min-content contribution or the max-content contribution of the element, consider the computed value of inline-size. (This is the normal behavior.)
use-min-inline-size
When computing the min-content contribution or the max-content contribution of the element, consider the computed value of min-inline-size. (This is the normal behavior.)
use-max-inline-size
When computing the min-content contribution or the max-content contribution of the element, consider the computed value of max-inline-size. (This is the normal behavior.)

The current proposal uses logical names only (inline-size) without providing physical names (width, height). Providing physical names could be done. However, it would significantly increase the number of new properties, while creating some new properties that would only work some of the time, and require yet another set of properties that have physical and logical equivalents.

The way this proposal allows separately ignoring or honoring inline-size, min-inline-size, and max-inline-size adds a good bit of complexity. Is it useful enough to be worthwhile?

Need to decide whether the <length> value affects the min-content, max-content, and fit-content keywords for inline-size, min-inline-size, max-inline-size, width, etc.

Need to describe the meaning on table cells and columns in a little more detail. Presumably cells are straightforward, and setting on a column overrides the contributions from all of the cells, and the use-inline-size etc. keywords only apply to the inline-size of the element they’re specified on.

Add example of some 100%-width images in a grid track whose size is determined by something else.

3. Security and Privacy Considerations

By changing the math of layout calculations, this document introduces no new security or privacy considerations.

4. Acknowledgements

The author wishes to thank Rachel Andrew, Elika J. Etemad (fantasai), Jen Simmons, and the CSS Working Group for participating in various discussions that led to this proposal.

Conformance

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Examples in this specification are introduced with the words “for example” or are set apart from the normative text with class="example", like this:

This is an example of an informative example.

Informative notes begin with the word “Note” and are set apart from the normative text with class="note", like this:

Note, this is an informative note.

Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[CSS-DISPLAY-3]
Tab Atkins Jr.; Elika Etemad. CSS Display Module Level 3. URL: http://dev.w3.org/csswg/css-display/
[CSS-LOGICAL-PROPS-1]
CSS Logical Properties Module Level 1 URL: https://drafts.csswg.org/css-logical-props-1/
[CSS-SIZING-4]
Tab Atkins Jr.; Elika Etemad. CSS Intrinsic & Extrinsic Sizing Module Level 4. ED. URL: https://drafts.csswg.org/css-sizing-4/
[CSS-VALUES-3]
Tab Atkins Jr.; Elika Etemad. CSS Values and Units Module Level 3. URL: https://drafts.csswg.org/css-values/
[CSS2]
Bert Bos; et al. Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification. 7 June 2011. REC. URL: https://www.w3.org/TR/CSS2
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://tools.ietf.org/html/rfc2119

Property Index

Name Value Initial Applies to Inh. %ages Media Anim­ation type Canonical order Com­puted value
min-content-inline-size auto | [ [ <length> | contents ] && use-inline-size? && use-min-inline-size? && use-max-inline-size? ] auto all elements but non-replaced inline elements, table rows, and table row groups, and table column groups no n/a visual length or discrete The animation type needs to be more formal per grammar as specified, with lengths made absolute
max-content-inline-size auto | [ [ <length> | contents ] && use-inline-size? && use-min-inline-size? && use-max-inline-size? ] auto all elements but non-replaced inline elements, table rows, and table row groups, and table column groups no n/a visual length or discrete The animation type needs to be more formal per grammar as specified, with lengths made absolute

Issues Index

The animation type needs to be more formal
The current proposal uses logical names only (inline-size) without providing physical names (width, height). Providing physical names could be done. However, it would significantly increase the number of new properties, while creating some new properties that would only work some of the time, and require yet another set of properties that have physical and logical equivalents.
The way this proposal allows separately ignoring or honoring inline-size, min-inline-size, and max-inline-size adds a good bit of complexity. Is it useful enough to be worthwhile?
Need to decide whether the <length> value affects the min-content, max-content, and fit-content keywords for inline-size, min-inline-size, max-inline-size, width, etc.
Need to describe the meaning on table cells and columns in a little more detail. Presumably cells are straightforward, and setting on a column overrides the contributions from all of the cells, and the use-inline-size etc. keywords only apply to the inline-size of the element they’re specified on.
Add example of some 100%-width images in a grid track whose size is determined by something else.