Abstract

This module describes how the CSS formatting box tree is generated from the document element tree and defines the display and box-suppress properties that control it.

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 section describes the status of this document at the time of
its publication. Other documents may supersede this document. A list of
current W3C publications and the latest revision of this technical report
can be found in the W3C technical reports
index at http://www.w3.org/TR/.

Publication as a Working Draft does not imply endorsement by the W3C
Membership. This is a draft document and may be updated, replaced or
obsoleted by other documents at any time. It is inappropriate to cite this
document as other than 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…”

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 beforedisplay: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.

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
Controlling Layout Modes

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.

The display-outside property specifies the outer display type
of the box generated by the element,
dictating how the element participates in its parent formatting context.

block-level

The element generates a block-level box,
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 generates an inline-level box,
and participates in an inline formatting context. [CSS21]

run-in

The element generates a run-in box.
Run-in elements act like inlines or blocks,
depending on the surrounding elements.
See §4
Run-In Layout for details.

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.

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?

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-suppress property.

It is recommended that box-suppress be used instead of display: none,
so that the element’s display type is automatically preserved
for when it’s no longer suppressed.

Some values of display-outside are specialized for particular formatting contexts,
and don’t have meaning outside of those specific contexts:

layout-specific internal types

These display types require their parent and children to be of particular display types.
For example, a table-row box requires its parent to be a table row group box
and its children to be table-cell boxes.

layout-specific leaf types

These display types require their parent to be of a particular display type,
but can accept any display-inside value.
For example, a table-caption box must have a table parent,
but can establish any kind of formatting context for its children.

Boxes with layout-specific types generate wrapper boxes around themselves
when placed in an incompatible parent,
as defined by their respective specifications.

When a box is inlinified,
it recursively inlinifies all of its in-flow children
unless it itself establishes a new formatting context,
so that no block-level descendants
break up the inline formatting context in which it participates.

The element generates boxes as normal,
but those boxes do not participate in layout in any way,
and must not be displayed.

For the purpose of any layout-related information,
such as querying for the computed value of the element’s width property,
it must be treated as if it did not generate any boxes.

Properties that rely on boxes but do not rely on layout,
such as animations, counter-increment, etc.,
must work as normal on this element and its descendants.

This needs more clarity about what "layout-related" and "participates in layout" means.
Does the box still generate anonymous boxes, etc.?

How does this affect speech? Is that "layout"?

We welcome better naming suggestions on this property.

4
Run-In Layout

A run-in box is a box that merges into a block that comes after it,
inserting itself at the beginning of that block’s inline-level content.
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 {
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.

If a run-in sequence is immediately followed by a block box
that does not establish a new formatting context,
it is inserted as direct children of the block box
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).

The reparented content is then formatted as if originally parented there.
Note that only layout is affected, not inheritance,
because property inheritance for non-anonymous boxes is based only on the element tree.

Otherwise,
an anonymous block box is generated around the run-in sequence
and all immediately following inline-level content
(up to, but not including, the next run-in sequence, if any).

A rectangle that forms the basis of sizing and positioning
for the boxes associated with it
(usually the children of the box that generated it).
Notably, a containing block is not a box
(it is a rectangle),
however it is often derived from the dimensions of a box.
If properties of a containing block are referenced,
they reference the values on the box that generated the containing block.
(For the initial containing block, the values are taken from the root element.)
See [CSS21]Section 9.1.2
and Section 10.1 for details.

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,
and Anton Prowse,
whose relentless assault on CSS2.1 Chapter 9 forced some order out of the chaos.

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.

Advisements are normative sections styled to evoke special attention and are
set apart from other normative text with <strong class="advisement">, like
this:
UAs MUST provide an accessible alternative.

Conformance classes

Conformance to this specification
is defined for three conformance classes:

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.