# CSS Containment Module Level 1

Editor’s Draft, 6 September 2022

More details about this document

This version:
  https://drafts.csswg.org/css-contain-1/
Latest published version:
  https://www.w3.org/TR/css-contain-1/
Previous Versions:
  https://www.w3.org/TR/2019/REC-css-contain-1-20191121/
  https://www.w3.org/TR/2019/PR-css-contain-1-20191015/
  https://www.w3.org/TR/2019/CR-css-contain-1-20190430/
  https://www.w3.org/TR/2018/CR-css-contain-1-20181108/
  https://www.w3.org/TR/2018/CR-css-contain-1-20180524/
  https://www.w3.org/TR/2017/CR-css-contain-1-20170808/
  https://www.w3.org/TR/2017/WD-css-contain-1-20170419/
  https://www.w3.org/TR/2017/WD-css-contain-1-20170221/
Implementation Report:
  https://drafts.csswg.org/css-contain-1/implementation-report-2022-09
Test Suites:
  http://test.csswg.org/suites/css-contain-1_dev/nightly-unstable/
  https://wpt.fyi/results/css/css-contain/
Feedback:
  CSSWG Issues Repository
Editors:
  Tab Atkins (Google)
  Florian Rivoal (On behalf of Bloomberg)
Suggest an Edit for this Spec:
  GitHub Editor

Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). W3C liability, trademark and permissive document license rules apply.

## Abstract

This CSS module describes the contain property, which indicates that the element’s subtree is independent of the rest of the page. This enables heavy optimizations by user agents when used well.

CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, etc.

## Status of this document

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

Please send feedback by filing issues in GitHub (preferred), including the spec code “css-contain” in the title, like this: “[css-contain] …summary of comment…”. All issues and comments are archived. Alternately, feedback can be sent to the (archived) public mailing list www-style@w3.org.

This document is governed by the 2 November 2021 W3C Process Document.

Candidate corrections are marked in the document.

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

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

Candidate Correction 1: This makes a minor adjustment to the way the computed value of the contain property is determined: the shortcut values (strict and content), instead of computing to themselves, compute to the corresponding keywords. Given that the effect is identical, this allows implementations not to store the precise syntax through which this was achieved. Also, thanks to the shortest-serialization principle, this makes this unimportant difference non observable via serialization.
This change has tests
Tests for this change have been added to WPT. The results can be viewed at wpt.fyi

Name: | contain
Value: | none | strict | content | [ size || layout || paint ]
Initial: | none
Applies to: | See below
Inherited: | no
Percentages: | n/a
Computed value: | specified keyword(s) the keyword none or one or more of size, layout, 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)
- 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)

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, and thus turns on all forms of containment for the element. In other words, it behaves the same as contain: size layout paint;. .
  Tests
  - contain-strict-001.html (live test) (source)
  - contain-strict-002.html (live test) (source)
  - contain-strict-003.html (live test) (source)
  - contain-flexbox-outline.html (live test) (source)
content
  This value computes to layout paint, and thus turns on all forms of containment except size containment for the element. In other words, it behaves the same as contain: layout paint;. .
  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)

  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-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)
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-button-001.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)
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)

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.

Candidate Correction 3: The CSS Working Group had forgotten to consider the effects of containment on the HTML `html` and `body` elements, particularly in consideration of the fact that for legacy reasons, some properties can propagate outwards from the `body` element. This proposed text addresses this oversight.

> Additionally, when the used value of the contain property on either the HTML `html` or `body` elements is anything other than none, 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.5 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.

This change has tests
Tests to cover these new requirements have been added to WPT. The results of these tests can be seen at the Web-Platform-Tests dashboard:

1. contain-body-bg-001.html
2. contain-body-bg-002.html
3. contain-body-bg-003.html
4. contain-body-bg-004.html
5. contain-body-dir-001.html
6. contain-body-dir-002.html
7. contain-body-dir-003.html
8. contain-body-dir-004.html
9. contain-body-overflow-001.html
10. contain-body-overflow-002.html
11. contain-body-overflow-003.html
12. contain-body-overflow-004.html
13. contain-body-t-o-001.html
14. contain-body-t-o-002.html
15. contain-body-t-o-003.html
16. contain-body-t-o-004.html
17. contain-body-w-m-001.html
18. contain-body-w-m-002.html
19. contain-body-w-m-003.html
20. contain-body-w-m-004.html
21. contain-html-bg-001.html
22. contain-html-bg-002.html
23. contain-html-bg-003.html
24. contain-html-bg-004.html
25. contain-html-dir-001.html
26. contain-html-dir-002.html
27. contain-html-dir-003.html
28. contain-html-dir-004.html
29. contain-html-overflow-001.html
30. contain-html-overflow-002.html
31. contain-html-overflow-003.html
32. contain-html-overflow-004.html
33. contain-html-t-o-001.html
34. contain-html-t-o-002.html
35. contain-html-t-o-003.html
36. contain-html-t-o-004.html
37. contain-html-w-m-001.html
38. contain-html-w-m-002.html
39. contain-html-w-m-003.html
40. contain-html-w-m-004.html

## 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. When calculating the size of size containment box, it must be treated as having no contents.
   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)
   - 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)
   - replaced-element-023.html (live test) (source)
   - replaced-element-025.html (live test) (source)
   - replaced-element-027.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)

   Then, its contents must then be laid out into the containment box's resolved size.

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

   Tests
   - contain-size-baseline-001.html (live test) (source)
   Candidate Correction 2: The way the two normative sentences above are written was somewhat ambiguous, causing implementers to have some doubts about the precise intended effects in certain cases. In order to clarify what is meant without changing the intended behavior, The CSSWG suggest replacing this first item in the list with the following two (the existing notes remain the same):

   > 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-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)

   This change has tests
   All statements in this more detailed write-up have tests in WPT. The results of these tests can be seen at the Web-Platform-Tests dashboard:
   1. contain-size-013.html
   2. contain-size-021.html
   3. contain-size-023.html
   4. contain-size-025.html
   5. contain-size-027.html
   6. contain-size-041.html
   7. contain-size-042.html
   8. contain-size-061.html
   9. contain-size-062.html
   10. contain-size-063.html
   11. contain-size-064.html
   12. contain-size-borders.html
   13. contain-size-button-001.html
   14. contain-size-fieldset-001.html
   15. contain-size-fieldset-002.html
   16. contain-size-flexbox-001.html
   17. contain-size-flexbox-002.html
   18. contain-size-grid-001.html
   19. contain-size-grid-002.html
   20. contain-size-grid-003.html
   21. contain-size-multicol-001.html
   22. contain-size-multicol-as-flex-item.html
   23. contain-size-replaced-001.html
   24. contain-size-replaced-002.html
   25. contain-size-replaced-003a.html
   26. contain-size-replaced-003b.html
   27. contain-size-replaced-003c.html
   28. contain-size-replaced-004.html
   29. contain-size-replaced-005.html
   30. contain-size-replaced-006.html
   31. contain-size-scrollbars-001.html
   32. contain-size-scrollbars-002.html
   33. contain-size-scrollbars-003.html
   34. contain-size-scrollbars-004.html
   35. contain-size-select-001.html
   36. contain-size-select-002.html
   37. replaced-element-023.html
   38. replaced-element-025.html
   39. replaced-element-027.html
   40. contain-size-block-001.html
   41. contain-size-block-002.html
   42. contain-size-block-003.html
   43. contain-size-block-004.html
   44. contain-size-button-002.html
   45. contain-size-fieldset-003.html
   46. contain-size-flex-001.html
   47. contain-size-grid-005.html
   48. contain-size-inline-block-001.html
   49. contain-size-inline-block-002.html
   50. contain-size-inline-block-003.html
   51. contain-size-inline-block-004.html
   52. contain-size-inline-flex-001.html
   53. contain-size-multicol-002.html
   54. contain-size-multicol-003.html
   55. contain-size-select-elem-001.html
   56. contain-size-select-elem-002.html
   57. contain-size-select-elem-003.html
   58. contain-size-select-elem-004.html
   59. contain-size-select-elem-005.html
   60. contain-size-fieldset-004.html
   61. contain-size-inline-block-001.html
   62. contain-size-inline-block-002.html
   63. contain-size-inline-block-003.html
   64. contain-size-inline-block-004.html
   65. contain-size-inline-flex-001.html

   Also, note the insertion of a parenthetical at the very end of this section, referencing part of this clarified text.

2. 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. 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-button-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.2.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.3. 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 padding 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.

   Note: The next level of this specification [CSS-CONTAIN-2] refines this effect to apply to the overflow clip edge rather than the padding edge, in order to take the new overflow-clip-margin property into account. For implementations that do not support overflow-clip-margin, the effect is identical.

   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.3.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, resize, or text-overflow 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. Privacy Considerations

There are no known privacy impacts of the features in this specification.

## 5. Security Considerations

There are no known security impacts of the features in this specification.

Like any other CSS specification, it affects the rendering of the document, but does not introduce any special ability to present content in a misleading way that was not previously available through other CSS modules and that isn’t inherent to the act of formatting the document.

## Appendix A. Changes

This appendix is informative.

### Changes from the Recommendation of 22 December 2020

A full Disposition of Comments is available.

- Marked as Candidate Correction 3: Define the effects of containment on outwards propagation of properties from the HTML `body` element.
- Editorial tweaks:
  - Note that paint effects with non-local effects can limit certain optimization opportunities.
  - Add subsection headings for the possible optimizations
  - List cases where various types of containment do not apply at the end rather than the start of each section, to start with the general behavior and go into exceptions later.

### Changes from the Recommendation of 21 November 2019

A full Disposition of Comments is available.

- Marked as Candidate Correction 1: Changed how the computed values of the contain property are determined for the shortcut values.
- Marked as Candidate Correction 2: Rewrote much of the § 3.1 Size Containment section in more detail to clarify ambiguities about how it is meant to work, and improve the general legibility. The intended behavior is unaltered.
- Marked as Candidate Correction 3: Define the effects of containment on outwards propagation of properties from the HTML `body` element.
- Editorial tweaks:
  - Added an example and clarified a note in the § 3.1 Size Containment section
  - phrasing improvement in § 3.3 Paint Containment to use established terminology rather than ad-hoc wording with the same intended meaning
  - phrasing improvement in note in § 3.3 Paint Containment
  - terminology change: replace "containing box" with "containment box"

### Changes from the Candidate Recommendation of 30 April 2019

Full Dispositions of Comments since CR and since PR is available.

- Editorial tweaks
- Drop the at-risk “style containment” feature from this specification, move it Level 2
  Tests
  - contain-strict-011.html (live test) (source)
  - contain-content-011.html (live test) (source)
  - 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)
  - counter-scoping-001.html (live test) (source)
  - counter-scoping-002.html (live test) (source)
  - counter-scoping-003.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)

### Changes from the Candidate Recommendation of 08 November 2018

A full Disposition of Comments is available.

- Exclude style containment from contain: strict and contain: content, and mark it at risk.

### Changes from the Candidate Recommendation of 24 May 2018

A full Disposition of Comments is available.

- Clarify that layout containment causes overflow to be treated as ink overflow only when visible (or clip)

- Layout containment suppresses baseline alignment, but size containment does not

- Layout containment causes the element to establish a new stacking context

- Size containment does not apply to tables

- Clarify that the columns and grid properties affect the size of size-contained elements

- Change the animation type of the contain property from discrete to not animatable

- Define the effect of containment on SVG elements

- Editorial improvements

- A comprehensive test suite for the full specification was developed, see http://test.csswg.org/harness/review/css-contain-1_dev

### Changes from the Candidate Recommendation of 8 August 2017

A full Disposition of Comments is available.

- Clarify to which box paint containment clips (see tests).
- Move the interaction between containment and the `bookmark-*` and `string-set` properties to [CSS-CONTENT-3] (additional tests not needed, no change in behavior).
- Remove the effects of style containment on the "break-*" properties (see tests).
- Move the description of the effects of containment on regions from this specification to [CSS-REGIONS-1] (additional tests not needed, no change in behavior).
- Clarify the effects of style scoping on counter-set and counter-increment (see tests)
- Size layout and paint containment don’t apply to internal ruby elements (see tests)
- Layout, Paint, and size containments do not apply to non-atomic inlines (see tests here and one more test here)
- Align paint containment’s behavior with overflow:clip (see test)
- Elements with size containment are monolithic (see test)
- Forced breaks area allowed in elements with layout containments, but do not propagate (see tests)
- Clarify the effects of scoping to a subtree (see test)
- Clarify the effects of scoping on open/close quotes (see tests)
- Editorial clarification: replace "Becoming a formatting context" (aka "Becoming a formatting context root") with "Establish a FC" (additional tests not needed, no change in behavior)

### Changes from the Working Draft of 19 April 2017

A Disposition of Comments covering this draft and the previous one together is available.

- Clarify the interaction with display: contents
- Clarify how containment works on table parts
- Move the interaction between containment and fragmentation of overflow from this specification to CSS-OVERFLOW-4

### Changes from the First Public Working Draft of 21 February 2017

- Specify handling of replaced elements for size containment
- Layout containment makes element act as a containing block for absolutely positioned and fixed positioned descendants.

Tests

WPT tests not applicable to this specification, as they related to later levels.

- content-visibility-001.html (live test) (source)
- content-visibility-002.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-012.html (live test) (source)
- content-visibility-013.html (live test) (source)
- content-visibility-014.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-023.html (live test) (source)
- content-visibility-024.html (live test) (source)
- content-visibility-025.html (live test) (source)
- content-visibility-026.html (live test) (source)
- content-visibility-027.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-035.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-042.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-046.html (live test) (source)
- content-visibility-047.html (live test) (source)
- content-visibility-048.html (live test) (source)
- content-visibility-049.html (live test) (source)
- content-visibility-050.html (live test) (source)
- content-visibility-051.html (live test) (source)
- content-visibility-052.html (live test) (source)
- content-visibility-053.html (live test) (source)
- content-visibility-054.html (live test) (source)
- content-visibility-055.html (live test) (source)
- content-visibility-056.html (live test) (source)
- content-visibility-057.html (live test) (source)
- content-visibility-058.html (live test) (source)
- content-visibility-060.html (live test) (source)
- content-visibility-061.html (live test) (source)
- content-visibility-062.html (live test) (source)
- content-visibility-063.html (live test) (source)
- content-visibility-064.html (live test) (source)
- content-visibility-065.html (live test) (source)
- content-visibility-066.html (live test) (source)
- content-visibility-067.html (live test) (source)
- content-visibility-068.html (live test) (source)
- content-visibility-069.html (live test) (source)
- content-visibility-070.html (live test) (source)
- content-visibility-071.html (live test) (source)
- content-visibility-072.html (live test) (source)
- content-visibility-073.html (live test) (source)
- content-visibility-074.html (live test) (source)
- content-visibility-075.html (live test) (source)
- content-visibility-076.html (live test) (source)
- content-visibility-077.html (live test) (source)
- content-visibility-078.html (live test) (source)
- content-visibility-079.html (live test) (source)
- content-visibility-form-controls-crash.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)
- animation-container-size.html (live test) (source)
- animation-container-type-dynamic.html (live test) (source)
- animation-nested-animation.html (live test) (source)
- animation-nested-transition.html (live test) (source)
- aspect-ratio-feature-evaluation.html (live test) (source)
- at-container-parsing.html (live test) (source)
- at-container-serialization.html (live test) (source)
- at-container-style-serialization.html (live test) (source)
- auto-scrollbars.html (live test) (source)
- backdrop-invalidation.html (live test) (source)
- calc-evaluation.html (live test) (source)
- canvas-as-container-001.html (live test) (source)
- canvas-as-container-002.html (live test) (source)
- canvas-as-container-003.html (live test) (source)
- canvas-as-container-004.html (live test) (source)
- canvas-as-container-005.html (live test) (source)
- canvas-as-container-006.html (live test) (source)
- change-display-in-container.html (live test) (source)
- chrome-legacy-skip-recalc.html (live test) (source)
- column-spanner-in-container.html (live test) (source)
- conditional-container-status.html (live test) (source)
- container-computed.html (live test) (source)
- container-for-cue.html (live test) (source)
- container-for-shadow-dom.html (live test) (source)
- container-inheritance.html (live test) (source)
- container-inner-at-rules.html (live test) (source)
- container-longhand-animation-type.html (live test) (source)
- container-name-computed.html (live test) (source)
- container-name-invalidation.html (live test) (source)
- container-name-parsing.html (live test) (source)
- container-nested.html (live test) (source)
- container-parsing.html (live test) (source)
- container-selection.html (live test) (source)
- container-size-invalidation-after-load.html (live test) (source)
- container-size-invalidation.html (live test) (source)
- container-size-nested-invalidation.html (live test) (source)
- container-type-computed.html (live test) (source)
- container-type-containment.html (live test) (source)
- container-type-invalidation.html (live test) (source)
- container-type-layout-invalidation.html (live test) (source)
- container-type-parsing.html (live test) (source)
- container-units-animation.html (live test) (source)
- container-units-basic.html (live test) (source)
- container-units-computational-independence.html (live test) (source)
- container-units-gradient-invalidation.html (live test) (source)
- container-units-gradient.html (live test) (source)
- container-units-in-at-container-dynamic.html (live test) (source)
- container-units-in-at-container-fallback.html (live test) (source)
- container-units-in-at-container.html (live test) (source)
- container-units-invalidation.html (live test) (source)
- container-units-media-queries.html (live test) (source)
- container-units-selection.html (live test) (source)
- container-units-shadow.html (live test) (source)
- container-units-small-viewport-fallback.html (live test) (source)
- container-units-svglength.html (live test) (source)
- container-units-typed-om.html (live test) (source)
- counters-flex-circular.html (live test) (source)
- counters-in-container-dynamic.html (live test) (source)
- counters-in-container.html (live test) (source)
- br-crash.html (live test) (source)
- canvas-as-container-crash.html (live test) (source)
- chrome-bug-1289718-000-crash.html (live test) (source)
- chrome-bug-1289718-001-crash.html (live test) (source)
- chrome-bug-1346969-crash.html (live test) (source)
- chrome-quotes-crash.html (live test) (source)
- chrome-remove-insert-evaluator-crash.html (live test) (source)
- columns-in-table-001-crash.html (live test) (source)
- columns-in-table-002-crash.html (live test) (source)
- container-in-canvas-crash.html (live test) (source)
- container-type-change-chrome-legacy-crash.html (live test) (source)
- flex-in-columns-000-crash.html (live test) (source)
- flex-in-columns-001-crash.html (live test) (source)
- flex-in-columns-002-crash.html (live test) (source)
- flex-in-columns-003-crash.html (live test) (source)
- focus-inside-content-visibility-crash.html (live test) (source)
- force-sibling-style-crash.html (live test) (source)
- grid-in-columns-000-crash.html (live test) (source)
- grid-in-columns-001-crash.html (live test) (source)
- grid-in-columns-002-crash.html (live test) (source)
- grid-in-columns-003-crash.html (live test) (source)
- inline-multicol-inside-container-crash.html (live test) (source)
- inline-with-columns-000-crash.html (live test) (source)
- inline-with-columns-001-crash.html (live test) (source)
- input-column-group-container-crash.html (live test) (source)
- input-placeholder-inline-size-crash.html (live test) (source)
- marker-gcs-after-disconnect-crash.html (live test) (source)
- math-block-container-child-crash.html (live test) (source)
- orthogonal-replaced-crash.html (live test) (source)
- pseudo-container-crash.html (live test) (source)
- svg-layout-root-crash.html (live test) (source)
- svg-text-crash.html (live test) (source)
- table-in-columns-000-crash.html (live test) (source)
- table-in-columns-001-crash.html (live test) (source)
- table-in-columns-002-crash.html (live test) (source)
- table-in-columns-003-crash.html (live test) (source)
- table-in-columns-004-crash.html (live test) (source)
- table-in-columns-005-crash.html (live test) (source)
- custom-layout-container-001.https.html (live test) (source)
- deep-nested-inline-size-containers.html (live test) (source)
- display-contents.html (live test) (source)
- display-in-container.html (live test) (source)
- display-none.html (live test) (source)
- fieldset-legend-change.html (live test) (source)
- font-relative-calc-dynamic.html (live test) (source)
- font-relative-units-dynamic.html (live test) (source)
- font-relative-units.html (live test) (source)
- fragmented-container-001.html (live test) (source)
- get-animations.html (live test) (source)
- grid-container.html (live test) (source)
- grid-item-container.html (live test) (source)
- idlharness.html (live test) (source)
- iframe-in-container-invalidation.html (live test) (source)
- iframe-invalidation.html (live test) (source)
- ineligible-containment.html (live test) (source)
- inline-size-and-min-width.html (live test) (source)
- inline-size-bfc-floats.html (live test) (source)
- inline-size-containment-vertical-rl.html (live test) (source)
- inline-size-containment.html (live test) (source)
- inner-first-line-non-matching.html (live test) (source)
- layout-dependent-focus.html (live test) (source)
- multicol-container-001.html (live test) (source)
- multicol-inside-container.html (live test) (source)
- never-match-container.html (live test) (source)
- orthogonal-wm-container-query.html (live test) (source)
- percentage-padding-orthogonal.html (live test) (source)
- pseudo-elements-001.html (live test) (source)
- pseudo-elements-002.html (live test) (source)
- pseudo-elements-003.html (live test) (source)
- pseudo-elements-004.html (live test) (source)
- query-content-box.html (live test) (source)
- query-evaluation.html (live test) (source)
- reattach-container-with-dirty-child.html (live test) (source)
- resize-while-content-visibility-hidden.html (live test) (source)
- sibling-layout-dependency.html (live test) (source)
- size-container-no-principal-box.html (live test) (source)
- size-feature-evaluation.html (live test) (source)
- style-change-in-container.html (live test) (source)
- svg-foreignobject-child-container.html (live test) (source)
- svg-foreignobject-no-size-container.html (live test) (source)
- svg-g-no-size-container.html (live test) (source)
- svg-root-size-container.html (live test) (source)
- table-inside-container-changing-display.html (live test) (source)
- top-layer-dialog-backdrop.html (live test) (source)
- top-layer-dialog-container.html (live test) (source)
- top-layer-dialog.html (live test) (source)
- top-layer-nested-dialog.html (live test) (source)
- transition-scrollbars.html (live test) (source)
- transition-style-change-event.html (live test) (source)
- unsupported-axis.html (live test) (source)
- viewport-units-dynamic.html (live test) (source)
- viewport-units.html (live test) (source)
- whitespace-update-after-removal.html (live test) (source)
- animation-display-lock.html (live test) (source)
- content-visibility-080.html (live test) (source)
- content-visibility-081.html (live test) (source)
- content-visibility-082.html (live test) (source)
- content-visibility-083.html (live test) (source)
- content-visibility-084.html (live test) (source)
- content-visibility-auto-state-changed.html (live test) (source)
- content-visibility-canvas.html (live test) (source)
- content-visibility-continuations-crash.html (live test) (source)
- content-visibility-hit-test-contents-crash.html (live test) (source)
- content-visibility-img.html (live test) (source)
- content-visibility-in-svg-000-crash.html (live test) (source)
- content-visibility-input-image.html (live test) (source)
- content-visibility-output-crash.html (live test) (source)
- content-visibility-svg.html (live test) (source)
- content-visibility-video.html (live test) (source)
- contentvisibility-nestedslot-crash.html (live test) (source)
- detach-locked-slot-children-crash.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)
- hidden-execcommand-crash.html (live test) (source)
- hidden-pseudo-element-removed-crash.html (live test) (source)
- meter-selection-crash.html (live test) (source)
- scrollIntoView-target-with-contents-hidden.html (live test) (source)
- scrollIntoView-with-focus-target-with-contents-hidden.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)
- 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)
- container-inside-multicol-with-table.html (live test) (source)
- container-size-shadow-invalidation.html (live test) (source)
- custom-property-style-queries.html (live test) (source)
- custom-property-style-query-change.html (live test) (source)
- content-visibility-forced-layout-client-rects.html (live test) (source)
- quote-scoping-empty-style-boundaries.html (live test) (source)

## Conformance

### Document conventions

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Examples in this specification are introduced with the words “for example” or are set apart from the normative text with `class="example"`, like this:

This is an example of an informative example.

Informative notes begin with the word “Note” and are set apart from the normative text with `class="note"`, like this:

Note, this is an informative note.

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

Tests

Tests relating to the content of this specification may be documented in “Tests” blocks like this one. Any such block is non-normative.

### Conformance classes

Conformance to this specification is defined for three conformance classes:

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

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

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

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

### Partial implementations

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

#### Implementations of Unstable and Proprietary Features

To avoid clashes with future stable CSS features, the CSSWG recommends following best practices for the implementation of unstable features and proprietary extensions to CSS.

### Non-experimental implementations

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

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

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

## Index

### Terms defined by this specification

- contain, in § 2
- containment, in § 3
- content, in § 2
- Laying out in-place, in § 3.1
- layout, in § 2
- layout containment, in § 3.2
- layout containment box, in § 3.2
- none, in § 2
- paint, in § 2
- paint containment, in § 3.3
- paint containment box, in § 3.3
- size, in § 2
- size containment, in § 3.1
- size containment box, in § 3.1
- Sizing as if empty, in § 3.1
- strict, in § 2

https://drafts.csswg.org/css-backgrounds-3/#propdef-background Referenced in:

- 2. Strong Containment: the contain property

https://drafts.csswg.org/css-backgrounds-3/#canvas-background Referenced in:

- 2. Strong Containment: the contain property (2)

https://drafts.csswg.org/css-backgrounds-3/#corner-clipping Referenced in:

- 3.3. Paint Containment

https://drafts.csswg.org/css-break-3/#forced-break Referenced in:

- 3.2. Layout Containment (2)

https://drafts.csswg.org/css-break-3/#fragmentation Referenced in:

- 3.2. Layout Containment

https://drafts.csswg.org/css-break-3/#fragmentation-container Referenced in:

- 3.2. Layout Containment (2) (3) (4) (5) (6) (7) (8)

https://drafts.csswg.org/css-break-3/#fragmentation-context Referenced in:

- 3.2. Layout Containment (2) (3) (4) (5) (6)

https://drafts.csswg.org/css-break-3/#fragmented-flow Referenced in:

- 3.2. Layout Containment (2) (3)

https://drafts.csswg.org/css-break-3/#monolithic Referenced in:

- 3.1. Size Containment

https://drafts.csswg.org/css-cascade-5/#used-value Referenced in:

- 2. Strong Containment: the contain property
- 3.1. Size Containment

https://drafts.csswg.org/css-contain-2/#style-containment Referenced in:

- Changes from the Candidate Recommendation of 08 November 2018

https://drafts.csswg.org/css-display-3/#atomic-inline Referenced in:

- 3.1. Size Containment
- 3.2. Layout Containment
- 3.3. Paint Containment

https://drafts.csswg.org/css-display-3/#propdef-display Referenced in:

- 3.1. Size Containment (2)
- 3.2. Layout Containment (2)
- 3.3. Paint Containment (2)

https://drafts.csswg.org/css-display-3/#establish-an-independent-formatting-context Referenced in:

- 3.2. Layout Containment
- 3.3. Paint Containment

https://drafts.csswg.org/css-display-3/#initial-containing-block Referenced in:

- 2. Strong Containment: the contain property (2)

https://drafts.csswg.org/css-display-3/#inline-level Referenced in:

- 3.1. Size Containment
- 3.2. Layout Containment
- 3.3. Paint Containment

https://drafts.csswg.org/css-display-3/#inner-display-type Referenced in:

- 3.1. Size Containment

https://drafts.csswg.org/css-display-3/#internal-ruby-box Referenced in:

- 3.1. Size Containment
- 3.2. Layout Containment
- 3.3. Paint Containment

https://drafts.csswg.org/css-display-3/#internal-table-box Referenced in:

- 3.1. Size Containment
- 3.2. Layout Containment
- 3.3. Paint Containment

https://drafts.csswg.org/css-display-3/#principal-box Referenced in:

- 3.1. Size Containment (2) (3) (4)
- 3.2. Layout Containment (2) (3) (4)
- 3.3. Paint Containment (2) (3) (4)

https://drafts.csswg.org/css-display-3/#replaced-element Referenced in:

- 3.1. Size Containment

https://drafts.csswg.org/css-display-3/#valdef-display-table Referenced in:

- 3.1. Size Containment

https://drafts.csswg.org/css-display-3/#valdef-display-table-cell Referenced in:

- 3.2. Layout Containment
- 3.3. Paint Containment

https://drafts.csswg.org/css-grid-2/#grid-track Referenced in:

- 3.1. Size Containment

https://drafts.csswg.org/css-images-3/#natural-aspect-ratio Referenced in:

- 3.1. Size Containment (2) (3)

https://drafts.csswg.org/css-images-3/#natural-dimensions Referenced in:

- 3.1. Size Containment

https://drafts.csswg.org/css-images-3/#natural-height Referenced in:

- 3.1. Size Containment

https://drafts.csswg.org/css-overflow-3/#valdef-overflow-clip Referenced in:

- 3.2. Layout Containment

https://drafts.csswg.org/css-overflow-3/#ink-overflow Referenced in:

- 3.2. Layout Containment
- 3.3. Paint Containment

https://drafts.csswg.org/css-overflow-3/#propdef-overflow Referenced in:

- 2. Strong Containment: the contain property
- 3.2. Layout Containment
- 3.3. Paint Containment
- 3.3.1. Possible Paint-Containment Optimizations (2)

https://drafts.csswg.org/css-overflow-3/#overflow-clip-edge Referenced in:

- 3.3. Paint Containment

https://drafts.csswg.org/css-overflow-3/#propdef-overflow-clip-margin Referenced in:

- 3.3. Paint Containment (2)

https://drafts.csswg.org/css-overflow-3/#propdef-overflow-x Referenced in:

- 3.3. Paint Containment (2) (3)

https://drafts.csswg.org/css-overflow-3/#propdef-overflow-y Referenced in:

- 3.3. Paint Containment (2) (3)

https://drafts.csswg.org/css-overflow-3/#scrollable-overflow Referenced in:

- 3.3. Paint Containment

https://drafts.csswg.org/css-overflow-3/#valdef-overflow-visible Referenced in:

- 3.2. Layout Containment

https://drafts.csswg.org/css-overflow-4/#selectordef-nth-fragment Referenced in:

- 3.2. Layout Containment

https://drafts.csswg.org/css-position-3/#absolute-positioning-containing-block Referenced in:

- 3.2. Layout Containment
- 3.3. Paint Containment

https://drafts.csswg.org/css-position-3/#fixed-positioning-containing-block Referenced in:

- 3.2. Layout Containment
- 3.3. Paint Containment

https://drafts.csswg.org/css-pseudo-4/#selectordef-after Referenced in:

- 3.1. Size Containment

https://drafts.csswg.org/css-pseudo-4/#selectordef-before Referenced in:

- 3.1. Size Containment

https://drafts.csswg.org/css-pseudo-4/#selectordef-marker Referenced in:

- 3.1. Size Containment

https://drafts.csswg.org/css-sizing-3/#fit-content-size Referenced in:

- 3.1. Size Containment

https://drafts.csswg.org/css-sizing-3/#propdef-height Referenced in:

- 3.1. Size Containment (2)

https://drafts.csswg.org/css-sizing-3/#intrinsic-size Referenced in:

- 3.1. Size Containment

https://drafts.csswg.org/css-sizing-3/#valdef-width-max-content Referenced in:

- 3.1. Size Containment

https://drafts.csswg.org/css-sizing-3/#valdef-width-min-content Referenced in:

- 3.1. Size Containment

https://drafts.csswg.org/css-sizing-3/#sizing-property Referenced in:

- 3.1. Size Containment (2)

https://drafts.csswg.org/css-sizing-3/#propdef-width Referenced in:

- 3.1. Size Containment (2)

https://drafts.csswg.org/css-sizing-4/#propdef-aspect-ratio Referenced in:

- 3.1. Size Containment (2) (3)

https://drafts.csswg.org/css-sizing-4/#preferred-aspect-ratio Referenced in:

- 3.1. Size Containment

https://drafts.csswg.org/css-ui-3/#propdef-text-overflow Referenced in:

- 3.3. Paint Containment
- 3.3.1. Possible Paint-Containment Optimizations

https://drafts.csswg.org/css-ui-4/#propdef-resize Referenced in:

- 3.3. Paint Containment
- 3.3.1. Possible Paint-Containment Optimizations

https://drafts.csswg.org/css-values-4/#css-wide-keywords Referenced in:

- 1.1. Value Definitions

https://drafts.csswg.org/css-values-4/#comb-one Referenced in:

- 2. Strong Containment: the contain property (2) (3)

https://drafts.csswg.org/css-values-4/#comb-any Referenced in:

- 2. Strong Containment: the contain property (2)

https://drafts.csswg.org/css-writing-modes-3/#propdef-direction Referenced in:

- 2. Strong Containment: the contain property

https://drafts.csswg.org/css-writing-modes-4/#propdef-text-orientation Referenced in:

- 2. Strong Containment: the contain property

https://drafts.csswg.org/css-writing-modes-4/#propdef-writing-mode Referenced in:

- 2. Strong Containment: the contain property

https://www.w3.org/TR/CSS2/box.html#padding-edge Referenced in:

- 3.3. Paint Containment (2)

https://drafts.csswg.org/css2/#stacking-context Referenced in:

- 3.2. Layout Containment
- 3.3. Paint Containment

https://www.w3.org/TR/CSS2/visudet.html#propdef-vertical-align Referenced in:

- 3.2. Layout Containment

https://drafts.csswg.org/filter-effects-1/#funcdef-filter-blur Referenced in:

- 3.3.1. Possible Paint-Containment Optimizations

https://html.spec.whatwg.org/multipage/sections.html#the-body-element Referenced in:

- 2. Strong Containment: the contain property (2) (3) (4)
- Changes from the Recommendation of 22 December 2020
- Changes from the Recommendation of 21 November 2019

https://html.spec.whatwg.org/multipage/semantics.html#the-html-element Referenced in:

- 2. Strong Containment: the contain property (2) (3)

https://svgwg.org/svg2-draft/struct.html#elementdef-svg Referenced in:

- 2. Strong Containment: the contain property

### Terms defined by reference

- [css-backgrounds-3] defines the following terms:
  - background
  - canvas background
  - corner clipping
- [css-break-3] defines the following terms:
  - forced break
  - fragmentation
  - fragmentation container
  - fragmentation context
  - fragmented flow
  - monolithic
- [css-cascade-5] defines the following terms:
  - used value
- [CSS-CONTAIN-2] defines the following terms:
  - style containment
- [css-display-3] defines the following terms:
  - atomic inline
  - display
  - establishes an independent formatting context
  - initial containing block
  - inline-level
  - inner display type
  - internal ruby box
  - internal table box
  - principal box
  - replaced element
  - table
  - table-cell
- [css-grid-2] defines the following terms:
  - grid track
- [css-images-3] defines the following terms:
  - natural aspect ratio
  - natural dimension
  - natural height
- [css-overflow-3] defines the following terms:
  - clip
  - ink overflow
  - overflow
  - overflow clip edge
  - overflow-clip-margin
  - overflow-x
  - overflow-y
  - scrollable overflow
  - visible
- [css-overflow-4] defines the following terms:
  - ::nth-fragment()
- [css-position-3] defines the following terms:
  - absolute positioning containing block
  - fixed positioning containing block
- [css-pseudo-4] defines the following terms:
  - ::after
  - ::before
  - ::marker
- [css-sizing-3] defines the following terms:
  - fit-content size
  - height
  - intrinsic size
  - max-content
  - min-content
  - sizing property
  - width
- [css-sizing-4] defines the following terms:
  - aspect-ratio
  - preferred aspect ratio
- [css-ui-3] defines the following terms:
  - text-overflow
- [css-ui-4] defines the following terms:
  - resize
- [css-values-4] defines the following terms:
  - css-wide keywords
  - |
  - ||
- [css-writing-modes-3] defines the following terms:
  - direction
- [css-writing-modes-4] defines the following terms:
  - text-orientation
  - writing-mode
- [CSS2] defines the following terms:
  - padding edge
  - stacking context
  - vertical-align
- [FILTER-EFFECTS-1] defines the following terms:
  - blur()
- [HTML] defines the following terms:
  - body
  - html
- [SVG2] defines the following terms:
  - svg

## References

### Normative References

[CSS-BACKGROUNDS-3]
  Bert Bos; Elika Etemad; Brad Kemper. CSS Backgrounds and Borders Module Level 3. 26 July 2021. CR. URL: https://www.w3.org/TR/css-backgrounds-3/
[CSS-BREAK-3]
  Rossen Atanassov; Elika Etemad. CSS Fragmentation Module Level 3. 4 December 2018. CR. URL: https://www.w3.org/TR/css-break-3/
[CSS-CASCADE-5]
  Elika Etemad; Miriam Suzanne; Tab Atkins Jr.. CSS Cascading and Inheritance Level 5. 13 January 2022. CR. URL: https://www.w3.org/TR/css-cascade-5/
[CSS-CONTAIN-2]
  Tab Atkins Jr.; Florian Rivoal; Vladimir Levin. CSS Containment Module Level 2. 16 December 2020. WD. URL: https://www.w3.org/TR/css-contain-2/
[CSS-DISPLAY-3]
  Tab Atkins Jr.; Elika Etemad. CSS Display Module Level 3. 3 September 2021. CR. URL: https://www.w3.org/TR/css-display-3/
[CSS-IMAGES-3]
  Tab Atkins Jr.; Elika Etemad; Lea Verou. CSS Images Module Level 3. 17 December 2020. CR. URL: https://www.w3.org/TR/css-images-3/
[CSS-OVERFLOW-3]
  David Baron; Elika Etemad; Florian Rivoal. CSS Overflow Module Level 3. 23 December 2021. WD. URL: https://www.w3.org/TR/css-overflow-3/
[CSS-POSITION-3]
  Elika Etemad; Tab Atkins Jr.. CSS Positioned Layout Module Level 3. 1 September 2022. WD. URL: https://www.w3.org/TR/css-position-3/
[CSS-PSEUDO-4]
  Daniel Glazman; Elika Etemad; Alan Stearns. CSS Pseudo-Elements Module Level 4. 31 December 2020. WD. URL: https://www.w3.org/TR/css-pseudo-4/
[CSS-SIZING-3]
  Tab Atkins Jr.; Elika Etemad. CSS Box Sizing Module Level 3. 17 December 2021. WD. URL: https://www.w3.org/TR/css-sizing-3/
[CSS-UI-3]
  Tantek Çelik; Florian Rivoal. CSS Basic User Interface Module Level 3 (CSS3 UI). 21 June 2018. REC. URL: https://www.w3.org/TR/css-ui-3/
[CSS-UI-4]
  Florian Rivoal. CSS Basic User Interface Module Level 4. 16 March 2021. WD. URL: https://www.w3.org/TR/css-ui-4/
[CSS-VALUES-3]
  Tab Atkins Jr.; Elika Etemad. CSS Values and Units Module Level 3. 6 June 2019. CR. URL: https://www.w3.org/TR/css-values-3/
