GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing drafts.csswg.org — CSS Display Module Level 4 1. IntroductionThis section is normative. CSS takes a source document organized as a tree of elements (which can contain a mix of other elements and text nodes) and text nodes (which can contain text), and renders it onto a canvas such as your screen, a piece of paper, or an audio stream. Although any such source document can be rendered with CSS, the most commonly used type is the DOM. [DOM] (Some of these more complex tree types might have additional types of nodes, such as the comment nodes in the DOM. For the purposes of CSS, all of these additional types of nodes are ignored, as if they didn’t exist.) To do this, it generates an intermediary structure, the box tree, which represents the formatting structure of the rendered document. Each box in the box tree represents its corresponding element (or pseudo-element) in space and/or time on the canvas, while each text sequence in the box tree likewise represents the corresponding contents of its text nodes. To create the box tree, CSS first uses cascading and inheritance, to assign a computed value for each CSS property to each element and text node in the source tree. (See [CSS-CASCADE-3].) Then, for each element, CSS generates zero or more boxes as specified by that element’s display property. Typically, an element generates a single box, the principal box, which represents itself and contains its contents in the box tree. However, some display values (e.g. display: list-item) generate more than one box (e.g. a principal block box and a child marker box). And some values (such as none or contents) cause the element and/or its descendants to not generate any boxes at all. Boxes are often referred to by their display type—e.g. a box generated by an element with display: block is called a “block box” or just a “block”. A box is assigned the same styles as its generating element, unless otherwise indicated.
In general, inherited properties are assigned to the principal box,
and then inherit through the box tree
to any other boxes generated by the same element.
Non-inherited properties default to applying to the principal box,
but when the element generates multiple boxes,
are sometimes defined to apply to a different box:
for example, the border properties applied to a table element
are applied to its table grid box,
not to its principal table wrapper box.
If the value computation process alters the styles of those boxes,
and the element’s style is requested
(such as through Similarly, each contiguous sequence of sibling text nodes generates a text sequence containing their text contents, which is assigned the same styles as the generating text nodes. If the sequence contains no text, however, it does not generate a text sequence. In constructing the box tree, boxes generated by an element are descendants of the principal box of any ancestor elements. In the general case, the direct parent box of an element’s principal box is the principal box of its nearest ancestor element that generates a box; however, there are some exceptions, such as for run-in boxes, display types (like tables) that generate multiple container boxes, and intervening anonymous boxes. An anonymous box is a box that is not associated with any element. Anonymous boxes are generated in certain circumstances to fix up the box tree when it requires a particular nested structure that is not provided by the boxes generated from the element tree. For example, a table cell box requires a particular type of parent box (the table row box), and will generate an anonymous table row box around itself if its parent is not a table row box. (See [CSS2] § 17.2.1.) Unlike element-generated boxes, whose styles inherit strictly through the element tree, anonymous boxes (which only exist in the box tree) inherit through their box tree parentage. In the course of layout, boxes and text sequences can be broken into multiple fragments. This happens, for example, when an inline box and/or text sequence is broken across lines, or when a block box is broken across pages or columns, in a process called fragmentation. It can also happen due to bidi reordering of text (see Applying the Bidirectional Reordering Algorithm in CSS Writing Modes) or higher-level display type box splitting, e.g. block-in-inline splitting (see CSS2§9.2) or column-spanner-in-block splitting (see CSS Multi-column Layout). A box therefore consists of one or more box fragments, and a text sequence consists of one or more text fragments. See [CSS-BREAK-3] for more information on fragmentation. Note: Many of the CSS specs were written before this terminology was ironed out, or refer to things incorrectly, so view older specs with caution when they’re using these terms. It should be possible to infer from context which term they really mean. Please report errors in specs when you find them, so they can be corrected. Note: Further information on the “aural” box tree and its interaction with the display property can be found in the CSS Speech Module. [CSS-SPEECH-1] Tests1.1. Module interactionsThis module replaces and extends the definition of the display property defined in [CSS2] section 9.2.4. None of the properties in this module apply to the Tests1.2. Value DefinitionsThis specification follows the CSS property definition conventions from [CSS2] using the value definition syntax from [CSS-VALUES-3]. Value types not defined in this specification are defined in CSS Values & Units [CSS-VALUES-3]. Combination with 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 they have not been repeated explicitly. 2. Box Layout Modes: the display property
User agents are expected to support this property on all media, including non-visual ones. The display property defines an element’s display type, which consists of the two basic qualities of how an element generates boxes:
Text sequences have no display type. Some display values have additional side-effects: such as list-item, which also generates a ::marker pseudo-element, and none, which causes the element’s entire subtree to be left out of the box tree.
The display property has no effect on an element’s semantics:
these are defined by the document language and are not affected by CSS.
Aside from the none value,
which also affects the aural/speech output [CSS-SPEECH-1]
and interactivity of an element and its descendants,
the display property only affects visual layout:
its purpose is to allow designers freedom
to change the layout behavior of an element
without affecting the underlying document semantics.
Values are defined as follows: <display-outside> = block | inline | run-in <display-inside> = flow | flow-root | table | flex | grid | ruby <display-listitem> = <display-outside>? && [ flow | flow-root ]? && list-item <display-internal> = 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 <display-box> = contents | none <display-legacy> = inline-block | inline-table | inline-flex | inline-grid The following informative table summarizes the values of display: Note: Following the precedence rules of “most backwards-compatible, then shortest”, serialization of equivalent display values uses the “Short display” column. [CSSOM] Tests
2.1. Outer Display Roles for Flow Layout: the block, inline, and run-in keywordsThe <display-outside> keywords specify the element’s outer display type, which is essentially its principal box’s role in flow layout. They are defined as follows:
Note: Outer display types do affect replaced elements. If a <display-outside> value is specified but <display-inside> is omitted, the element’s inner display type defaults to flow. Tests
2.2. Inner Display Layout Models: the flow, flow-root, table, flex, grid, and ruby keywordsThe <display-inside> keywords specify the element’s inner display type, which defines the type of formatting context that lays out its contents (assuming it is a non-replaced element). They are defined as follows:
If a <display-inside> value is specified but <display-outside> is omitted, the element’s outer display type defaults to block—except for ruby, which defaults to inline. Tests2.3. Generating Marker Boxes: the list-item keywordThe list-item keyword
causes the element to generate a ::marker pseudo-element [CSS-PSEUDO-4]
with the content specified by its If no inner display type value is specified, the principal box’s inner display type defaults to flow. If no outer display type value is specified, the principal box’s outer display type defaults to block. Note: In this level, as restricted in the grammar, list-items are limited to the Flow Layout display types (block/inline/run-in with flow/flow-root inner types). This restriction may be relaxed in a future level of this module. Tests2.4. Layout-Internal Display Types: the table-* and ruby-* keywordsSome layout models, such as table and ruby, have a complex internal structure, with several different roles that their children and descendants can fill. This section defines those “layout-internal” display values, which only have meaning within that particular layout mode. Unless otherwise specified, both the inner display type and the outer display type of elements using these display values are set to the given keyword. When the display property of a replaced element computes to one of the layout-internal values, it is handled as having a used value of inline. White space collapsing and anonymous box generation must happen around those replaced elements based on that inline value, as if they never had a layout-internal display value applied to them. Authors should not assign a layout-internal display value to replaced elements. The <display-internal> keywords are defined as follows:
Boxes with layout-specific display types generate anonymous wrapper boxes around themselves when placed in an incompatible parent, as defined by their respective specifications.
For example, Table Layout requires that a table-cell box
must have a table-row parent box.
If it is misparented, like so:
It will generate wrapper boxes around itself, producing a structure like: block box └anonymous table box └anonymous table-row-group box └anonymous table-row box └table-cell box Even if the parent is another internal table element, if it’s not the correct one, wrapper boxes will be generated. For example, in the following markup:
Anonymous wrapper box generation will produce: table box └anonymous table-row-group box └table-row box └table-cell box This "fix-up" ensures that table layout has a predictable structure to operate on. TestsThis section lacks tests. 2.5. Box Generation: the none and contents keywordsWhile display can control the types of boxes an element will generate, it can also control whether an element will generate any boxes at all. The <display-box> keywords are defined as follows:
Elements with either of these values do not have inner or outer display types, because they don’t generate any boxes at all. Note: As these values cause affected elements to not generate a box, anonymous box generation rules will ignore the elided elements entirely, as if they did not exist in the box tree. Markup-based relationships, however, are not affected by these values,
as they are solely rendering-time effects.
For example,
although they may affect which table cell appears in a column,
they do not affect which table cell is associated with a particular column element.
Similarly, they cannot affect which HTML Tests
2.6. Precomposed Inline-level Display ValuesCSS level 2 used a single-keyword syntax for display, requiring separate keywords for block-level and inline-level variants of the same layout mode. These <display-legacy> keywords map as follows:
Note: Although these keywords and their equivalents compute to the same value, their specified values remain distinct. Note: The TestsThis section lacks tests. 2.7. Automatic Box Type TransformationsSome layout effects require blockification or inlinification of the box type, which sets the box’s computed outer display type to block or inline (respectively). (This has no effect on display types that generate no box at all, such as none or contents.) Additionally:
Note: There are two methods used to fix up box types when a box is mismatched to its context. One is transformation of the computed value of display, such as blockification and inlinification described here. The other, taking place during box tree construction (after computed values have been determined), is the creation of intermediary anonymous boxes, such as happens in tables, ruby, and flow layout.
Some examples of computed-value fixup include:
2.8. The Root Element’s Principal BoxThe root element’s display type is always blockified, and its principal box always establishes an independent formatting context. This box’s containing block is the initial containing block. Additionally, a display of contents computes to block on the root element. 2.9. Animating and Interpolating displayIn general, the display property’s animation type is discrete. However, similar to interpolation of visibility (see Web Animations § Animation of visibility), during interpolation between none and any other display value, p values between 0 and 1 map to the non-none value. Additionally, the element is inert as long as its display value would compute to none when ignoring the Transitions and Animations cascade origins. 3. Display Order: the order property
Boxes are generally displayed and laid out in the same order as they appear in the source document. In some formatting contexts, the order property can be used to rearrange the order of boxes to deliberately create a divergence of the logical order of elements and their spatial arrangement on the 2D visual canvas. (See § 3.1 Reordering and Accessibility.) Specifically, the order property controls the order in which flex items or grid items appear within their container, by assigning them to ordinal groups. It takes a single <integer> value, which specifies which ordinal group the item belongs to.
Here’s an example of a catalog item card
which has a title, a photo, and a description.
Within each entry, the source document content is ordered logically
with the title first, followed by the description and the photo.
This provides a sensible ordering for speech rendering and in non-CSS browsers.
For a more compelling visual presentation, however,
order is used to pull the image up from later in the content to the top of the card.
article.sale-item
Computer Starter KitThis is the best computer money can buy, if you don’t have much money.
Flex and grid containers lay out their contents in order-modified document order, starting from the lowest numbered ordinal group and going up. Items with the same ordinal group are laid out in the order they appear in the source document. This also affects the painting order [CSS2], exactly as if the flex/grid items were reordered in the source document. Absolutely-positioned children of a flex/grid container are treated as having order: 0 for the purpose of determining their painting order relative to flex/grid items. Unless otherwise specified by a future specification, this property has no effect on boxes that are not flex items or grid items. 3.1. Reordering and AccessibilityThe order property does not affect ordering in non-visual media
(such as speech).
Likewise, order does not affect
the default traversal order of sequential navigation modes
(such as cycling through links, see e.g. Authors must use order only for spatial, not logical, reordering of content. Style sheets that use order to perform logical reordering are non-conforming. Note: This is so that non-visual media and non-CSS UAs, which typically present content linearly, can rely on a logical source order, while order is used to tailor the layout order. (Since visual perception is two-dimensional and non-linear, the desired layout order is not always logical.) In order to preserve the author’s intended ordering in all presentation modes, authoring tools—including WYSIWYG editors as well as Web-based authoring aids—must reorder the underlying document source and not use order to perform reordering unless the author has explicitly indicated that the spatial order should be out-of-sync with the underlying document order (which determines speech and navigation order).
For example, a tool might offer both drag-and-drop reordering of flex items
as well as handling of media queries for alternate layouts per screen size range.
Since most of the time, reordering should affect all screen ranges as well as navigation and speech order, the tool would perform drag-and-drop reordering at the DOM layer. In some cases, however, the author may want different layouts per screen size. The tool could offer this functionality by using order together with media queries, but also tie the smallest screen size’s ordering to the underlying DOM order (since this is most likely to be a logical linear presentation order) while using order to define the visual presentation order in other size ranges. This tool would be conformant, whereas a tool that only ever used order to handle drag-and-drop reordering (however convenient it might be to implement it that way) would be non-conformant. Note: User agents, including browsers, accessible technology, and extensions, may offer spatial navigation features. This section does not preclude respecting the order property when determining element ordering in such spatial navigation modes; indeed it would need to be considered for such a feature to work. But order is not the only (or even the primary) CSS property that would need to be considered for such a spatial navigation feature. A well-implemented spatial navigation feature would need to consider all the layout features of CSS that modify spatial relationships. 4. Reading Order: the reading-flow propertyA reading flow container is a block, flex or grid container with a valid reading-flow value other than normal. The rendering-defined sibling reading flow of a reading flow container is an ordered list of the children of the container. All children must render to an element and are considered siblings in the reading flow container. The order is determined by the reading-flow property. Should this property also apply to tables? [Issue #9922]
The reading-flow property controls the order in which elements are rendered to speech or are navigated to when using (linear) sequential navigation methods. It takes one keyword value. Values are defined as follows:
In this example, there are three flex items displayed as a row,
with reading-flow: flex-visual
and flex-direction: row-reverse.
We are in English with a text direction of left to right.
The reading order of these items is therefore
"Item 3", "Item 2", "Item 1", reading from left to right.
.wrapper
In this example there are four grid items,
placed on a grid and displayed visually out of DOM order.
The reading-flow property has a value of grid-rows,
and the document is in English.
The reading order of these items is therefore
"Item 4", "Item 2", "Item 3", "Item 1".
.wrapper The reading-flow property affects neither layout nor painting order and therefore has no effect on rendering to the visual canvas. When using a flex-* or grid-* keyword value, the order property is taken into account.
In this example, there are three flex items displayed as a row,
with reading-flow: flex-flow.
The third item in the DOM has
order=-1.
The reading order of these items is therefore
"Item 3", "Item 1", "Item 2".
.wrapper a:nth-child 4.1. Overriding Reading Flow: the reading-order property
The reading-order property lets the author change where in the reading flow an item is visited, overriding the position set by the reading-flow property on its parent. It takes a single <integer> value, which specifies which ordinal group the item belongs to. Sibling elements are ordered starting from the lowest numbered ordinal group and going up. If the reading order of two items is equivalent, the reading-flow property breaks the tie.
In this example there are six grid items,
the grid-auto-flow property has a value of dense,
therefore items may display out of source order.
The reading-order property on the item with a class of top is
-1
Therefore Item 4 will be the first item in reading flow.
The remaining items will be visited in the order they display in rows,
as reading-flow has a value of grid-rows.
.wrapper
In this example there are five direct block-level children of a block container
where reading-flow has a value of source-order.
The third item has a reading-order value of
-1.
The reading flow visits the third item first, then the rest in source order.
.wrapper The source document should express the underlying logical order of elements. The reading-flow and reading-order properties exist for cases where a given document can have multiple reading orders depending on layout changes, e.g. in response to media queries. In such cases, the most common or most fundamental reading order should be encoded in the source order so that the document is sensical without CSS. Design Considerations and BackgroundSome of the considerations that went into the design of reading-flow are:
TestsDOM needs a convenient reordering function so that authors (even authors who don’t usually write JS) can easily perform source order reordering when necessary instead of misusing order or reading-flow. [Issue #7387] 5. Invisibility: the visibility property
The visibility property specifies whether the box is rendered. Invisible boxes still affect layout. (Set the display property to none to suppress box generation altogether.). Values have the following meanings:
Note: Currently, many user agents and/or accessibility tools don’t correctly implement the accessibility implications of visible elements with semantic relationships to invisible elements, so, for example, making parent elements with special roles (such as table rows) invisible while leaving child elements with special roles (such as table cells) visible can be problematic for users of those tools. Authors should avoid creating these situations until the tooling situation improves. Invisible boxes are not rendered (as if they were fully transparent), cannot be interacted with (and behave as if they had pointer-events: none), are removed from navigation (similar to display: none), and are also not rendered to speech (except when speak is always [CSS-SPEECH-1]). However, as with display: contents, their semantic role as a container is not affected, to ensure that any visible descendants are properly interpreted. Note: If speak is always, an otherwise invisible box is rendered to speech, and may be interacted with using non-visual/spatial methods.
While temporarily hiding things with display: none
is often sufficient,
doing so removes the elements from layout entirely,
possibly causing unwanted movement or reflow of the page
when an element is hidden or shown.
visibility: hidden can instead be used
to keep the page’s layout stable
as something is hidden and displayed.
For example, here is a (deliberately simplified) possible implementation of a "spoiler" element that can be revealed by clicking on the hidden text:
This example is deliberately significantly simplified. It is missing a number of accessibility and UX features that a well-designed spoiler element would have to show off the visibility usage more plainly. Don’t copy this code for a real site. TestsThis section lacks tests. 6. Run-In LayoutA 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. A run-in box behaves exactly as any other inline-level box, except:
A run-in sequence is a maximal sequence of consecutive sibling run-in boxes and intervening white space and/or out-of-flow boxes. Note: This statement implies that out-of-flow boxes are reparented if they are between two run-in boxes. Another alternative would be to leave behind the intervening out-of-flow boxes, or to have out-of-flow boxes impede the running-in of earlier boxes. Implementers and authors are encouraged to contact the CSSWG if they have a preferred behavior, as this one was picked somewhat at random. This fixup occurs before the anonymous block and inline box fixup described in CSS2§9.2, and affects the determination of the first formatted line of the affected elements as if the run-in sequence were originally in its final location in the box tree. Note: As the earliest run-in represents the first text on the first formatted line of its containing block, a ::first-letter pseudo-element applied to that block element selects the first letter of the run-in, rather than the first letter of its own contents. Note: This run-in model is slightly different from the one proposed in earlier revisions of [CSS2]. Tests
Appendix A: GlossaryThe following terms are defined here for convenience:
See [CSS2] Chapter 9 for a fuller definition of these terms. Appendix B: Effects of display: contents on Unusual ElementsThis section is (currently) non-normative. Some elements aren’t rendered purely by CSS box concepts;
for example, replaced elements (such as This appendix defines how they interact with display: contents. HTML Elements
SVG Elements
The intention here is that
the display: none behavior applies
whenever the "rendering context" inside the element
is different than the context outside of it.
If the element’s child elements would not be valid children
of the element’s parent,
you cannot simply hoist them up the formatting tree.
For example, text content and text formatting elements in SVG
require a Similarly, if hoisting would convert the children from
non-rendered elements
(e.g., a shape inside a When an element is stripped from the formatting tree, then any SVG attributes on that element that control layout and visual formatting are ignored when rendering the contents. However, SVG presentation attributes—which map to CSS properties—continue to affect value processing and inheritance [CSS-CASCADE-3]; thus such attributes can affect the layout and visual formatting of the element’s descendants by influencing the values of such properties on those descendants. MathML ElementsFor all MathML elements, display: contents computes to display: none. Appendix C: Box Construction Guidelines for Spec AuthorsThis section is non-normative guidance for specification authors.
AcknowledgmentsWe 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; Anton Prowse, whose relentless assault on CSS2.1 Chapter 9 forced some order out of the chaos; and Oriol Brufau, who teased apart dozens of fine distinctions and errors in this spec. Honorable mentions also go to David Baron, Mats Palmgren, Ilya Streltsyn, and Boris Zbarsky for their feedback. ChangesRecent ChangesSignificant changes since the 19 December 2024 First Public Working Draft:
Additions since Level 3The following features were added since CSS Display Module Level 3:
Privacy ConsiderationsThis specification introduces no new privacy considerations. Security ConsiderationsThis specification introduces no new security considerations. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |