CSS Display Module Level 3

Status: ED
ED: http://dev.w3.org/csswg/css-display
Shortname: css-display
Level: 3
Editor: Tab Atkins Jr., Google, http://xanthir.com/contact/
Abstract: This module contains the features of CSS relating to the 'display' property and other box-generation details.

Introduction

This section is not normative. The 'display' property, introduced in CSS 2.1, defines what kind of boxes an element generates (and whether it generates boxes at all), and how it lays out its contents. These concepts are actually rather independent, though they're conflated by the 'display' property. This causes some pain when a property value intended to affect one aspect (such as setting an element to ''display:none'' to suppress box generation) affects another aspect (such as losing the memory of what it was before ''display:none'', so that it can be set back to that value later). This specification subsumes the CSS 2.1 definition of the 'display' property, and redefines it to be a shorthand property for a small family of longhands, each controlling an independent aspect of an element's "display".

Module interactions

This specification transforms the 'display' property into a shorthand property, and defines several longhand properties that it expands into or effects. This module replaces and extends the definition of the 'display' property defined in [[!CSS21]] section 9.2.4. None of the properties in this module apply to the ::first-line or ::first-letter pseudo-elements.

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. In addition to the property-specific values listed in their definitions, all properties defined in this specification also accept the CSS-wide keywords as their property value. For readability it has not been repeated explicitly.

The Display Properties

The 'display' shorthand and its associated family of properties control the layout mode of elements (how the element determines the sizes and positions of itself and its descendants), and what boxes they and their descendants generate.

Setting the layout mode: the 'display-inside' property

Name: display-inside
Value: auto | block | table | flex | grid
Initial: auto
Applies To: all elements
Inherited: no
Percentages: N/A
Computed Value: a keyword
auto
If the element's computed 'display-outside' value is ''inline-level'', the element is an inline element, and lays out its contents using inline layout. [[!CSS21]] If the element's computed 'display-outside' value is ''table-row-group'', ''table-header-group'', ''table-footer-group'', ''table-row'', ''table-column-group'', or ''table-column'', this elements acts as normal for its given 'display-outside' value. Otherwise, this value computes to ''block''.
block
The element lays out its contents using block layout. [[!CSS21]]
table
The element lays out its contents using table layout. [[!CSS21]]
flex
The element lays out its contents using flex layout. [[!CSS3-FLEXBOX]]
grid
The element lays out its contents using grid layout. [[!CSS3-GRID-LAYOUT]]

Interacting with the layout mode: the 'display-outside' property

Name: display-outside
Value: block-level | inline-level | none | table-row-group | table-header-group | table-footer-group | table-row | table-cell | table-column-group | table-column | table-caption
Initial: inline-level
Applies To: all elements
Inherited: no
Percentages: N/A
Computed Value: as specified
''block-level''
The element is block-level, and participates in a block formatting context. Other formatting contexts, such as flex formatting contexts, may also work with block-level elements. [[!CSS21]]
''inline-level''
The element is inline-level, and participates in an inline formatting context. [[!CSS21]]
''none''
The element generates no boxes, and does not participate in any formatting context. Note: This value exists for legacy reasons, and interacts with the separate 'box' property. It is recommended that 'box' be used to suppress an element, so that the element's display type is automatically preserved for when it's no longer suppressed.
''table-row-group'', ''table-header-group'', ''table-footer-group'', ''table-row'', ''table-cell'', ''table-column-group'', ''table-column'', ''table-caption''
The element is an internal table element, and participates in a table layout context. [[!CSS21]]

Do we need special bits about some of the interactions with 'display-inside'? For example, how ''display:inline-level block;'' works? Or does that fall out of what exists, and the definitions of Block Layout in 2.1? (...or a new Block Layout spec, explaining all the 2.1 stuff more sanely?)

Is fantasai's proposal for a run-in model sane enough to include in this spec?

Additional stuff: the 'display-extras' property

Name: display-extras
Value: none | [ list-item ]
Initial: none
Applies To: all elements
Inherited: no
Percentages: N/A
Computed Value: as specified
list-item
The element generates a ::marker pseudo-element and is considered a list item.

This property is probably dumb, and at the very least has a dumb name. Better names? If I define more one-off weird box-generation details like this, should I merge them into a single "extras" property like this, or just have them all be separate properties?

The 'display' shorthand property

Name: display
Value: inline | block | list-item | inline-list-item | inline-block | table | inline-table | table-cell | table-caption | flex | inline-flex | grid | inline-grid | [ <'display-inside'> || <'display-outside'> || <'display-box'> || <'display-extras'> ]
Initial: see individual properties
Applies To: all elements
Inherited: no
Percentages: see individual properties
Computed Value: see individual properties
Animatable: see individual properties

The single-keyword values listed explicitly in the grammar above are handled specially, for legacy reasons. All other single-keyword values, and all other values in general, are handled as normal for shorthands.

The general rule for new layout modes seems to be that they're block-level by default. However, this conflicts with the default value of 'display-outside', which is ''inline-level''. What's the best way to address this? Simplest answer is to just expand this list of special values as we go along. Another possibility is to magic up the expansion in a different way, so that if the value is just a 'display-inside' keyword, 'display-outside' defaults to ''block-level''. If the latter is chosen, we could remove several more of the special expansions below (all the ones that are identical to a 'display-inside' value).

Several of the "special" expansions below are actually just what the shorthand would expand to normally. They're included here for clarity, as they're very familiar from long usage in CSS 2.1, before the 'display' property became a shorthand.

inline
Expands identically to ''inline-level auto''.
block
Expands identically to ''block-level block''.
list-item
Expands identically to ''block-level block list-item''.
inline-list-item
Expands identically to ''inline-level block list-item''.
inline-block
Expands identically to ''inline-level block''.
table
Expands identically to ''block-level table''.
inline-table
Expands identically to ''inline-level table''.
table-caption
Expands identically to ''table-caption block''.
table-cell
Expands identically to ''table-cell block''.
flex
Expands identically to ''block-level flex''.
inline-flex
Expands identically to ''inline-level flex''.
grid
Expands identically to ''block-level grid''.
inline-grid
Expands identically to ''inline-level grid''.

Controlling box generation: the 'box' property

Name: box
Value: normal | none | contents
Initial: normal
Applies To: all elements
Inherited: no
Percentages: N/A
Computed Value: see prose
The 'box' property is not part of the 'display' shorthand, so that 'display' can be safely set without accidentally overriding whether an element is being suppressed or not. The computed value of 'box' is the specified value, unless 'display-outside' has the value ''none'', in which case the computed value of 'box' is ''none'' as well.
normal
The element generates boxes as normal, per its other 'display-*' properties.
none
The element generates no boxes at all.
contents
The element itself does not generate any boxes, but its children and pseudo-elements still generate boxes as normal. For the purposes of box generation and layout, the element must be treated as if it had been replaced with its children and pseudo-elements in the document tree.

Is there a need for a value that suppresses box generation for layout purposes, but still generates them for the purposes of animations/counters/etc.?

''contents'' currently only has an effect on box generation and layout. Other things that care about the document tree are unaffected, like counter scopes. Is this what we want?

Is 'box' a good name? What about 'show'? Other suggestions?

Acknowledgments

We would like to thank the many people who have attempted to separate out the disparate details of box generation over the years, most particularly Bert Bos, whose last attempt with 'display-model' and 'display-role' didn't get anywhere, but primed us for the current spec. We would also like to thank the many JavaScript libraries such as jQuery which have hacked around the "what 'display' should I give it when you call .show()?" problem, making it extremely clear that something needed to be done on our part.