[CSS-VALUES-4]
  Tab Atkins Jr.; Elika Etemad. CSS Values and Units Module Level 4. 16 December 2021. WD. URL: https://www.w3.org/TR/css-values-4/
[CSS-WRITING-MODES-3]
  Elika Etemad; Koji Ishii. CSS Writing Modes Level 3. 10 December 2019. REC. URL: https://www.w3.org/TR/css-writing-modes-3/
[CSS-WRITING-MODES-4]
  Elika Etemad; Koji Ishii. CSS Writing Modes Level 4. 30 July 2019. CR. URL: https://www.w3.org/TR/css-writing-modes-4/
[CSS2]
  Bert Bos; et al. Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification. 7 June 2011. REC. URL: https://www.w3.org/TR/CSS21/
[HTML]
  Anne van Kesteren; et al. HTML Standard. Living Standard. URL: https://html.spec.whatwg.org/multipage/
[RFC2119]
  S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://datatracker.ietf.org/doc/html/rfc2119
[SVG2]
  Amelia Bellamy-Royds; et al. Scalable Vector Graphics (SVG) 2. 4 October 2018. CR. URL: https://www.w3.org/TR/SVG2/

### Informative References

[CSS-CONTENT-3]
  Elika Etemad; Dave Cramer. CSS Generated Content Module Level 3. 2 August 2019. WD. URL: https://www.w3.org/TR/css-content-3/
[CSS-GRID-2]
  Tab Atkins Jr.; Elika Etemad; Rossen Atanassov. CSS Grid Layout Module Level 2. 18 December 2020. CR. URL: https://www.w3.org/TR/css-grid-2/
[CSS-MULTICOL-1]
  Florian Rivoal; Rachel Andrew. CSS Multi-column Layout Module Level 1. 12 October 2021. CR. URL: https://www.w3.org/TR/css-multicol-1/
[CSS-OVERFLOW-4]
  David Baron; Florian Rivoal. CSS Overflow Module Level 4. 13 June 2017. WD. URL: https://www.w3.org/TR/css-overflow-4/
[CSS-PAGE-3]
  Elika Etemad; Simon Sapin. CSS Paged Media Module Level 3. 18 October 2018. WD. URL: https://www.w3.org/TR/css-page-3/
[CSS-REGIONS-1]
  Rossen Atanassov; Alan Stearns. CSS Regions Module Level 1. 9 October 2014. WD. URL: https://www.w3.org/TR/css-regions-1/
[CSS-SIZING-4]
  Tab Atkins Jr.; Elika Etemad; Jen Simmons. CSS Box Sizing Module Level 4. 20 May 2021. WD. URL: https://www.w3.org/TR/css-sizing-4/
[FILTER-EFFECTS-1]
  Dirk Schulze; Dean Jackson. Filter Effects Module Level 1. 18 December 2018. WD. URL: https://www.w3.org/TR/filter-effects-1/

## Property Index

Name | Value | Initial | Applies to | Inh. | %ages | Animation type | Canonical order | Computed value
--- | --- | --- | --- | --- | --- | --- | --- | ---
contain | none | strict | content | [ size || layout || paint ] | none | See below | no | n/a | not animatable | per grammar | specified keyword(s)the keyword none or one or more of size, layout, paint

#propdef-contain Referenced in:

- 1. Introduction
- 2. Strong Containment: the contain property (2) (3) (4) (5) (6) (7) (8) (9) (10) (11) (12) (13)
- Changes from the Candidate Recommendation of 08 November 2018 (2)

#valdef-contain-none Referenced in:

- 2. Strong Containment: the contain property (2)

#valdef-contain-strict Referenced in:

- 2. Strong Containment: the contain property

#valdef-contain-content Referenced in:

- 2. Strong Containment: the contain property

#valdef-contain-size Referenced in:

- 2. Strong Containment: the contain property

#valdef-contain-layout Referenced in:

- 2. Strong Containment: the contain property

#valdef-contain-paint Referenced in:

- 2. Strong Containment: the contain property

#containment Referenced in:

- 2. Strong Containment: the contain property (2)
- 3. Types of Containment

#size-containment Referenced in:

- 2. Strong Containment: the contain property (2) (3)
- 3.1. Size Containment (2) (3)
- 3.1.1. Possible Size-Containment Optimizations
- 3.2.1. Possible Layout-Containment Optimizations

#size-containment-box Referenced in:

- 2. Strong Containment: the contain property
- 3.1. Size Containment (2) (3) (4) (5) (6) (7) (8) (9)
- 3.1.1. Possible Size-Containment Optimizations (2) (3) (4) (5) (6) (7) (8)

#sizing-as-if-empty Referenced in:

- 3.1. Size Containment

#laying-out-in-place Referenced in:

- 3.1.1. Possible Size-Containment Optimizations

#layout-containment Referenced in:

- 2. Strong Containment: the contain property
- 3.1. Size Containment (2)
- 3.1.1. Possible Size-Containment Optimizations
- 3.2. Layout Containment (2) (3) (4) (5)
- 3.2.1. Possible Layout-Containment Optimizations

#layout-containment-box Referenced in:

- 2. Strong Containment: the contain property
- 3.2. Layout Containment (2) (3) (4) (5) (6) (7) (8) (9)
- 3.2.1. Possible Layout-Containment Optimizations (2) (3) (4) (5)

#paint-containment Referenced in:

- 2. Strong Containment: the contain property
- 3.3. Paint Containment
- 3.3.1. Possible Paint-Containment Optimizations (2)

#paint-containment-box Referenced in:

- 2. Strong Containment: the contain property
- 3.3. Paint Containment (2) (3) (4)
- 3.3.1. Possible Paint-Containment Optimizations