GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing drafts.csswg.org (truncated) — CSS Containment Module Level 2

1. Introduction

Efficiently rendering a website relies on the user agent being able to detect what parts of the page are being displayed, which parts might affect the currently-displayed section, and what can be ignored.

There are various heuristics that can be used to guess when a given sub-tree is independent of the rest of the page in some manner, but they’re fragile, so innocuous changes to a page may inadvertently make it fail such heuristic tests, causing rendering to fall into a slow code path. There are also many things that would be good to isolate which are difficult or impossible to detect in a heuristic manner.

To alleviate these problems and allow strong, predictable isolation of a subtree from the rest of the page, this specification defines a contain property.

To allow even further optimization of off-screen contents, this spec also defines a content-visibility property, enabling the user agent to skip an element’s layout and painting entirely when not needed.

1.1. Module Interactions

This document defines new features not present in earlier specifications. In addition, it aims to replace and supersede [CSS-CONTAIN-1] once stable.

1.2. Value Definitions

This 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. Strong Containment: the contain property

Tests

The following tests are crash tests that relate to general usage of this feature but are not particularly tied to any particular normative statement.

  • contain-chrome-thcrash-001.html (live test) (source)
  • contain-crash.html (live test) (source)
  • contain-flexbox-outline.html (live test) (source)
  • contain-nested-crash-001.html (live test) (source)
  • contain-nested-crash-002.html (live test) (source)
  • contain-nested-crash-003.html (live test) (source)
  • contain-nested-crash-004.html (live test) (source)
  • contain-nested-relayout-boundary.html (live test) (source)
  • quote-scoping-shadow-dom-crash.html (live test) (source)
  • contain-style-remove-element-crash.html (live test) (source)

Name: contain
Value: none | strict | content | [ [size | inline-size] || layout || style || paint ]
Initial: none
Applies to: See below
Inherited: no
Percentages: n/a
Computed value: the keyword none or one or more of size, layout, style, paint
Canonical order: per grammar
Animation type: not animatable
Tests
  • contain-animation-001.html (live test) (source)
  • inheritance.html (live test) (source)
  • contain-computed.html (live test) (source)
  • contain-invalid.html (live test) (source)
  • contain-valid.html (live test) (source)
  • contain-computed-children.html (live test) (source)
  • contain-layout-size-003.html (live test) (source)
  • contain-paint-size-001.html (live test) (source)
  • contain-paint-size-002.html (live test) (source)
  • contain-paint-size-003.html (live test) (source)

User agents are expected to support this property on all media, including non-visual ones.

The contain property allows an author to indicate that an element and its contents are, as much as possible, independent of the rest of the document tree. This allows user agents to utilize much stronger optimizations when rendering a page using contain properly, and allows authors to be confident that their page won’t accidentally fall into a slow code path due to an innocuous change.

none
This value indicates that the property has no effect. The element renders as normal, with no containment effects applied.
strict
This value computes to size layout paint style, and thus turns on all forms of containment for the element.
Tests
  • contain-strict-001.html (live test) (source)
  • contain-strict-002.html (live test) (source)
  • contain-strict-003.html (live test) (source)
  • contain-strict-011.html (live test) (source)
  • contain-flexbox-outline.html (live test) (source)
content
This value computes to layout paint style, and thus turns on all forms of containment except size containment for the element.
Tests
  • contain-content-001.html (live test) (source)
  • contain-content-002.html (live test) (source)
  • contain-content-003.html (live test) (source)
  • contain-content-004.html (live test) (source)
  • contain-content-011.html (live test) (source)

Note: contain: content is reasonably "safe" to apply widely; its effects are fairly minor in practice, and most content won’t run afoul of its restrictions. However, because it doesn’t apply size containment, the element can still respond to the size of its contents, which can cause layout-invalidation to percolate further up the tree than desired. Use contain: strict when possible, to gain as much containment as you can.

size
The value turns on size containment for the element. This ensures that the containment box can be laid out without needing to examine its descendants.
Tests
  • contain-size-001.html (live test) (source)
  • contain-size-002.html (live test) (source)
  • contain-size-003.html (live test) (source)
  • contain-size-004.html (live test) (source)
  • contain-size-005.html (live test) (source)
  • contain-size-006.html (live test) (source)
  • contain-size-007.html (live test) (source)
  • contain-size-008.html (live test) (source)
  • contain-size-009.html (live test) (source)
  • contain-size-010.html (live test) (source)
  • contain-size-011.html (live test) (source)
  • contain-size-012.html (live test) (source)
  • contain-size-012b.html (live test) (source)
  • contain-size-013.html (live test) (source)
  • contain-size-021.html (live test) (source)
  • contain-size-023.html (live test) (source)
  • contain-size-025.html (live test) (source)
  • contain-size-027.html (live test) (source)
  • contain-size-041.html (live test) (source)
  • contain-size-042.html (live test) (source)
  • contain-size-051.html (live test) (source)
  • contain-size-052.html (live test) (source)
  • contain-size-056.html (live test) (source)
  • contain-size-061.html (live test) (source)
  • contain-size-062.html (live test) (source)
  • contain-size-063.html (live test) (source)
  • contain-size-baseline-001.html (live test) (source)
  • contain-size-borders.html (live test) (source)
  • contain-size-breaks-001.html (live test) (source)
  • contain-size-button-001.html (live test) (source)
  • contain-size-fieldset-001.html (live test) (source)
  • contain-size-fieldset-002.html (live test) (source)
  • contain-size-flexbox-001.html (live test) (source)
  • contain-size-flexbox-002.html (live test) (source)
  • contain-size-grid-001.html (live test) (source)
  • contain-size-grid-002.html (live test) (source)
  • contain-size-grid-003.html (live test) (source)
  • contain-size-grid-004.html (live test) (source)
  • contain-size-grid-005.html (live test) (source)
  • contain-size-grid-006.html (live test) (source)
  • contain-size-monolithic-001.html (live test) (source)
  • contain-size-monolithic-002.html (live test) (source)
  • contain-size-multicol-001.html (live test) (source)
  • contain-size-multicol-as-flex-item.html (live test) (source)
  • contain-size-replaced-001.html (live test) (source)
  • contain-size-replaced-002.html (live test) (source)
  • contain-size-replaced-003a.html (live test) (source)
  • contain-size-replaced-003b.html (live test) (source)
  • contain-size-replaced-003c.html (live test) (source)
  • contain-size-replaced-004.html (live test) (source)
  • contain-size-replaced-005.html (live test) (source)
  • contain-size-replaced-006.html (live test) (source)
  • contain-size-replaced-007.html (live test) (source)
  • contain-size-select-001.html (live test) (source)
  • contain-size-select-002.html (live test) (source)
  • contain-size-scrollbars-001.html (live test) (source)
  • contain-size-scrollbars-002.html (live test) (source)
  • contain-size-scrollbars-003.html (live test) (source)
  • contain-size-scrollbars-004.html (live test) (source)
  • contain-layout-size-003.html (live test) (source)
  • contain-paint-size-001.html (live test) (source)
  • contain-paint-size-002.html (live test) (source)
  • contain-paint-size-003.html (live test) (source)
  • contain-size-removed.html (live test) (source)
  • contain-size-dynamic-001.html (live test) (source)
  • contain-size-grid-indefinite-height-min-height-flex-row.html (live test) (source)
  • contain-size-grid-stretches-auto-rows.html (live test) (source)
inline-size
This value turns on inline-size containment for the element. This prevents the inline-size of its principal box from directly depending on its contents.
Tests
  • contain-inline-size-bfc-floats-001.html (live test) (source)
  • contain-inline-size-bfc-floats-002.html (live test) (source)
  • contain-inline-size-fieldset.html (live test) (source)
  • contain-inline-size-flex.html (live test) (source)
  • contain-inline-size-flexitem.html (live test) (source)
  • contain-inline-size-grid.html (live test) (source)
  • contain-inline-size-intrinsic.html (live test) (source)
  • contain-inline-size-legend.html (live test) (source)
  • contain-inline-size-multicol.html (live test) (source)
  • contain-inline-size-regular-container.html (live test) (source)
  • contain-inline-size-removed.html (live test) (source)
  • contain-inline-size-replaced.html (live test) (source)
  • contain-inline-size-table.html (live test) (source)
  • contain-inline-size-vertical-rl-.html (live test) (source)
  • contain-inline-size-grid-indefinite-height-min-height-flex-row.html (live test) (source)
  • contain-inline-size-grid-stretches-auto-rows.html (live test) (source)

Note: There can still be indirect dependencies, see § 3.2 Inline-Size Containment.

layout
This value turns on layout containment for the element. This ensures that the containment box is totally opaque for layout purposes; nothing outside can affect its internal layout, and vice versa.
Tests
  • contain-layout-001.html (live test) (source)
  • contain-layout-002.html (live test) (source)
  • contain-layout-003.html (live test) (source)
  • contain-layout-004.html (live test) (source)
  • contain-layout-005.html (live test) (source)
  • contain-layout-006.html (live test) (source)
  • contain-layout-007.html (live test) (source)
  • contain-layout-009.html (live test) (source)
  • contain-layout-010.html (live test) (source)
  • contain-layout-011.html (live test) (source)
  • contain-layout-012.html (live test) (source)
  • contain-layout-013.html (live test) (source)
  • contain-layout-014.html (live test) (source)
  • contain-layout-016.html (live test) (source)
  • contain-layout-017.html (live test) (source)
  • contain-layout-018.html (live test) (source)
  • contain-layout-019.html (live test) (source)
  • contain-layout-020.html (live test) (source)
  • contain-layout-021.html (live test) (source)
  • contain-layout-baseline-001.html (live test) (source)
  • contain-layout-baseline-002.html (live test) (source)
  • contain-layout-baseline-003.html (live test) (source)
  • contain-layout-baseline-004.html (live test) (source)
  • contain-layout-baseline-005.html (live test) (source)
  • contain-layout-breaks-001.html (live test) (source)
  • contain-layout-breaks-002.html (live test) (source)
  • contain-layout-cell-001.html (live test) (source)
  • contain-layout-cell-002.html (live test) (source)
  • contain-layout-flexbox-001.html (live test) (source)
  • contain-layout-grid-001.html (live test) (source)
  • contain-layout-ifc-022.html (live test) (source)
  • contain-layout-independent-formatting-context-001.html (live test) (source)
  • contain-layout-independent-formatting-context-002.html (live test) (source)
  • contain-layout-independent-formatting-context-003.html (live test) (source)
  • contain-layout-ink-overflow-013.html (live test) (source)
  • contain-layout-ink-overflow-014.html (live test) (source)
  • contain-layout-ink-overflow-015.html (live test) (source)
  • contain-layout-ink-overflow-016.html (live test) (source)
  • contain-layout-ink-overflow-017.html (live test) (source)
  • contain-layout-ink-overflow-018.html (live test) (source)
  • contain-layout-ink-overflow-019.html (live test) (source)
  • contain-layout-ink-overflow-020.html (live test) (source)
  • contain-layout-size-003.html (live test) (source)
  • contain-subgrid-001.html (live test) (source)
  • contain-layout-dynamic-001.html (live test) (source)
  • contain-layout-dynamic-004.html (live test) (source)
  • contain-layout-dynamic-005.html (live test) (source)
style
This value turns on style containment for the element. This ensures that, for properties which can have effects on more than just an element and its descendants, those effects don’t escape the element.
Tests
  • contain-style-baseline-001.html (live test) (source)
  • contain-style-breaks-001.html (live test) (source)
  • contain-style-breaks-002.html (live test) (source)
  • contain-style-breaks-003.html (live test) (source)
  • contain-style-breaks-004.html (live test) (source)
  • contain-style-breaks-005.html (live test) (source)
  • contain-style-counters-001.html (live test) (source)
  • contain-style-counters-002.html (live test) (source)
  • contain-style-counters-003.html (live test) (source)
  • contain-style-counters-004.html (live test) (source)
  • contain-style-counters-005.html (live test) (source)
  • contain-style-ol-ordinal-li-container.html (live test) (source)
  • contain-style-ol-ordinal-pseudo-reversed.html (live test) (source)
  • contain-style-ol-ordinal-pseudo.html (live test) (source)
  • contain-style-ol-ordinal-reversed.html (live test) (source)
  • contain-style-ol-ordinal-start-reversed.html (live test) (source)
  • contain-style-ol-ordinal-start.html (live test) (source)
  • contain-style-ol-ordinal.html (live test) (source)
  • counter-scoping-001.html (live test) (source)
  • counter-scoping-002.html (live test) (source)
  • counter-scoping-003.html (live test) (source)
  • counter-scoping-004.html (live test) (source)
  • quote-scoping-001.html (live test) (source)
  • quote-scoping-002.html (live test) (source)
  • quote-scoping-003.html (live test) (source)
  • quote-scoping-004.html (live test) (source)
  • quote-scoping-invalidation-001.html (live test) (source)
  • quote-scoping-invalidation-002.html (live test) (source)
  • quote-scoping-invalidation-003.html (live test) (source)
  • quote-scoping-invalidation-004.html (live test) (source)
  • contain-style-dynamic-001.html (live test) (source)
paint
This value turns on paint containment for the element. This ensures that the descendants of the containment box don’t display outside its bounds, so if an element is off-screen or otherwise not visible, its descendants are also guaranteed to be not visible.
Tests
  • contain-paint-001.html (live test) (source)
  • contain-paint-002.html (live test) (source)
  • contain-paint-004.html (live test) (source)
  • contain-paint-005.html (live test) (source)
  • contain-paint-006.html (live test) (source)
  • contain-paint-007.html (live test) (source)
  • contain-paint-008.html (live test) (source)
  • contain-paint-009.html (live test) (source)
  • contain-paint-010.html (live test) (source)
  • contain-paint-011.html (live test) (source)
  • contain-paint-012.html (live test) (source)
  • contain-paint-014.html (live test) (source)
  • contain-paint-015.html (live test) (source)
  • contain-paint-016.html (live test) (source)
  • contain-paint-017.html (live test) (source)
  • contain-paint-018.html (live test) (source)
  • contain-paint-019.html (live test) (source)
  • contain-paint-020.html (live test) (source)
  • contain-paint-021.html (live test) (source)
  • contain-paint-022.html (live test) (source)
  • contain-paint-023.html (live test) (source)
  • contain-paint-024.html (live test) (source)
  • contain-paint-025.html (live test) (source)
  • contain-paint-047.html (live test) (source)
  • contain-paint-048.html (live test) (source)
  • contain-paint-baseline-001.html (live test) (source)
  • contain-paint-cell-001.html (live test) (source)
  • contain-paint-cell-002.html (live test) (source)
  • contain-paint-clip-011.html (live test) (source)
  • contain-paint-clip-012.html (live test) (source)
  • contain-paint-clip-013.html (live test) (source)
  • contain-paint-clip-014.html (live test) (source)
  • contain-paint-clip-015.html (live test) (source)
  • contain-paint-clip-016.html (live test) (source)
  • contain-paint-clip-017.html (live test) (source)
  • contain-paint-clip-018.html (live test) (source)
  • contain-paint-clip-019.html (live test) (source)
  • contain-paint-ifc-011.html (live test) (source)
  • contain-paint-independent-formatting-context-001.html (live test) (source)
  • contain-paint-independent-formatting-context-002.html (live test) (source)
  • contain-paint-independent-formatting-context-003.html (live test) (source)
  • contain-paint-size-001.html (live test) (source)
  • contain-paint-size-002.html (live test) (source)
  • contain-paint-size-003.html (live test) (source)
  • contain-paint-table-001.html (live test) (source)
  • contain-paint-table-002.html (live test) (source)
  • contain-subgrid-001.html (live test) (source)
  • contain-paint-change-opacity.html (live test) (source)
  • contain-paint-dynamic-001.html (live test) (source)
  • contain-paint-dynamic-002.html (live test) (source)
  • contain-paint-dynamic-003.html (live test) (source)
  • contain-paint-dynamic-004.html (live test) (source)
  • contain-paint-dynamic-005.html (live test) (source)

This property generally applies to all elements (including CSS Pseudo-Elements 4 § 4.1 Generated Content Pseudo-elements: ::before and ::after), although some types of containment have no effect on some elements, as detailed in § 3 Types of Containment. In addition, in the case of [SVG2], the contain property only applies to svg elements that have an associated CSS layout box.

contain is useful when used widely on a page, particularly when a page contains a lot of "widgets" which are all independent.

For example, assume a micropost social network had markup something like this:

<body>
  <aside>...</aside>
  <section>
    <h2>Messages</h2>
    <article>
      Lol, check out this dog: images.example.com/jsK3jkl
    </article>
    <article>
      I had a ham sandwich today. #goodtimes
    </article>
    <article>
      I have political opinions that you need to hear!
    </article>
    …
  </section>
</body>

There are probably a lot of messages displayed on the site, but each is independent and won’t affect anything else on the site. As such, each can be marked with contain: content to communicate this to the user agent, so it can optimize the page and skip a lot of computation for messages that are off-screen. If the size of each message is known ahead of time, contain: strict can be applied to communicate further restrictions.

Additionally, when any containments are active on either the HTML html or body elements, propagation of properties from the body element to the initial containing block, the viewport, or the canvas background, is disabled. Notably, this affects:

  • writing-mode, direction, and text-orientation (see CSS Writing Modes 3 § 8 The Principal Writing Mode)

  • overflow and its longhands (see CSS Overflow 3 § 3.1.4 Overflow Viewport Propagation)

  • background and its longhands (see CSS Backgrounds 3 § 2.11.2 The Canvas Background and the HTML <body> Element)

Tests
  • contain-body-bg-001.html (live test) (source)
  • contain-body-bg-002.html (live test) (source)
  • contain-body-bg-003.html (live test) (source)
  • contain-body-bg-004.html (live test) (source)
  • contain-body-dir-001.html (live test) (source)
  • contain-body-dir-002.html (live test) (source)
  • contain-body-dir-003.html (live test) (source)
  • contain-body-dir-004.html (live test) (source)
  • contain-body-overflow-001.html (live test) (source)
  • contain-body-overflow-002.html (live test) (source)
  • contain-body-overflow-003.html (live test) (source)
  • contain-body-overflow-004.html (live test) (source)
  • contain-body-t-o-001.html (live test) (source)
  • contain-body-t-o-002.html (live test) (source)
  • contain-body-t-o-003.html (live test) (source)
  • contain-body-t-o-004.html (live test) (source)
  • contain-body-w-m-001.html (live test) (source)
  • contain-body-w-m-002.html (live test) (source)
  • contain-body-w-m-003.html (live test) (source)
  • contain-body-w-m-004.html (live test) (source)
  • contain-html-bg-001.html (live test) (source)
  • contain-html-bg-002.html (live test) (source)
  • contain-html-bg-003.html (live test) (source)
  • contain-html-bg-004.html (live test) (source)
  • contain-html-dir-001.html (live test) (source)
  • contain-html-dir-002.html (live test) (source)
  • contain-html-dir-003.html (live test) (source)
  • contain-html-dir-004.html (live test) (source)
  • contain-html-overflow-001.html (live test) (source)
  • contain-html-overflow-002.html (live test) (source)
  • contain-html-overflow-003.html (live test) (source)
  • contain-html-overflow-004.html (live test) (source)
  • contain-html-t-o-001.html (live test) (source)
  • contain-html-t-o-002.html (live test) (source)
  • contain-html-t-o-003.html (live test) (source)
  • contain-html-t-o-004.html (live test) (source)
  • contain-html-w-m-001.html (live test) (source)
  • contain-html-w-m-002.html (live test) (source)
  • contain-html-w-m-003.html (live test) (source)
  • contain-html-w-m-004.html (live test) (source)

Note: Propagation to the initial containing block, the viewport, or the canvas background, of properties set on the html element itself is unaffected.

Note: Several properties beyond contain can turn on various containments for an element. These do not affect the value of contain; an element can have contain: none but still have layout containment turned on by content-visibility, for example.

3. Types of Containment

There are several varieties of containment that an element can be subject to, restricting the effects that its descendants can have on the rest of the page in various ways. Containment enables much more powerful optimizations by user agents, and helps authors compose their page out of functional units, as it limits how widely a given change can affect a document.

Specification authors introducing new properties or mechanisms need to consider whether and how the various types of containment affect what they are introducing, and include in their specification any effect not described here.

3.1. Size Containment

Giving an element size containment makes its principal box a size containment box and has the following effects:

  1. The intrinsic sizes of the size containment box are determined as if the element had no content, following the same logic as when sizing as if empty.

    Note: This affects explicit invocations of the min-content or max-content keywords, as well as any calculation that depends on these measurement, such as sizing grid tracks into which a size contained item is placed, or if fit-content sizing the containment box’s parent.

    Tests
    • contain-size-013.html (live test) (source)
    • contain-size-041.html (live test) (source)
    • contain-size-042.html (live test) (source)
    • contain-size-replaced-001.html (live test) (source)
    • contain-size-replaced-002.html (live test) (source)
    • contain-size-replaced-003a.html (live test) (source)
    • contain-size-replaced-003b.html (live test) (source)
    • contain-size-replaced-003c.html (live test) (source)
    • contain-size-replaced-004.html (live test) (source)
    • contain-size-replaced-005.html (live test) (source)
    • contain-size-replaced-006.html (live test) (source)
    • contain-size-block-001.html (live test) (source)
    • contain-size-block-002.html (live test) (source)
    • contain-size-block-003.html (live test) (source)
    • contain-size-block-004.html (live test) (source)
    • contain-size-button-002.html (live test) (source)
    • contain-size-fieldset-003.html (live test) (source)
    • contain-size-flex-001.html (live test) (source)
    • contain-size-grid-005.html (live test) (source)
    • contain-size-grid-006.html (live test) (source)
    • contain-size-inline-block-001.html (live test) (source)
    • contain-size-inline-block-002.html (live test) (source)
    • contain-size-inline-block-003.html (live test) (source)
    • contain-size-inline-block-004.html (live test) (source)
    • contain-size-inline-flex-001.html (live test) (source)
    • contain-size-multicol-002.html (live test) (source)
    • contain-size-multicol-003.html (live test) (source)
    • contain-size-select-elem-001.html (live test) (source)
    • contain-size-select-elem-002.html (live test) (source)
    • contain-size-select-elem-003.html (live test) (source)
    • contain-size-select-elem-004.html (live test) (source)
    • contain-size-select-elem-005.html (live test) (source)
  2. Laying out a size containment box and its content is conceptually done in two phases:

    Sizing as if empty
    The used width and height of the containment box are determined as if performing a normal layout of the box, except that it is treated as having no content—​not even through pseudo-elements such as ::before, ::after, or ::marker.
    Tests
    • contain-size-021.html (live test) (source)
    • contain-size-023.html (live test) (source)
    • contain-size-025.html (live test) (source)
    • contain-size-027.html (live test) (source)
    • contain-size-061.html (live test) (source)
    • contain-size-062.html (live test) (source)
    • contain-size-063.html (live test) (source)
    • contain-size-borders.html (live test) (source)
    • contain-size-fieldset-001.html (live test) (source)
    • contain-size-fieldset-002.html (live test) (source)
    • contain-size-select-001.html (live test) (source)
    • contain-size-select-002.html (live test) (source)
    • contain-size-scrollbars-001.html (live test) (source)
    • contain-size-scrollbars-002.html (live test) (source)
    • contain-size-scrollbars-003.html (live test) (source)
    • contain-size-scrollbars-004.html (live test) (source)
    • contain-size-button-001.html (live test) (source)
    • contain-size-flexbox-001.html (live test) (source)
    • contain-size-flexbox-002.html (live test) (source)
    • contain-size-grid-001.html (live test) (source)

    Replaced elements must be treated as having a natural width and height of 0 and no natural aspect ratio.

    Note: Size containment only suppresses the natural aspect ratio, so properties like aspect-ratio which affect that preferred aspect ratio directly are honored.

    Tests
    • contain-size-013.html (live test) (source)
    • contain-size-041.html (live test) (source)
    • contain-size-042.html (live test) (source)
    • contain-size-replaced-001.html (live test) (source)
    • contain-size-replaced-002.html (live test) (source)
    • contain-size-replaced-003a.html (live test) (source)
    • contain-size-replaced-003b.html (live test) (source)
    • contain-size-replaced-003c.html (live test) (source)
    • contain-size-replaced-004.html (live test) (source)
    • contain-size-replaced-005.html (live test) (source)
    • replaced-element-023.html (live test) (source)
    • replaced-element-025.html (live test) (source)
    • replaced-element-027.html (live test) (source)

    All CSS properties of the size containment box are taken into account as they would be when performing layout normally. Other specifications may make specific exemptions.

    Tests
    • contain-size-replaced-006.html (live test) (source)

    Note: Even when the element’s sizing properties specify an intrinsic size, this does not necessarily make the element zero-sized: properties set on the element itself continue to be taken into account, which can cause it to be larger.

    Tests
    • contain-size-grid-002.html (live test) (source)
    • contain-size-grid-003.html (live test) (source)
    • contain-size-multicol-001.html (live test) (source)
    • contain-size-multicol-as-flex-item.html (live test) (source)
    Laying out in-place
    The containment box’s content (including any pseudo-elements) must then be laid out into the now fixed-size containment box normally.
    Tests
    • contain-size-064.html (live test) (source)

    Note: Size containment does not suppress baseline alignment. See layout containment for that.

    Tests
    • contain-size-baseline-001.html (live test) (source)
    • contain-size-fieldset-004.html (live test) (source)
    • contain-size-inline-block-001.html (live test) (source)
    • contain-size-inline-block-002.html (live test) (source)
    • contain-size-inline-block-003.html (live test) (source)
    • contain-size-inline-block-004.html (live test) (source)
    • contain-size-inline-flex-001.html (live test) (source)
  3. Size containment boxes are monolithic (See CSS Fragmentation 3 § 4.1 Possible Break Points).

    Tests
    • contain-size-breaks-001.html (live test) (source)
    • contain-size-monolithic-001.html (live test) (source)
    • contain-size-monolithic-002.html (live test) (source)
    • contain-size-multicol-004.html (live test) (source)
Given the following markup and style, the image would be sized to 100px by 100px, as the aspect ratio set by the aspect-ratio property takes effect.
img {
  width: 100px;
  aspect-ratio: 1/1;
  contain: size;
}

<img src="https://www.example.com/300x100.jpg">

If the aspect-ratio property had not been declared, the image would have been 100px by 0px, as its natural aspect ratio is suppressed, and its natural height is treated as 0.

However, giving an element size containment has no effect if any of the following are true:

  • if the element does not generate a principal box (as is the case with display: contents or display: none)

  • if its inner display type is table

    Tests
    • contain-size-012.html (live test) (source)
    • contain-size-012b.html (live test) (source)
  • if its principal box is an internal table box

    Tests
    • contain-size-006.html (live test) (source)
    • contain-size-007.html (live test) (source)
    • contain-size-008.html (live test) (source)
    • contain-size-009.html (live test) (source)
    • contain-size-010.html (live test) (source)
    • contain-size-051.html (live test) (source)
    • contain-size-052.html (live test) (source)
  • if its principal box is an internal ruby box or a non-atomic inline-level box

    Tests
    • contain-size-002.html (live test) (source)
    • contain-size-003.html (live test) (source)
    • contain-size-004.html (live test) (source)
    • contain-size-005.html (live test) (source)
    • contain-size-001.html (live test) (source)

Note: Internal table boxes, which do not include table captions, are excluded, because the table layout algorithm does not allow boxes to become smaller than their inflow content. Sizing a table cell as if it was empty and then laying out its content inside without changing the size is effectively an undefined operation. Manually setting the width or height properties to 0 cannot make it smaller than its content. This concern does not apply to table captions, which are perfectly capable of having a fixed size that is independent of their content.

Tests
  • contain-size-011.html (live test) (source)
  • contain-size-056.html (live test) (source)
  • contain-size-table-caption-001.html (live test) (source)

3.1.1. Possible Size-Containment Optimizations

This section is non-normative.

By itself, size containment does not offer much optimization opportunity. Its primary benefit on its own is that tools which want to lay out the containment box’s contents based on the containment box’s size (such as a JS library implementing the "container query" concept) can do so without fear of "infinite loops", where having a child’s size respond to the size of the containment box causes the containment box’s size to change as well, possibly triggering further changes in how the child sizes itself and possibly thus more changes to the containment box’s size, ad infinitum.

When paired with layout containment, though, possible optimizations that can be enabled include (but are not limited to):

  1. When the style or contents of a descendant of the containment box is changed, calculating what part of the DOM tree is "dirtied" and might need to be re-laid out can stop at the containment box.

  2. When laying out the page, if the containment box is off-screen or obscured, the layout of its contents (i.e. "laying out in-place") can be delayed or done at a lower priority.

3.2. Inline-Size Containment

Giving an element inline-size containment applies size containment to the inline-axis sizing of its principal box. This means the inline-axis intrinsic sizes of the principal box are determined as if the element had no content. However, content continues to impact the box’s block-axis intrinsic sizes as usual, and the box is allowed to fragment normally in the block axis.

Note: In some cases, a box’s block-axis intrinsic sizes can impact layout in the parent formatting context in ways that affect the box’s inline size (e.g. by triggering scrollbars on an ancestor element), creating a dependency of the box’s inline size on its own content. If this changed inline size results in a different block size, that new block size can loop into further impacting the parent formatting context, but not in a way that reverts it to the previously-problematic layout.

For example, if scrollbars were introduced, they are then not removed, even if the consequent block size is small enough to not need them; or if a box’s logical height collides with a lower-placed float and is cleared down to where it also has more available inline space and thus becomes short enough to not have collided, it is then not moved back up to its previous problematic size and position.

Thus, although inline-size containment prevents the box’s content from directly affecting its inline size through its inline-axis intrinsic sizes, its inline size can still indirectly depend on its contents by their effect on its block size.

In general, the relationship between an element’s inline size and it’s block size is unpredictable and non-monotonic, with the block size capable of shifting up and down arbitrarily as the inline size is changed. Infinite cycles are prevented by ensuring that layout does not revert to a previous (known-problematic) state, even if a naive analysis of the constraints would allow for such; in other words, layout always “moves forward”. We believe that current CSS layout specifications incorporate such rules, but to the extent that they don’t, please inform the CSSWG so that these errors can be corrected.

Consider this example, where float placement creates a dependency of block sizes on inline sizes:
<section style="width: 200px; border: solid; display: flow-root;">
  <!-- floated elements that impact the available space -->
  <div style="float: left; width: 50px; height: 80px; background: blue;"></div>
  <div style="float: right; width: 50px; height: 80px; background: blue;"></div>
  <div style="float: left; width: 160px; height: 80px; background: navy;"></div>

  <!-- parent layout, determining context -->
  <article style="border: solid orangered; display: flow-root; min-width: min-content">
    <div style="background: orange; aspect-ratio: 1/1;">
      Article
    </div>
  </article>
</section>
Article

The block layout algorithm will first place the floating boxes, with the first two sitting in the left and right corners of the container, and the third, being too wide to fit between, being pushed below them.

The following article will then be laid out. Because it is display: flow-root, it cannot intersect any floats, and thus must take them into account when figuring out how to size and position itself.

The layout engine first attempts to place the article flush with the top of the container, resulting a 100px width, plenty wide enough to accommodate its min-content size. However, due to the aspect-ratio of its child, this would cause the article to be 100px tall as well, which would intersect the third float 80px below, so this layout opportunity is discarded.

It then attempts to position the article flush with the top of the third float, in the narrow 40px-wide space to its right. However, since the article’s min-width makes it too large to fit in the 40px-wide space beside the third float, it shifts below that one as well, forming a 200px square below all the floated boxes.

Article

If the min-width is removed from the article, or if inline-size containment is added to either the article or header (causing min-width: min-content to resolve to zero), then the article will fit as a 40px square next to the final floated div (possibly with some of its content overflowing).

At this point, the width and height of the article (40px each) would fit back in the first considered space, flush with the top of the container. However, the box is not returned to the previous position, because the layout engine knows already that this position would result in an invalid layout.

Giving an element inline-size containment has no effect if any of the following are true:

  • if the element does not generate a principal box (as is the case with display: contents or display: none)

  • if its inner display type is table

  • if its principal box is an internal table box

  • if its principal box is an internal ruby box or a non-atomic inline-level box

3.3. Layout Containment

Giving an element layout containment makes its principal box a layout containment box and has the following effects:

  1. The layout containment box establishes an independent formatting context.

    Tests
    • contain-layout-ifc-022.html (live test) (source)
    • contain-layout-independent-formatting-context-001.html (live test) (source)
    • contain-layout-independent-formatting-context-002.html (live test) (source)
    • contain-subgrid-001.html (live test) (source)
    • contain-layout-formatting-context-float-001.html (live test) (source)
    • contain-layout-formatting-context-margin-001.html (live test) (source)
  2. If at least one fragmentation container of a fragmentation context has layout containment, or if at least one fragmentation container of a fragmentation context is a descendant of layout containment box and at least one subsequent fragmentation container of the same fragmentation context is not a descendant of that same element with layout containment, then the first layout containment box which is either a fragmentation container itself or is an ancestor of a fragmentation container must “trap” the remainder of the fragmented flow: fragmentation must not continue past the layout containment boundary, and the last fragmentation container within the first layout containment boundary is treated as if it is the last fragmentation container in its fragmentation context.

    If subsequent fragmentation containers in the fragmentation context are only generated when more content remains in the fragmented flow, then they are not generated. If they would exist regardless, they remain part of the fragmentation context, but do not receive any content from the fragmented flow.

    Note: At the time of writing, no stable specification is affected by this point. Only specifications that would enable some (but not all) fragmentation containers of a fragmentation context to be layout-contained (or descendants of a layout contained element) are concerned. This is not the case of [CSS-PAGE-3] nor of [CSS-MULTICOL-1]. This requirement is nonetheless included because several mechanisms that would make this a possibility have been considered (e.g.: [CSS-REGIONS-1], ::nth-fragment(), a hypothetical selector for individual columns of a multicol…), and the guarantees that layout containment is intended to offer would not be realized if such mechanisms did not abide by this rule. [CSS-REGIONS-1] has details over how layout containment affects regions.

    <article>Lorem ipsum…</article>
    <div id=a></div>
    <aside>
      <div id=b></div>
      <div id=c></div>
    </aside>
    <aside>
      <div id=d></div>
      <div id=e></div>
    </aside>
    <div id=f></div>
    
    article {flow-into: foo;}
    #a, #b, #c, #d, #e, #f {flow-from: foo;}
    aside {contain: layout}
    

    In this [CSS-REGIONS-1] example, content can flow from #a to #b, from #b to #c. However as #c is the last fragment container in the first layout containment box it traps all the remaining content, and nothing gets flowed into #d, #e, or #f.

  3. If the computed value of the overflow property is either visible or clip or a combination thereof, any overflow must be treated as ink overflow.

    Tests
    • contain-layout-ink-overflow-013.html (live test) (source)
    • contain-layout-ink-overflow-014.html (live test) (source)
    • contain-layout-ink-overflow-015.html (live test) (source)
    • contain-layout-ink-overflow-016.html (live test) (source)
    • contain-layout-ink-overflow-017.html (live test) (source)
    • contain-layout-ink-overflow-018.html (live test) (source)
    • contain-layout-ink-overflow-019.html (live test) (source)
    • contain-layout-ink-overflow-020.html (live test) (source)
    • contain-layout-overflow-001.html (live test) (source)
    • contain-layout-overflow-002.html (live test) (source)
  4. The layout containment box establishes an absolute positioning containing block and a fixed positioning containing block.

    Tests
    • contain-layout-006.html (live test) (source)
    • contain-layout-007.html (live test) (source)
    • contain-layout-cell-001.html (live test) (source)
    • contain-layout-cell-002.html (live test) (source)
    • contain-layout-021.html (live test) (source)
    • contain-layout-containing-block-absolute-001.html (live test) (source)
    • contain-layout-containing-block-fixed-001.html (live test) (source)
  5. The layout containment box creates a stacking context.

    Tests
    • contain-layout-016.html (live test) (source)
    • contain-layout-017.html (live test) (source)
    • contain-layout-018.html (live test) (source)
    • contain-layout-stacking-context-001.html (live test) (source)
  6. Forced breaks are allowed within layout containment boxes but do not propagate to the parent as otherwise described in CSS Fragmentation 3 § 3.1 Breaks Between Boxes: the break-before and break-after properties.

    Tests
    • contain-layout-breaks-001.html (live test) (source)
    • contain-layout-breaks-002.html (live test) (source)

    Note: This introduces the previously non-existent possibility that forced breaks may occur between a box and its container (See CSS Fragmentation 3 § 4.1 Possible Break Points).

  7. For the purpose of the vertical-align property, or any other property whose effects need to relate the position of the layout containment box’s baseline to something other than its descendants, the containment box is treated as having no baseline.

    Tests
    • contain-layout-baseline-001.html (live test) (source)
    • contain-layout-flexbox-001.html (live test) (source)
    • contain-layout-grid-001.html (live test) (source)
    • contain-layout-baseline-002.html (live test) (source)
    • contain-layout-baseline-003.html (live test) (source)
    • contain-layout-baseline-004.html (live test) (source)
    • contain-layout-baseline-005.html (live test) (source)
    • contain-layout-suppress-baseline-001.html (live test) (source)
    • contain-layout-suppress-baseline-002.html (live test) (source)

However, giving an element layout containment has no effect if any of the following are true:

  • if the element does not generate a principal box (as is the case with display: contents or display: none)

    Tests
    • contain-layout-ignored-cases-no-principal-box-001.html (live test) (source)
    • contain-layout-ignored-cases-no-principal-box-002.html (live test) (source)
    • contain-layout-ignored-cases-no-principal-box-003.html (live test) (source)
  • if its principal box is an internal table box other than table-cell

    Tests
    • contain-layout-009.html (live test) (source)
    • contain-layout-010.html (live test) (source)
    • contain-layout-011.html (live test) (source)
    • contain-layout-012.html (live test) (source)
    • contain-layout-013.html (live test) (source)
    • contain-layout-014.html (live test) (source)
  • if its principal box is an internal ruby box or a non-atomic inline-level box

    Tests
    • contain-layout-002.html (live test) (source)
    • contain-layout-003.html (live test) (source)
    • contain-layout-004.html (live test) (source)
    • contain-layout-005.html (live test) (source)
    • contain-layout-001.html (live test) (source)
    • contain-layout-independent-formatting-context-003.html (live test) (source)
    • contain-layout-ignored-cases-ib-split-001.html (live test) (source)

3.3.1. Possible Layout-Containment Optimizations

This section is non-normative.

Possible optimizations that can be enabled by layout containment include (but are not limited to):

  1. When laying out the page, the contents of separate containment boxes can be laid out in parallel, as they’re guaranteed not to affect each other.

  2. When laying out the page, if the containment box is off-screen or obscured and the layout of the visible parts of the screen do not depend on the size of the containment box (for example, if the containment box is near the end of a block container, and you’re viewing the beginning of the block container), the layout of the containment box' contents can be delayed or done at a lower priority.

    (When paired with size containment, this optimization can be applied more liberally.)

3.4. Style Containment

Giving an element style containment has the following effects:

  1. The counter-increment and counter-set properties must be scoped to the element’s sub-tree and create a new counter.

    Tests
    • contain-style-counters-001.html (live test) (source)
    • contain-style-counters-002.html (live test) (source)
    • contain-style-counters-003.html (live test) (source)
    • contain-style-counters-004.html (live test) (source)
    • contain-style-ol-ordinal-li-container.html (live test) (source)
    • contain-style-ol-ordinal-pseudo-reversed.html (live test) (source)
    • contain-style-ol-ordinal-pseudo.html (live test) (source)
    • contain-style-ol-ordinal-reversed.html (live test) (source)
    • contain-style-ol-ordinal-start-reversed.html (live test) (source)
    • contain-style-ol-ordinal-start.html (live test) (source)
    • contain-style-ol-ordinal.html (live test) (source)
  2. The effects of the content property’s open-quote, close-quote, no-open-quote and no-close-quote must be scoped to the element’s sub-tree.

    Note: This implies that the depth of quote nesting in the subtree is unchanged and starts at the value that its context normally implies, but that changes to the depth of quote nesting by these values inside the subtree do not affect the depth of quote nesting outside the subtree.

    Tests
    • quote-scoping-001.html (live test) (source)
    • quote-scoping-002.html (live test) (source)
    • quote-scoping-003.html (live test) (source)
    • quote-scoping-004.html (live test) (source)
    • quote-scoping-empty-style-boundaries.html (live test) (source)
    • quote-scoping-invalidation-001.html (live test) (source)
    • quote-scoping-invalidation-002.html (live test) (source)
    • quote-scoping-invalidation-003.html (live test) (source)
    • quote-scoping-invalidation-004.html (live test) (source)
Tests
  • contain-style-baseline-001.html (live test) (source)
  • contain-style-breaks-001.html (live test) (source)
  • contain-style-breaks-002.html (live test) (source)
  • contain-style-breaks-003.html (live test) (source)
  • contain-style-breaks-004.html (live test) (source)
  • contain-style-breaks-005.html (live test) (source)

However, giving an element style containment has no effect if any of the following are true:

  • if the element does not generate a principal box (as is the case with display: contents or display: none)

Note: [CSS-REGIONS-1] has normative requirements on how style containment affects regions.

A scoped property has its effects scoped to a particular element or subtree.

  • If scoped to an element, it must act as if the scoping element was the root of the document for the purpose of evaluating the property’s effects: any uses of the property outside the scoping element must have no effect on the uses of the property on or in the scoping element, and vice versa.

    Note: “Scoping to an element” is currently unused. It is defined as an extension point for future specifications to use.

  • If scoped to a sub-tree, it’s the same, except the scoping element itself is counted as "outside" the tree, like the rest of the document, and the effects of the property on that element are unaffected by scoping. When considering the effects of the scoped property on elements inside the subtree, the element at the base of the subtree is treated as if it was the root of the document.

    Tests
    • counter-scoping-001.html (live test) (source)
    • counter-scoping-002.html (live test) (source)
    • counter-scoping-003.html (live test) (source)
    • counter-scoping-004.html (live test) (source)
    • contain-style-ol-ordinal-li-container.html (live test) (source)
    • contain-style-ol-ordinal-pseudo-reversed.html (live test) (source)
    • contain-style-ol-ordinal-pseudo.html (live test) (source)
    • contain-style-ol-ordinal-reversed.html (live test) (source)
    • contain-style-ol-ordinal-start-reversed.html (live test) (source)
    • contain-style-ol-ordinal-start.html (live test) (source)
    • contain-style-ol-ordinal.html (live test) (source)
As counter-increment is scoped to an element’s subtree, the first use of it within the subtree creates a fresh counter, regardless of whether the counter had been used outside the scoping element. Any increments made within the subtree have no effect on counters of the same name outside the scoping element. However, the counter() and counters() value of the content property is not itself scoped, and can refer to counters established outside of the subtree.

For example, the following markup and style:

<div>
  <div style="contain: style;">
    <div></div>
    <div></div>
  </div>
  <div>
    <div></div>
    <div></div>
  </div>
</div>
body {
  counter-reset: foo;
}
div {
  counter-increment: foo;

  /* and to help observe nesting properly */
  margin: .2em;
  padding: .2em;
  background: #0001;
}
div::before {
  content: counters(foo, ".");
}

Will render like:

1
2
2.1
2.2
3
4
5

Here, the style-contained element still interacts with the foo counter normally, incrementing it to 2. Its ::before pseudo-element, which is effectively a child and thus within the containment boundary, can still see that counter normally, and thus will render the string "2".

Later siblings of the style-contained element don’t see anything that goes on within the boundary, so they increment the foo counter to 3 and beyond.

Within the containment, however, the descendant divs aren’t allowed to modify the value of the outside counter, so instead they’ll create a fresh (nested) foo counter when they attempt to increment it.

3.4.1. Possible Style-Containment Optimizations

This section is non-normative.

Possible optimizations that can be enabled by style containment include (but are not limited to):

  1. Whenever a property is changed on a descendant of an element with style containment, calculating what part of the DOM tree is "dirtied" and might need to have its style recalculated can stop at the element with style containment.

3.5. Paint Containment

Giving an element paint containment makes its principal box a paint containment box and has the following effects:

  1. The contents of the element including any ink or scrollable overflow must be clipped to the overflow clip edge of the paint containment box, taking corner clipping into account. This does not include the creation of any mechanism to access or indicate the presence of the clipped content; nor does it inhibit the creation of any such mechanism through other properties, such as overflow, resize, or text-overflow.

    Tests
    • contain-paint-050.html (live test) (source)

    Note: This clipping shape respects overflow-clip-margin, allowing an element with paint containment to still slightly overflow its normal bounds.

    Note: The behavior is described in this paragraph is equivalent to changing overflow-x: visible into overflow-x: clip and overflow-y: visible into overflow-y: clip at used value time, while leaving other values of overflow-x and overflow-y unchanged.

    Tests
    • contain-paint-001.html (live test) (source)
    • contain-paint-004.html (live test) (source)
    • contain-paint-047.html (live test) (source)
    • contain-paint-048.html (live test) (source)
    • contain-paint-cell-001.html (live test) (source)
    • contain-paint-cell-002.html (live test) (source)
    • contain-paint-clip-011.html (live test) (source)
    • contain-paint-clip-012.html (live test) (source)
    • contain-paint-clip-013.html (live test) (source)
    • contain-paint-clip-014.html (live test) (source)
    • contain-paint-clip-015.html (live test) (source)
    • contain-paint-clip-016.html (live test) (source)
    • contain-paint-clip-017.html (live test) (source)
    • contain-paint-clip-018.html (live test) (source)
    • contain-paint-clip-019.html (live test) (source)
    • contain-paint-table-001.html (live test) (source)
    • contain-paint-table-002.html (live test) (source)
    • contain-paint-026.html (live test) (source)
    • contain-paint-049.html (live test) (source)
    • contain-paint-clip-001.html (live test) (source)
    • contain-paint-clip-002.html (live test) (source)
    • contain-paint-clip-003.html (live test) (source)
    • contain-paint-clip-004.html (live test) (source)
    • contain-paint-clip-005.html (live test) (source)
    • contain-paint-clip-006.html (live test) (source)
  2. The paint containment box establishes an absolute positioning containing block and a fixed positioning containing block.

    Tests
    • contain-paint-009.html (live test) (source)
    • contain-paint-010.html (live test) (source)
    • contain-paint-022.html (live test) (source)
    • contain-paint-023.html (live test) (source)
    • contain-paint-024.html (live test) (source)
    • contain-paint-containing-block-absolute-001.html (live test) (source)
    • contain-paint-containing-block-fixed-001.html (live test) (source)
  3. The paint containment box creates a stacking context.

    Tests
    • contain-paint-020.html (live test) (source)
    • contain-paint-021.html (live test) (source)
    • contain-paint-025.html (live test) (source)
    • contain-subgrid-001.html (live test) (source)
    • contain-paint-stacking-context-001a.html (live test) (source)
    • contain-paint-stacking-context-001b.html (live test) (source)
  4. The paint containment box establishes an independent formatting context.

    Tests
    • contain-paint-ifc-011.html (live test) (source)
    • contain-paint-independent-formatting-context-001.html (live test) (source)
    • contain-paint-independent-formatting-context-002.html (live test) (source)
    • contain-paint-formatting-context-float-001.html (live test) (source)
    • contain-paint-formatting-context-margin-001.html (live test) (source)
    • contain-paint-baseline-001.html (live test) (source)

However, giving an element paint containment has no effect if any of the following are true:

  • if the element does not generate a principal box (as is the case with display: contents or display: none)

    Tests
    • contain-paint-ignored-cases-no-principal-box-001.html (live test) (source)
  • if its principal box is an internal table box other than table-cell

    Tests
    • contain-paint-014.html (live test) (source)
    • contain-paint-015.html (live test) (source)
    • contain-paint-016.html (live test) (source)
    • contain-paint-017.html (live test) (source)
    • contain-paint-018.html (live test) (source)
    • contain-paint-019.html (live test) (source)
    • contain-paint-ignored-cases-internal-table-001a.html (live test) (source)
    • contain-paint-ignored-cases-internal-table-001b.html (live test) (source)
  • if its principal box is an internal ruby box or a non-atomic inline-level box

    Tests
    • contain-paint-005.html (live test) (source)
    • contain-paint-006.html (live test) (source)
    • contain-paint-007.html (live test) (source)
    • contain-paint-008.html (live test) (source)
    • contain-paint-ignored-cases-ruby-containing-block-001.html (live test) (source)
    • contain-paint-ignored-cases-ruby-stacking-and-clipping-001.html (live test) (source)
    • contain-paint-002.html (live test) (source)
    • contain-paint-011.html (live test) (source)
    • contain-paint-012.html (live test) (source)
    • contain-paint-independent-formatting-context-003.html (live test) (source)
    • contain-paint-ignored-cases-ib-split-001.html (live test) (source)

3.5.1. Possible Paint-Containment Optimizations

This section is non-normative.

Possible optimizations that can be enabled by paint containment include (but are not limited to):

  1. If the containment box is off-screen or obscured, the UA can usually skip trying to paint its contents, as they’re guaranteed to be off-screen/obscured as well.

    Note: Some paint effects such as the blur() filter from [FILTER-EFFECTS-1] have non local effects. The user agent needs to keep track of these, as it may need to repaint parts of an element with such a filter when its descendents change, even if they have paint containment and could otherwise be skipped.

  2. Unless the clipped content is made accessible via a separate mechanism such as the overflow or resize properties, the UA can reserve "canvas" space for the box exactly the box’s size. (In similar, scrollable, situations, like overflow: hidden, it’s possible to scroll to the currently-clipped content, so UAs often predictively overpaint somewhat so there’s something to see as soon as the scroll happens, rather than a frame later.)

  3. Because they are guaranteed to be stacking contexts, scrolling elements can be painted into a single GPU layer.

4. Suppressing An Element’s Contents Entirely: the content-visibility property

Tests

Tests related to content-visibility which haven't been triaged to any particular point in the spec

  • content-visibility-085.html (live test) (source)
  • content-visibility-086.html (live test) (source)
  • content-visibility-087.html (live test) (source)
  • content-visibility-088.html (live test) (source)
  • content-visibility-089.html (live test) (source)
  • content-visibility-090.html (live test) (source)
  • content-visibility-091.html (live test) (source)
  • content-visibility-092.html (live test) (source)
  • content-visibility-093.html (live test) (source)
  • content-visibility-094.html (live test) (source)
  • content-visibility-095.html (live test) (source)
  • content-visibility-096.html (live test) (source)
  • content-visibility-097.html (live test) (source)
  • content-visibility-098.html (live test) (source)
  • content-visibility-099.html (live test) (source)
  • content-visibility-animation-and-scroll.html (live test) (source)
  • content-visibility-animation-becomes-visible.html (live test) (source)
  • content-visibility-animation-in-auto-subtree.html (live test) (source)
  • content-visibility-animation-with-scroll-timeline-in-auto-subtree.html (live test) (source)
  • content-visibility-animation-with-scroll-timeline-in-hidden-subtree.html (live test) (source)
  • content-visibility-auto-applied-to-th-crash.html (live test) (source)
  • content-visibility-auto-first-observation-immediate.html (live test) (source)
  • content-visibility-auto-nested-scroll.html (live test) (source)
  • content-visibility-auto-nested.html (live test) (source)
  • content-visibility-auto-relevancy-updates.html (live test) (source)
  • content-visibility-auto-text-fragment.html (live test) (source)
  • content-visibility-background-clip-crash.html (live test) (source)
  • content-visibility-interpolation.html (live test) (source)
  • content-visibility-intrinsic-size-001.html (live test) (source)
  • content-visibility-layout-containment-001.html (live test) (source)
  • content-visibility-layout-paint-containment-001.html (live test) (source)
  • content-visibility-on-g.html (live test) (source)
  • content-visibility-on-root-svg.html (live test) (source)
  • content-visibility-paint-containment-001.html (live test) (source)
  • content-visibility-paint-containment-002.html (live test) (source)
  • content-visibility-paint-containment-003.html (live test) (source)
  • content-visibility-selection-crash.html (live test) (source)
  • content-visibility-size-containment-001.html (live test) (source)
  • content-visibility-style-containment-001.html (live test) (source)
  • content-visibility-svg-path.html (live test) (source)
  • content-visibility-svg-rect.html (live test) (source)
  • content-visibility-svg-text.html (live test) (source)
  • content-visibility-vs-scrollIntoView-001.html (live test) (source)
  • content-visibility-vs-scrollIntoView-002.html (live test) (source)
  • content-visibility-vs-scrollIntoView-003.html (live test) (source)
  • content-visibility-web-animation-in-auto-subtree.html (live test) (source)
  • content-visibility-with-float-crash.html (live test) (source)
  • content-visibility-with-popover-top-layer-000.html (live test) (source)
  • content-visibility-with-popover-top-layer-001.html (live test) (source)
  • content-visibility-with-popover-top-layer-002.html (live test) (source)
  • content-visibility-with-popover-top-layer-003.html (live test) (source)
  • content-visibility-with-popover-top-layer-004.html (live test) (source)
  • content-visibility-with-popover-top-layer-005.html (live test) (source)
  • content-visibility-with-popover-top-layer-006.html (live test) (source)
  • content-visibility-with-popover-top-layer-and-auto-descendant.html (live test) (source)
  • content-visibility-with-popover-top-layer-hide-after-addition.html (live test) (source)
  • content-visibility-with-top-layer-007.html (live test) (source)
  • content-visibility-with-top-layer-008.html (live test) (source)
  • content-visibility-with-top-layer-and-auto-descendant.html (live test) (source)
  • content-visibility-with-top-layer-in-auto-subtree-removal.html (live test) (source)

