CSS Display Module Level 3

Editor’s Draft, 8 March 2014

This version:
http://dev.w3.org/csswg/css-display
Editor’s Draft:
http://dev.w3.org/csswg/css-display
Feedback:
www-style@w3.org with subject line “[css-display] … message topic …”(archives)
Test Suite:
None Yet
Editors:
Tab Atkins Jr. (Google)

Abstract

This module contains the features of CSS relating to the display property and other box-generation details. CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, in speech, etc.

Status of this document

This is a public copy of the editors’ draft. It is provided for discussion only and may change at any moment. Its publication here does not imply endorsement of its contents by W3C. Don’t cite this document other than as work in progress.

The (archived) public mailing list www-style@w3.org (see instructions) is preferred for discussion of this specification. When sending e-mail, please put the text “css-display” in the subject, preferably like this: “[css-display] …summary of comment…

This document was produced by the CSS Working Group (part of the Style Activity).

This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

Table of Contents

1 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".

1.1 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.

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.

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.

2 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.

2.1 Setting the layout mode: the display-inside property

Name:display-inside
Value:auto | block | table | flex | grid | ruby
Initial:auto
Applies to:all elements
Inherited:no
Media:all
Computed value:a keyword
Percentages:n/a
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 an layout-specific display role, 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]
ruby
The element lays out its contents using ruby layout. [CSS3RUBY]

2.2 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 | ruby-base | ruby-text | ruby-base-container | ruby-text-container
Initial:inline-level
Applies to:all elements
Inherited:no
Media:all
Computed value:as specified
Percentages:n/a
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 display-box property. It is recommended that display-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] These values are all layout-specific display roles.
ruby-base, ruby-text, ruby-base-container, ruby-text-container
The element is an internal ruby element, and participates in a ruby layout context. [CSS3RUBY] These values are all layout-specific display roles.
run-in
The element is a run-in element. Run-in elements act like inlines or blocks, depending on the surrounding elements. This is described more fully in a later section.

Some values of display-outside are specialized for particular formatting contexts, and don’t have meaning outside of those specific contexts. These values are called layout-specific display roles. Generally, a layout-specific display role will generate wrapper boxes around itself to ensure that it ends up in the correct formatting context, if it’s not placed in an appropriate formatting context; the details of this are specified by each layout mode.

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

2.3 Additional stuff: the display-extras property

Name:display-extras
Value:none | list-item
Initial:none
Applies to:all elements
Inherited:no
Media:all
Computed value:as specified
Percentages:n/a
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?

2.4 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-extras’> ]
Initial:see individual properties
Applies to:see individual properties
Inherited:see individual properties
Media: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.

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.

3 Controlling box generation: the display-box property

Name:display-box
Value:normal | none | contents
Initial:normal
Applies to:all elements
Inherited:no
Media:all
Computed value:see prose
Percentages:n/a

The display-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.

If the computed value of display-outside is none, the computed value of display-box is none. Otherwise, the computed value is the specified value.

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?

4 Run-In Layout

A run-in element is an element with display-outside: run-in. A run-in element acts differently based on whether its siblings are inlines or blocks; if it precedes a block, it merges into the block. This is useful for formatting compact headlines, definitions, and other similar things, where the appropriate DOM structure is to have a headline preceding the following prose, but the desired display is an inline headline laying out with the text.

For example, dictionary definitions are often formatted so that the word is inline with the definition:
<dl class='dict'>
  <dt>dictionary
  <dd>a book that lists the words of a language in alphabetical
      order and gives their meaning, or that gives the equivalent
      words in a different language.
  <dt>glossary
  <dd>an alphabetical list of terms or words found in or relating
      to a specific subject, text, or dialect, with explanations; a
      brief dictionary.
</dl>
<style>
.dict > dt {
  display: run-in;
}
.dict > dt::after {
  display: run-in;
  content: ": "
}
</style>

Which is formatted as:

dictionary: a book that lists the words of a language
in alphabetical order and explains their meaning.

glossary: an alphabetical list of terms or words found
in or relating to a specific subject, text, or dialect,
with explanations; a brief dictionary.

Whenever there is a sequence of one or more contiguous sibling run-in elements, if the sequence is followed by an element with display-inside: block and display-outside: block-level, all of the elements in the sequence generate inline-level boxes inside the following block, as if they were display-outside: inline-level, after its ::marker pseudo-element’s boxes (if any), but preceding any other boxes generates by the contents of the block (including the box generated by the ::before pseudo-element, if any).

Otherwise, the behavior depends on how many sibling run-in elements are in the sequence:

only one
The run-in element generates a block-level box, as if it were display-outside: block-level.
more than one
Each run-in element generates an inline-level box, as if it were display-outside: inline-level. An anonymous block box is generated around the entire sequence of boxes thus generated.

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.

Conformance

Document conventions

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.

Conformance classes

Conformance to this specification is defined for three conformance classes:

style sheet
A CSS style sheet.
renderer
A UA that interprets the semantics of a style sheet and renders documents that use them.
authoring tool
A UA that writes a style sheet.

A style sheet is conformant to this specification if all of its statements that use syntax defined in this module are valid according to the generic CSS grammar and the individual grammars of each feature defined in this module.

A renderer is conformant to this specification if, in addition to interpreting the style sheet as defined by the appropriate specifications, it supports all the features defined by this specification by parsing them correctly and rendering the document accordingly. However, the inability of a UA to correctly render a document due to limitations of the device does not make the UA non-conformant. (For example, a UA is not required to render color on a monochrome monitor.)

An authoring tool is conformant to this specification if it writes style sheets that are syntactically correct according to the generic CSS grammar and the individual grammars of each feature in this module, and meet all other conformance requirements of style sheets as described in this module.

Partial implementations

So that authors can exploit the forward-compatible parsing rules to assign fallback values, CSS renderers must treat as invalid (and ignore as appropriate) any at-rules, properties, property values, keywords, and other syntactic constructs for which they have no usable level of support. In particular, user agents must not selectively ignore unsupported component values and honor supported values in a single multi-value property declaration: if any value is considered invalid (as unsupported values must be), CSS requires that the entire declaration be ignored.

Experimental implementations

To avoid clashes with future CSS features, the CSS2.1 specification reserves a prefixed syntax for proprietary and experimental extensions to CSS.

Prior to a specification reaching the Candidate Recommendation stage in the W3C process, all implementations of a CSS feature are considered experimental. The CSS Working Group recommends that implementations use a vendor-prefixed syntax for such features, including those in W3C Working Drafts. This avoids incompatibilities with future changes in the draft.

Non-experimental implementations

Once a specification reaches the Candidate Recommendation stage, non-experimental implementations are possible, and implementors should release an unprefixed implementation of any CR-level feature they can demonstrate to be correctly implemented according to spec.

To establish and maintain the interoperability of CSS across implementations, the CSS Working Group requests that non-experimental CSS renderers submit an implementation report (and, if necessary, the testcases used for that implementation report) to the W3C before releasing an unprefixed implementation of any CSS features. Testcases submitted to W3C are subject to review and correction by the CSS Working Group.

Further information on submitting testcases and implementation reports can be found from on the CSS Working Group’s website at http://www.w3.org/Style/CSS/Test/. Questions should be directed to the public-css-testsuite@w3.org mailing list.

References

Normative References

[CSS21]
Bert Bos; et al. Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification. 7 June 2011. W3C Recommendation. URL: http://www.w3.org/TR/2011/REC-CSS2-20110607
[CSS3-FLEXBOX]
Tab Atkins Jr.; Elika J. Etemad; Alex Mogilevsky. CSS Flexible Box Layout Module. 18 September 2012. W3C Candidate Recommendation. (Work in progress.) URL: http://www.w3.org/TR/2012/CR-css3-flexbox-20120918/
[CSS3-GRID-LAYOUT]
Tab Atkins Jr.; Elika J. Etemad; Rossen Atanassov. CSS Grid Layout. 2 April 2013. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2013/WD-css3-grid-layout-20130402/
[CSS3RUBY]
Richard Ishida. CSS3 Ruby Module. 30 June 2011. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2011/WD-css3-ruby-20110630/
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. URL: http://www.ietf.org/rfc/rfc2119.txt

Informative References

Index

Property index

NameValueInitialApplies toInh.%agesMediaAnimatableComputed value
display-insideauto | block | table | flex | grid | rubyautoall elementsnon/aalla keyword
display-outsideblock-level | inline-level | none | table-row-group | table-header-group | table-footer-group | table-row | table-cell | table-column-group | table-column | table-caption | ruby-base | ruby-text | ruby-base-container | ruby-text-containerinline-levelall elementsnon/aallas specified
display-extrasnone | list-itemnoneall elementsnon/aallas specified
displayinline | 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-extras’> ]see individual propertiessee individual propertiessee individual propertiessee individual propertiessee individual propertiessee individual properties
display-boxnormal | none | contentsnormalall elementsnon/aallsee prose

Issues Index

Is fantasai’s proposal for a run-in model sane enough to include in this spec?
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?
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?