Name: content-visibility
Value: visible | auto | hidden
Initial: visible
Applies to: elements for which size containment can apply
Inherited: no
Percentages: n/a
Computed value: as specified
Canonical order: per grammar
Animation type: see § 4.1 Animating and Interpolating content-visibility
Tests
  • content-visibility-051.html (live test) (source)
  • content-visibility-073.html (live test) (source)
  • inheritance.html (live test) (source)
  • content-visibility-computed.html (live test) (source)
  • content-visibility-invalid.html (live test) (source)
  • content-visibility-valid.html (live test) (source)
  • content-visibility-077.html (live test) (source)
  • content-visibility-resize-observer-no-error.html (live test) (source)

The following tests are crash tests that relate to general usage of this feature but are not particularly tied to any particular normative statement.

  • content-visibility-069.html (live test) (source)
  • content-visibility-auto-selection-crash.html (live test) (source)
  • content-visibility-continuations-crash.html (live test) (source)
  • content-visibility-form-controls-crash.html (live test) (source)
  • content-visibility-hit-test-contents-crash.html (live test) (source)
  • content-visibility-in-svg-000-crash.html (live test) (source)
  • content-visibility-output-crash.html (live test) (source)
  • contentvisibility-nestedslot-crash.html (live test) (source)
  • first-line-and-inline-block.html (live test) (source)
  • detach-locked-slot-children-crash.html (live test) (source)
  • hidden-execcommand-crash.html (live test) (source)
  • hidden-pseudo-element-removed-crash.html (live test) (source)
  • meter-selection-crash.html (live test) (source)
  • slot-content-visibility-1-crash.html (live test) (source)
  • slot-content-visibility-10-crash.html (live test) (source)
  • slot-content-visibility-11-crash.html (live test) (source)
  • slot-content-visibility-12-crash.html (live test) (source)
  • slot-content-visibility-13-crash.html (live test) (source)
  • slot-content-visibility-14-crash.html (live test) (source)
  • slot-content-visibility-15-crash.html (live test) (source)
  • slot-content-visibility-16-crash.html (live test) (source)
  • slot-content-visibility-17-crash.html (live test) (source)
  • slot-content-visibility-18-crash.html (live test) (source)
  • slot-content-visibility-19-crash.html (live test) (source)
  • slot-content-visibility-2-crash.html (live test) (source)
  • slot-content-visibility-20-crash.html (live test) (source)
  • slot-content-visibility-21-crash.html (live test) (source)
  • slot-content-visibility-22-crash.html (live test) (source)
  • slot-content-visibility-3-crash.html (live test) (source)
  • slot-content-visibility-4-crash.html (live test) (source)
  • slot-content-visibility-5-crash.html (live test) (source)
  • slot-content-visibility-6-crash.html (live test) (source)
  • slot-content-visibility-7-crash.html (live test) (source)
  • slot-content-visibility-8-crash.html (live test) (source)
  • slot-content-visibility-9-crash.html (live test) (source)
  • content-visibility-transition-finished-001.html (live test) (source)
  • grid-dynamic.html (live test) (source)
  • display-ruby-text-crash.html (live test) (source)
  • locked-frame-crash.html (live test) (source)
  • touch-action-beside-display-locked-fixedpos-iframe-crash.html (live test) (source)

these should be more accurately dispatched paragraph per paragraph to the relevant points in the specification


    The content-visibility property controls whether or not an element renders its contents at all, along with forcing a strong set of containments, allowing user agents to potentially omit large swathes of layout and rendering work until it becomes needed. It has the following values:

    visible

    No effect. The element’s contents are laid out and rendered as normal.

    Tests
    • content-visibility-002.html (live test) (source)
    • content-visibility-012.html (live test) (source)
    • content-visibility-013.html (live test) (source)
    • content-visibility-014.html (live test) (source)
    • content-visibility-023.html (live test) (source)
    • content-visibility-024.html (live test) (source)
    • content-visibility-025.html (live test) (source)
    • content-visibility-042.html (live test) (source)
    • content-visibility-052.html (live test) (source)
    • content-visibility-057.html (live test) (source)
    • content-visibility-with-top-layer-003.html (live test) (source)
    hidden

    The element skips its contents.

    Tests
    • content-visibility-001.html (live test) (source)
    • content-visibility-003.html (live test) (source)
    • content-visibility-004.html (live test) (source)
    • content-visibility-005.html (live test) (source)
    • content-visibility-006.html (live test) (source)
    • content-visibility-007.html (live test) (source)
    • content-visibility-008.html (live test) (source)
    • content-visibility-009.html (live test) (source)
    • content-visibility-010.html (live test) (source)
    • content-visibility-011.html (live test) (source)
    • content-visibility-015.html (live test) (source)
    • content-visibility-016.html (live test) (source)
    • content-visibility-017.html (live test) (source)
    • content-visibility-018.html (live test) (source)
    • content-visibility-019.sub.https.html (live test) (source)
    • content-visibility-020.html (live test) (source)
    • content-visibility-021.html (live test) (source)
    • content-visibility-022.html (live test) (source)
    • content-visibility-026.html (live test) (source)
    • content-visibility-028.html (live test) (source)
    • content-visibility-029.html (live test) (source)
    • content-visibility-030.html (live test) (source)
    • content-visibility-031.html (live test) (source)
    • content-visibility-032.html (live test) (source)
    • content-visibility-033.sub.https.html (live test) (source)
    • content-visibility-034.html (live test) (source)
    • content-visibility-036.html (live test) (source)
    • content-visibility-037.html (live test) (source)
    • content-visibility-038.html (live test) (source)
    • content-visibility-039.html (live test) (source)
    • content-visibility-040.html (live test) (source)
    • content-visibility-041.html (live test) (source)
    • content-visibility-043.html (live test) (source)
    • content-visibility-044.html (live test) (source)
    • content-visibility-045.html (live test) (source)
    • content-visibility-072.html (live test) (source)
    • content-visibility-078.html (live test) (source)
    • content-visibility-082.html (live test) (source)
    • content-visibility-canvas.html (live test) (source)
    • content-visibility-forced-layout-client-rects.html (live test) (source)
    • content-visibility-img.html (live test) (source)
    • content-visibility-input-image.html (live test) (source)
    • content-visibility-svg.html (live test) (source)
    • content-visibility-video.html (live test) (source)
    • content-visibility-fieldset-size.html (live test) (source)
    • content-visibility-with-top-layer-000.html (live test) (source)
    • content-visibility-with-top-layer-001.html (live test) (source)
    • content-visibility-with-top-layer-002.html (live test) (source)
    • document-element-computed-style.html (live test) (source)
    • element-reassigned-to-skipped-slot.html (live test) (source)
    • element-reassigned-to-slot-in-skipped-subtree.html (live test) (source)
    • scrollIntoView-target-with-contents-hidden.html (live test) (source)
    • scrollIntoView-with-focus-target-with-contents-hidden.html (live test) (source)
    • content-visibility-with-top-layer-hide-after-addition.html (live test) (source)
    • dynamic-change-paint-fully-obscuring-child-001.html (live test) (source)

    The skipped contents must not be accessible to user-agent features, such as find-in-page, tab-order navigation, etc., nor be selectable or focusable.

    Tests
    • content-visibility-035.html (live test) (source)
    • content-visibility-047.html (live test) (source)
    • content-visibility-056.html (live test) (source)
    • content-visibility-060.html (live test) (source)
    • content-visibility-061.html (live test) (source)
    • content-visibility-067.html (live test) (source)
    • content-visibility-083.html (live test) (source)
    • content-visibility-084.html (live test) (source)

    Note: This is similar to giving the contents display: none.

    Tests
    • content-visibility-041.html (live test) (source)
    auto

    Changes the used value of the contain property so as to turn on layout containment, style containment, and paint containment for the element.

    Tests
    • content-visibility-026.html (live test) (source)
    • content-visibility-027.html (live test) (source)
    • content-visibility-074.html (live test) (source)
    • content-visibility-auto-in-iframe.html (live test) (source)
    • content-visibility-auto-intrinsic-width.html 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.