--- url: "https://www.w3.org/TR/css-contain-3/" titulek: "CSS Containment Module Level 3" h1: "CSS Containment Module Level 3" popis: "" jazyk: "en" kanonicka: "https://www.w3.org/TR/css-contain-3/" drobecky: [] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 04:46:39" znaku: 62611 slov: 8087 kodovani: "utf-8" sha256: "7e6b410172bfecf8b5fcccca2c5d6862ea87b81f20c34cd508934199f5373ec7" --- # CSS Containment Module Level 3 [W3C Working Draft](https://www.w3.org/standards/types#WD), 18 August 2022 More details about this document This version: [https://www.w3.org/TR/2022/WD-css-contain-3-20220818/](https://www.w3.org/TR/2022/WD-css-contain-3-20220818/) Latest published version: [https://www.w3.org/TR/css-contain-3/](https://www.w3.org/TR/css-contain-3/) Editor's Draft: [https://drafts.csswg.org/css-contain-3/](https://drafts.csswg.org/css-contain-3/) Previous Versions: [https://www.w3.org/TR/2021/WD-css-contain-3-20211221/](https://www.w3.org/TR/2021/WD-css-contain-3-20211221/) History: [https://www.w3.org/standards/history/css-contain-3](https://www.w3.org/standards/history/css-contain-3) Test Suite: [https://test.csswg.org/harness/results/css-contain-1_dev/](https://test.csswg.org/harness/results/css-contain-1_dev/) Feedback: [CSSWG Issues Repository](https://github.com/w3c/csswg-drafts/labels/css-contain-3) Inline In Spec Editors: [Tab Atkins](http://xanthir.com/contact/) (Google) [Florian Rivoal](https://florian.rivoal.net/) (On behalf of Bloomberg) [Miriam E. Suzanne](https://www.miriamsuzanne.com/who/) (Invited Expert) Suggest an Edit for this Spec: [GitHub Editor](https://github.com/w3c/csswg-drafts/blob/main/css-contain-3/Overview.bs) [Copyright](https://www.w3.org/Consortium/Legal/ipr-notice#Copyright) © 2022 [W3C](https://www.w3.org/)® ([MIT](https://www.csail.mit.edu/), [ERCIM](https://www.ercim.eu/), [Keio](https://www.keio.ac.jp/), [Beihang](https://ev.buaa.edu.cn/)). W3C [liability](https://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer), [trademark](https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks) and [permissive document license](https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document) rules apply. --- ## Abstract This CSS module describes the [contain](https://www.w3.org/TR/css-contain-1/#propdef-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](https://www.w3.org/TR/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 section describes the status of this document at the time of its publication. A list of current W3C publications and the latest revision of this technical report can be found in the [W3C technical reports index at https://www.w3.org/TR/.](https://www.w3.org/TR/)* This document was published by the [CSS Working Group](https://www.w3.org/groups/wg/css) as a **Working Draft** using the [Recommendation track](https://www.w3.org/2021/Process-20211102/#recs-and-notes). Publication as a Working Draft does not imply endorsement by W3C and its Members. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress. Please send feedback by [filing issues in GitHub](https://github.com/w3c/csswg-drafts/issues) (preferred), including the spec code “css-contain” in the title, like this: “[css-contain] *…summary of comment…*”. All issues and comments are [archived](https://lists.w3.org/Archives/Public/public-css-archive/). Alternately, feedback can be sent to the ([archived](https://lists.w3.org/Archives/Public/www-style/)) public mailing list [www-style@w3.org](mailto:www-style@w3.org?Subject=%5Bcss-contain%5D%20PUT%20SUBJECT%20HERE). This document is governed by the [2 November 2021 W3C Process Document](https://www.w3.org/2021/Process-20211102/). This document was produced by a group operating under the [W3C Patent Policy](https://www.w3.org/Consortium/Patent-Policy-20200915/). W3C maintains a [public list of any patent disclosures](https://www.w3.org/groups/wg/css/ipr) made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains [Essential Claim(s)](https://www.w3.org/Consortium/Patent-Policy-20200915/#def-essential) must disclose the information in accordance with [section 6 of the W3C Patent Policy](https://www.w3.org/Consortium/Patent-Policy-20200915/#sec-Disclosure). ## 1. Introduction This is a diff spec over [CSS Containment Level 2](https://www.w3.org/TR/css-contain-2/). It is currently an Exploratory Working Draft: if you are implementing anything, please use Level 2 as a reference. We will merge the Level 2 text into this draft once it reaches CR. ### 1.1. Module Interactions This document defines new features not present in earlier specifications. In addition, it aims to replace and supersede [CSS-CONTAIN-1] once stable. ### 1.2. Value Definitions This specification follows the [CSS property definition conventions](https://www.w3.org/TR/CSS2/about.html#property-defs) from [CSS2] using the [value definition syntax](https://www.w3.org/TR/css-values-3/#value-defs) 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](https://www.w3.org/TR/css-values-4/#css-wide-keywords) as their property value. For readability they have not been repeated explicitly. ## 2. Strong Containment: the [contain](https://www.w3.org/TR/css-contain-1/#propdef-contain) property [CSS Containment 2 § 2 Strong Containment: the contain property](https://drafts.csswg.org/css-contain-2/#contain-property) | Name: [contain](https://www.w3.org/TR/css-contain-1/#propdef-contain) | | --- | | [New values:](https://www.w3.org/TR/css-values/#value-defs) layout [\|\|](https://www.w3.org/TR/css-values-4/#comb-any) style \|\| paint \|\| [ size [\|](https://www.w3.org/TR/css-values-4/#comb-one) inline-size ] | inline-size This value turns on inline-size containment for the element. This prevents the [inline-size](https://www.w3.org/TR/css-writing-modes-4/#inline-size) of its [principal box](https://www.w3.org/TR/css-display-3/#principal-box) from directly depending on its contents. Note: There can still be indirect dependencies, see § 3.1 Inline-Size Containment. ## 3. Types of Containment [CSS Containment 2 § 3 Types of Containment](https://drafts.csswg.org/css-contain-2/#containment-types) ### 3.1. Inline-Size Containment Giving an element inline-size containment applies [size containment](https://www.w3.org/TR/css-contain-1/#size-containment) to the [inline-axis](https://www.w3.org/TR/css-writing-modes-4/#inline-axis) sizing of its [principal box](https://www.w3.org/TR/css-display-3/#principal-box). This means the inline-axis [intrinsic sizes](https://www.w3.org/TR/css-sizing-3/#intrinsic-size) of the principal box are determined as if the element had no content. However, content continues to impact the box’s [block-axis](https://www.w3.org/TR/css-writing-modes-4/#block-axis) intrinsic sizes as usual, and the box is allowed to [fragment](https://www.w3.org/TR/css-break-3/#fragmentation) normally in the block axis. Note: In some cases, a box’s [block-axis](https://www.w3.org/TR/css-writing-modes-4/#block-axis) [intrinsic sizes](https://www.w3.org/TR/css-sizing-3/#intrinsic-size) can impact layout in the parent [formatting context](https://www.w3.org/TR/css-display-3/#formatting-context) in ways that affect the box’s [inline size](https://www.w3.org/TR/css-writing-modes-4/#inline-size) (e.g. by triggering scrollbars on an ancestor element), creating a dependency of the box’s inline size on its own content. If this changed inline size results in a different [block size](https://www.w3.org/TR/css-writing-modes-4/#block-size) , that new block size can loop into further impacting the parent formatting context, but not in a way that reverts it to the previously-problematic layout. For example, if scrollbars were introduced, they are not then removed, even if the consequent [block size](https://www.w3.org/TR/css-writing-modes-4/#block-size) is small enough to not need them; or if a box’s logical height collides with a lower-placed float and is cleared down to where it also has more available inline space and thus becomes short enough to not have collided, it is not them moved back up to its previous problematic size and position. Thus, although inline-size containment prevents the box’s content from directly affecting its [inline size](https://www.w3.org/TR/css-writing-modes-4/#inline-size) through its [inline-axis](https://www.w3.org/TR/css-writing-modes-4/#inline-axis) [intrinsic sizes](https://www.w3.org/TR/css-sizing-3/#intrinsic-size), its inline size can still indirectly depend on its contents by their effect on its [block size](https://www.w3.org/TR/css-writing-modes-4/#block-size). In general, the relationship between an element’s inline size and it’s block size is unpredictable and non-monotonic, with the block size capable of shifting up and down arbitrarily as the inline size is changed. Infinite cycles are prevented by ensuring that layout does not revert to a previous (known-problematic) state, even if a naive analysis of the constraints would allow for such; in other words, layout always “moves forward”. We believe that current CSS layout specifications incorporate such rules, but to the extent that they don’t, please [inform the CSSWG](https://github.com/w3c/csswg-drafts/issues) so that these errors can be corrected. Consider this example, where float placement creates a dependency of block sizes on inline sizes: ```
Article
``` Article The block layout algorithm will first place the floating boxes, with the first two sitting in the left and right corners of the container, and the third, being too wide to fit between, being pushed below them. The following `article` will then be laid out. Because it is [display: flow-root](https://www.w3.org/TR/css-display-3/#propdef-display), it cannot intersect any floats, and thus must take them into account when figuring out how to size and position itself. The layout engine first attempts to place the `article` flush with the top of the container, resulting a 100px width, plenty wide enough to accommodate its [min-content size](https://www.w3.org/TR/css-sizing-3/#min-content). However, due to the [aspect-ratio](https://www.w3.org/TR/css-sizing-4/#propdef-aspect-ratio) of its child, this would cause the `article` to be 100px tall as well, which would intersect the third float 80px below, so this layout opportunity is discarded. It then attempts to position the `article` flush with the top of the third float, in the narrow 40px-wide space to its right. However, since the `article`’s [min-width](https://www.w3.org/TR/css-sizing-3/#propdef-min-width) makes it too large to fit in the 40px-wide space beside the third float, it shifts below that one as well, forming a 200px square below all the floated boxes. Article If the [min-width](https://www.w3.org/TR/css-sizing-3/#propdef-min-width) is removed from the `article`, or if inline-size containment is added to either the `article` or `header` (causing min-width: min-content to resolve to zero), then the `article` will fit as a 40px square next to the final floated `div` (possibly with some of its content overflowing). At this point, the width and height of the `article` (40px each) *would* fit back in the first considered space, flush with the top of the container. However, the box is not returned to the previous position, because the layout engine knows already that this position would result in an invalid layout. Giving an element inline-size containment has no effect if any of the following are true: - if the element does not generate a [principal box](https://www.w3.org/TR/css-display-3/#principal-box) (as is the case with [display: contents](https://www.w3.org/TR/css-display-3/#propdef-display) or display: none) - if its [inner display type](https://www.w3.org/TR/css-display-3/#inner-display-type) is [table](https://www.w3.org/TR/css-display-3/#valdef-display-table) - if its [principal box](https://www.w3.org/TR/css-display-3/#principal-box) is an [internal table box](https://www.w3.org/TR/css-display-3/#internal-table-box) - if its [principal box](https://www.w3.org/TR/css-display-3/#principal-box) is an [internal ruby box](https://www.w3.org/TR/css-display-3/#internal-ruby-box) or a [non-atomic](https://www.w3.org/TR/css-display-3/#atomic-inline) [inline-level](https://www.w3.org/TR/css-display-3/#inline-level) box ## 4. Container Queries While [media queries](https://www.w3.org/TR/mediaqueries-5/#media-query) provide a method to query aspects of the user agent or device environment that a document is being displayed in (such as viewport dimensions or user preferences), container queries allow testing aspects of elements within the document (such as box dimensions or computed styles). By default, all elements are query containers for the purpose of container style queries, and can be established as query containers for container size queries by specifying the additional query types using the container-type property (or the container [shorthand](https://www.w3.org/TR/css-cascade-5/#shorthand-property)). Style rules applying to a query container’s [shadow-including descendants](https://dom.spec.whatwg.org/#concept-shadow-including-descendant) can be conditioned by querying against it, using the @container [conditional group rule](https://www.w3.org/TR/css3-conditional/#conditional-group-rule). For example, we can define the main content area and sidebar as containers, and then describe a .media-object that changes from vertical to horizontal layout depending on the size of its container: ``` main, aside { container: my-layout / inline-size; } .media-object { display: grid; grid-template: 'img' auto 'content' auto / 100%; } @container my-layout (inline-size > 45em) { .media-object { grid-template: 'img content' auto / auto 1fr; } } ``` Media objects in the main and sidebar areas will each respond to their own container context. For selectors with pseudo elements, query containers can be established by the [shadow-including inclusive ancestors](https://dom.spec.whatwg.org/#concept-shadow-including-inclusive-ancestor) of the [ultimate originating element](https://www.w3.org/TR/selectors-4/#ultimate-originating-element). It follows that: - Pseudo elements themselves can not be query containers - [::before](https://www.w3.org/TR/css-pseudo-4/#selectordef-before), [::after](https://www.w3.org/TR/css-pseudo-4/#selectordef-after), [::marker](https://www.w3.org/TR/css-pseudo-4/#selectordef-marker), and [::backdrop](https://fullscreen.spec.whatwg.org/#css-pe-backdrop) query their originating elements - [::first-letter](https://www.w3.org/TR/css-pseudo-4/#selectordef-first-letter) and [::first-line](https://www.w3.org/TR/css-pseudo-4/#selectordef-first-line) query their originating elements, even if the [fictional tag sequence](https://www.w3.org/TR/css-pseudo-4/#fictional-tag-sequence) may push the `::first-line` past other elements for the purpose of inheritance and rendering - Multiple pseudo elements do not allow pseudo elements to be query containers for other pseudo elements. E.g., the host, but not the `::part()`, can be the query container for `::before` in `host::part()::before`. Similarly, `::before` can not be the query container for the `::marker` in `div::before::marker` - [::slotted()](https://drafts.csswg.org/css-scoping-1/#selectordef-slotted) selectors can query containers inside the shadow tree, including the slot itself - [::part()](https://www.w3.org/TR/css-shadow-parts-1/#selectordef-part) selectors can query its originating host, but not internal query containers inside the shadow tree - [::placeholder](https://www.w3.org/TR/css-pseudo-4/#selectordef-placeholder) and [::file-selector-button](https://www.w3.org/TR/css-pseudo-4/#selectordef-file-selector-button) can query the input element, but do not expose any internal containers if the input element is implemented using a shadow tree A ::before selector querying the size of the originating element: ```
``` A ::slotted() selector for styling a shadow host child can query a container in the shadow tree: ```
Green
``` ### 4.1. Creating Query Containers: the container-type property | Name: container-type | | --- | | [Value:](https://www.w3.org/TR/css-values/#value-defs) normal [\|\|](https://www.w3.org/TR/css-values-4/#comb-any) [ size [\|](https://www.w3.org/TR/css-values-4/#comb-one) inline-size ] | | [Initial:](https://www.w3.org/TR/css-cascade/#initial-values) normal | | [Applies to:](https://www.w3.org/TR/css-cascade/#applies-to) [all elements](https://www.w3.org/TR/css-pseudo/#generated-content) | | [Inherited:](https://www.w3.org/TR/css-cascade/#inherited-property) no | | [Percentages:](https://www.w3.org/TR/css-values/#percentages) n/a | | [Computed value:](https://www.w3.org/TR/css-cascade/#computed) the keyword normal or one or more of size, inline-size | | [Canonical order:](https://www.w3.org/TR/cssom/#serializing-css-values) per grammar | | [Animation type:](https://www.w3.org/TR/web-animations/#animation-type) not animatable | The container-type property establishes the element as a query container for the purpose of container queries that require explicit containment (such as container size queries), allowing [style rules](https://www.w3.org/TR/css-syntax-3/#style-rule) styling its descendants to query various aspects of its sizing and layout, and respond accordingly. Unless otherwise noted, all elements are query containers for the purpose container queries that do no require explicit containment (such as container style queries), reagardless of the specified container-type. Values have the following meanings: size Establishes a query container for container size queries on both the [inline](https://www.w3.org/TR/css-writing-modes-4/#inline-axis) and [block axis](https://www.w3.org/TR/css-writing-modes-4/#block-axis). Applies [layout containment](https://www.w3.org/TR/css-contain-1/#layout-containment), [style containment](https://drafts.csswg.org/css-contain-2/#style-containment), and [size containment](https://www.w3.org/TR/css-contain-1/#size-containment) to the [principal box](https://www.w3.org/TR/css-display-3/#principal-box). inline-size Establishes a query container for container size queries on the container’s own [inline axis](https://www.w3.org/TR/css-writing-modes-4/#inline-axis). Applies [layout containment](https://www.w3.org/TR/css-contain-1/#layout-containment), [style containment](https://drafts.csswg.org/css-contain-2/#style-containment), and inline-size containment to the [principal box](https://www.w3.org/TR/css-display-3/#principal-box). normal The element is not a query container for any container size queries, but remains a query container for container style queries. For example, authors can create container-responsive typography, adjusting [font-size](https://www.w3.org/TR/css-fonts-4/#propdef-font-size) , [line-height](https://www.w3.org/TR/CSS2/visudet.html#propdef-line-height) , and other typographic concerns based on the size of a container: ``` aside, main { container-type: inline-size; } h2 { font-size: 1.2em; } @container (width > 40em) { h2 { font-size: 1.5em; } } ``` The 40em value used in the query condition is relative to the [computed value](https://www.w3.org/TR/css-cascade-5/#computed-value) of [font-size](https://www.w3.org/TR/css-fonts-4/#propdef-font-size) on the relevant query container. Containers can also expose computed style values for querying. This can be useful for toggling behavior across multiple properties: ``` section { container-type: style; } @container (--cards: small) { article { border: thin solid silver; border-radius: 0.5em; padding: 1em; } } ``` ### 4.2. Naming Query Containers: the container-name property | Name: container-name | | --- | | [Value:](https://www.w3.org/TR/css-values/#value-defs) none [\|](https://www.w3.org/TR/css-values-4/#comb-one) [](https://www.w3.org/TR/css-values-4/#identifier-value)[+](https://www.w3.org/TR/css-values-4/#mult-one-plus) | | [Initial:](https://www.w3.org/TR/css-cascade/#initial-values) none | | [Applies to:](https://www.w3.org/TR/css-cascade/#applies-to) [all elements](https://www.w3.org/TR/css-pseudo/#generated-content) | | [Inherited:](https://www.w3.org/TR/css-cascade/#inherited-property) no | | [Percentages:](https://www.w3.org/TR/css-values/#percentages) n/a | | [Computed value:](https://www.w3.org/TR/css-cascade/#computed) the keyword none, or an ordered list of [identifiers](https://www.w3.org/TR/css-values-4/#css-css-identifier) | | [Canonical order:](https://www.w3.org/TR/cssom/#serializing-css-values) per grammar | | [Animation type:](https://www.w3.org/TR/web-animations/#animation-type) not animatable | The container-name property specifies a list of query container names. These names can be used by @container rules to filter which query containers are targeted. none The query container has no query container name. [](https://www.w3.org/TR/css-values-4/#identifier-value) Specifies a query container name as an [identifier](https://www.w3.org/TR/css-values-4/#css-css-identifier). The keywords none, and, [not](https://www.w3.org/TR/mediaqueries-5/#valdef-media-not), and or are excluded from this [](https://www.w3.org/TR/css-values-4/#identifier-value). In some cases, we want to query aspects of a specific container, even if it’s not the nearest ancestor container. For example, we might want to query the height of a main content area, and the width of a more nested inline-container. ``` main { container-type: size; container-name: my-page-layout; } .my-component { container-type: inline-size; container-name: my-component-library; } @container my-page-layout (block-size > 12em) { .card { margin-block: 2em; } } @container my-component-library (inline-size > 30em) { .card { margin-inline: 2em; } } ``` ### 4.3. Creating Named Containers: the container shorthand | Name: container | | --- | | [Value:](https://www.w3.org/TR/css-values/#value-defs) <'container-name'> [ / <'container-type'> ][?](https://www.w3.org/TR/css-values-4/#mult-opt) | | [Initial:](https://www.w3.org/TR/css-cascade/#initial-values) see individual properties | | [Applies to:](https://www.w3.org/TR/css-cascade/#applies-to) see individual properties | | [Inherited:](https://www.w3.org/TR/css-cascade/#inherited-property) see individual properties | | [Percentages:](https://www.w3.org/TR/css-values/#percentages) see individual properties | | [Computed value:](https://www.w3.org/TR/css-cascade/#computed) see individual properties | | [Animation type:](https://www.w3.org/TR/web-animations/#animation-type) see individual properties | | [Canonical order:](https://www.w3.org/TR/cssom/#serializing-css-values) per grammar | The container [shorthand property](https://www.w3.org/TR/css-cascade-5/#shorthand-property) sets both container-type and container-name in the same declaration. If <'container-type'> is omitted, it is reset to its [initial value](https://www.w3.org/TR/css-cascade-5/#initial-value). We can define both a container-type and container-name using the shorthand syntax: ``` main { container: my-layout / size; } .grid-item { container: my-component / inline-size; } ``` ### 4.4. Container Queries: the @container rule The @container rule is a [conditional group rule](https://www.w3.org/TR/css3-conditional/#conditional-group-rule) whose condition is a container query, which is a boolean combination of container size queries and/or container style queries. Style declarations within the [](https://www.w3.org/TR/css-syntax-3/#typedef-stylesheet) block of an @container rule are [filtered](https://www.w3.org/TR/css-cascade-4/#filtering) by its condition to only match when the container query is true for their element’s query container. The syntax of the @container rule is: ``` @container [ ]? { } ``` where: ``` = = not | [ [ and ]* | [ or ]* ] = ( ) | ( ) | style( ) | = | = not | [ [ and ]* | [ or ]* ] = ( ) | ( ) | ``` The keywords none, and, [not](https://www.w3.org/TR/mediaqueries-5/#valdef-media-not), and or are excluded from the [](https://www.w3.org/TR/css-values-4/#identifier-value) above. For each element, the query container to be queried is selected from among the element’s ancestor query containers that are established as a valid query container for all the container features in the . The optional filters the set of query containers considered to just those with a matching query container name. Once an eligible query container has been selected for an element, each container feature in the is evaluated against that query container. If no ancestor is an eligible query container, then the container query is unknown for that element. As with [media queries](https://www.w3.org/TR/mediaqueries-5/#media-query) , we can string together multiple conditions in a single query list: ``` @container card (inline-size > 30em) and style(--responsive: true) { /* styles */ } ``` The styles above will only be applied if there is an ancestor container named "card" that meets both the inline-size and style conditions. Style rules defined on an element inside multiple nested container queries apply when all of the wrapping container queries are true for that element. Note: Nested container queries can evaluate in relation to different containers, so it is not always possible to merge the individual s into a single query. While it is not possible to query multiple containers in a single container query , that can be achieved by nesting multiple queries: ``` @container card (inline-size > 30em) { @container style(--responsive: true) { /* styles */ } } ``` The styles above will only be applied if there is an ancestor container named "card" that meets the inline-size condition, as well as an ancestor container meeting style condition. Global, name-defining [at-rules](https://www.w3.org/TR/css-syntax-3/#at-rule) such as [@keyframes](https://www.w3.org/TR/css-animations-1/#at-ruledef-keyframes) or [@font-face](https://www.w3.org/TR/css-fonts-5/#at-font-face-rule) or [@layer](https://www.w3.org/TR/css-cascade-5/#at-ruledef-layer) that are defined inside container queries are not constrained by the container query conditions. ### 4.5. Animated Containers A change in the evaluation of a container query must be part of a [style change event](https://www.w3.org/TR/css-transitions-1/#style-change-event), even when the change occurred because of [animation effects](https://www.w3.org/TR/web-animations-1/#effect-value). A transition on a sibling element can indirectly affect the size of a container, triggering [style change events](https://www.w3.org/TR/css-transitions-1/#style-change-event) whenever container queries change their evaluation as a result: ``` main { display: flex; width: 300px; } #container { container-type: inline-size; flex: 1; } /* Resolved width is initially 200px, but changes as the transition on #sibling progresses. */ #inner { transition: 1s background-color; background-color: tomato; } /* When this container query starts (or stops) applying, a transition must start on background-color on #inner. */ @container (width <= 150px) { #inner { background-color: skyblue; } } #sibling { width: 100px; transition: width 1s; } #sibling:hover { width: 200px; } ``` ```
Inner
Sibling
``` Changes in [computed values](https://www.w3.org/TR/css-cascade-5/#computed-value) caused by container query length units must also be part of a [style change event](https://www.w3.org/TR/css-transitions-1/#style-change-event). ## 5. Container Features A container feature queries a specific aspect of a query container. ### 5.1. Size Container Features A container size query allows querying the size of the query container’s [principal box](https://www.w3.org/TR/css-display-3/#principal-box). It is a boolean combination of individual size features () that each query a single, specific dimensional feature of the query container. The syntax of a is the same as for a [media feature](https://www.w3.org/TR/mediaqueries-5/#media-feature): a feature name, a comparator, and a value. [mediaqueries-5] The boolean syntax and logic combining size features into a size query is the same as for [CSS feature queries](https://www.w3.org/TR/css3-conditional/#css-feature-queries). (See [@supports](https://www.w3.org/TR/css3-conditional/#at-ruledef-supports). [CSS-CONDITIONAL-3]) If the query container does not have a [principal box](https://www.w3.org/TR/css-display-3/#principal-box), or the principal box is not a [layout containment box](https://drafts.csswg.org/css-contain-2/#layout-containment-box), or the query container does not support container size queries on the relevant axes, then the result of evaluating the size feature is unknown. [Relative length](https://www.w3.org/TR/css-values-4/#relative-length) units (including container query length units) in container query conditions are evaluated based on the the [computed values](https://www.w3.org/TR/css-cascade-5/#computed-value) of the query container. Note: This is different from the handling of relative units in [media queries](https://www.w3.org/TR/mediaqueries-5/#media-query). For example, query containers with different font-sizes will evaluate [em](https://www.w3.org/TR/css-values-4/#em) -based queries relative to their own font sizes: ``` aside, main { container-type: inline-size; } aside { font-size: 16px; } main { font-size: 24px; } @container (width > 40em) { h2 { font-size: 1.5em; } } ``` The 40em value used in the query condition is relative to the [computed value](https://www.w3.org/TR/css-cascade-5/#computed-value) of [font-size](https://www.w3.org/TR/css-fonts-4/#propdef-font-size) on the relevant query container: - For any h2 inside aside, the query condition will be true above 640px. - For any h2 inside main, the query condition will be true above 960px. #### 5.1.1. Width: the width feature | Name: width | | --- | | For: @container | | Value: [](https://www.w3.org/TR/css-values-4/#length-value) | | Type: range | The width container feature queries the [width](https://www.w3.org/TR/css-sizing-3/#width) of the query container’s [content box](https://www.w3.org/TR/css-box-4/#content-box). #### 5.1.2. Height: the height feature | Name: height | | --- | | For: @container | | Value: [](https://www.w3.org/TR/css-values-4/#length-value) | | Type: range | The height container feature queries the [height](https://www.w3.org/TR/css-sizing-3/#height) of the query container’s [content box](https://www.w3.org/TR/css-box-4/#content-box). #### 5.1.3. Inline-size: the inline-size feature | Name: inline-size | | --- | | For: @container | | Value: [](https://www.w3.org/TR/css-values-4/#length-value) | | Type: range | The inline-size container feature queries the [size](https://www.w3.org/TR/css-sizing-3/#size) of the query container’s [content box](https://www.w3.org/TR/css-box-4/#content-box) in the query container’s [inline axis](https://www.w3.org/TR/css-writing-modes-4/#inline-axis). #### 5.1.4. Block-size: the block-size feature | Name: block-size | | --- | | For: @container | | Value: [](https://www.w3.org/TR/css-values-4/#length-value) | | Type: range | The block-size container feature queries the [size](https://www.w3.org/TR/css-sizing-3/#size) of the query container’s [content box](https://www.w3.org/TR/css-box-4/#content-box) in the query container’s [block axis](https://www.w3.org/TR/css-writing-modes-4/#block-axis). #### 5.1.5. Aspect-ratio: the aspect-ratio feature | Name: aspect-ratio | | --- | | For: @container | | Value: [](https://www.w3.org/TR/css-values-4/#ratio-value) | | Type: range | The aspect-ratio container feature is defined as the ratio of the value of the width container feature to the value of the height container feature. #### 5.1.6. Orientation: the orientation feature | Name: orientation | | --- | | For: @container | | Value: portrait [\|](https://www.w3.org/TR/css-values-4/#comb-one) landscape | | Type: discrete | portrait The orientation container feature is portrait when the value of the height container feature is greater than or equal to the value of the width container feature. landscape Otherwise orientation is landscape. ### 5.2. Style Container Features A container style query allows querying the [computed values](https://www.w3.org/TR/css-cascade-5/#computed-value) of the query container. It is a boolean combination of individual style features () that each query a single, specific property of the query container. The syntax of a is the same as for a [declaration](https://www.w3.org/TR/css-syntax-3/#declaration) [CSS-SYNTAX-3], and its query is true if the computed value of the given property on the query container matches the given value (which is also computed with respect to the query container), unknown if the property or its value is invalid or unsupported, and false otherwise. The boolean syntax and logic combining style features into a style query is the same as for [CSS feature queries](https://www.w3.org/TR/css3-conditional/#css-feature-queries). (See [@supports](https://www.w3.org/TR/css3-conditional/#at-ruledef-supports). [CSS-CONDITIONAL-3]) Style features that query a [shorthand property](https://www.w3.org/TR/css-cascade-5/#shorthand-property) are true if the [computed values](https://www.w3.org/TR/css-cascade-5/#computed-value) match for each of its [longhand properties](https://www.w3.org/TR/css-cascade-5/#longhand), and false otherwise. [Cascade-dependent keywords](https://drafts.csswg.org/css-cascade-5/#cascade-dependent-keyword), such as [revert](https://www.w3.org/TR/css-cascade-5/#valdef-all-revert) and [revert-layer](https://www.w3.org/TR/css-cascade-5/#valdef-all-revert-layer), are invalid as values in a style feature, and cause the container style query to be false. Note: The remaining non-cascade-dependent [CSS-wide keywords](https://www.w3.org/TR/css-values-4/#css-wide-keywords) are [computed](https://www.w3.org/TR/css-cascade-5/#computed-value) with respect to the query container, the same as other values. ## 6. Container Relative Lengths: the cqw, cqh, cqi, cqb, cqmin, cqmax units Container query length units specify a length relative to the dimensions of a query container. Style sheets that use container query length units can more easily move components from one query container to another. The container query length units are: | unit | relative to cqw 1% of a query container’s [width](https://www.w3.org/TR/css-sizing-3/#width) cqh 1% of a query container’s [height](https://www.w3.org/TR/css-sizing-3/#height) cqi 1% of a query container’s [inline size](https://www.w3.org/TR/css-writing-modes-4/#inline-size) cqb 1% of a query container’s [block size](https://www.w3.org/TR/css-writing-modes-4/#block-size) cqmin The smaller value of cqi or cqb cqmax The larger value of cqi or cqb | | --- | --- | | cqw | 1% of a query container’s [width](https://www.w3.org/TR/css-sizing-3/#width) | | cqh | 1% of a query container’s [height](https://www.w3.org/TR/css-sizing-3/#height) | | cqi | 1% of a query container’s [inline size](https://www.w3.org/TR/css-writing-modes-4/#inline-size) | | cqb | 1% of a query container’s [block size](https://www.w3.org/TR/css-writing-modes-4/#block-size) | | cqmin | The smaller value of cqi or cqb | | cqmax | The larger value of cqi or cqb | For each element, container query length units are evaluated as container size queries on the relevant axis (or axes) described by the unit. The query container for each axis is the nearest ancestor container that accepts container size queries on that axis. If no eligible query container is available, then use the [small viewport size](https://www.w3.org/TR/css-values-4/#small-viewport-size) for that axis. Note: In some cases cqi and cqb units on the same element will evaluate in relation to different query containers. Similarly, cqmin and cqmax units represent the larger or smaller of the cqi and cqb units, even when those dimensions come from different query containers. Child elements do not inherit the relative values as specified for their parent; they inherit the [computed values](https://www.w3.org/TR/css-cascade-5/#computed-value). Authors can ensure that container query length units have an appropriate query container by applying them inside a container query that relies on the same container-type . Custom fallback values can be defined outside the container query : ``` /* The fallback value does not rely on containment */ h2 { font-size: 1.2em; } @container (inline-size >= 0px) { /* only applies when an inline-size container is available */ h2 { font-size: calc(1.2em + 1cqi); } } ``` ## 7. APIs ### 7.1. The `CSSContainerRule` interface The `CSSContainerRule` interface represents a @container rule. ``` [Exposed=Window] interface CSSContainerRule : CSSConditionRule { }; ``` `conditionText` of type `CSSOMString` (CSSContainerRule-specific definition for attribute on CSSConditionRule) The `conditionText` attribute (defined on the `CSSConditionRule` parent rule), on getting, must return the condition that was specified, without any logical simplifications, so that the returned condition will evaluate to the same result as the specified condition in any conformant implementation of this specification (including implementations that implement future extensions allowed by the [](https://www.w3.org/TR/mediaqueries-5/#typedef-general-enclosed) extensibility mechanism in this specification). In other words, token stream simplifications are allowed (such as reducing whitespace to a single space or omitting it in cases where it is known to be optional), but logical simplifications (such as removal of unneeded parentheses, or simplification based on evaluating results) are not allowed. Add CSSOM API for CSSContainerRule [[Issue #7033]](https://github.com/w3c/csswg-drafts/issues/7033) Container Queries should have a `matchContainer` method. This will be modeled on `[matchMedia()](https://www.w3.org/TR/cssom-view/#dom-window-matchmedia)` and the `[MediaQueryList](https://www.w3.org/TR/cssom-view/#mediaquerylist)` interface, but applied to Elements rather than the Window. When measuring layout sizes, it behaves Similar to `resizeObserver`, but it provides the additional Container Query syntax and features. [[Issue #6205]](https://github.com/w3c/csswg-drafts/issues/6205) ## 8. Suppressing An Element’s Contents Entirely: the [content-visibility](https://drafts.csswg.org/css-contain-2/#propdef-content-visibility) property [CSS Containment 2 § 4 Suppressing An Element’s Contents Entirely: the content-visibility property](https://drafts.csswg.org/css-contain-2/#content-visibility) ## 9. Privacy and Security Considerations [CSS Containment 2 § 5 Privacy and Security Considerations](https://drafts.csswg.org/css-contain-2/#priv-sec) ## Appendix A. Changes This appendix is *informative*. ### Changes since the 21 December 2021 First Public Working Draft Significant changes since the [21 December 2021 First Public Working Draft](https://www.w3.org/TR/2021/WD-css-contain-3-20211221/) include: - Allow the computed value of container-name to include duplicate identifiers. ([Issue 7181](https://github.com/w3c/csswg-drafts/issues/7181)) - Make the <'container-name'> in the container shorthand required. ([Issue 7142](https://github.com/w3c/csswg-drafts/issues/7142)) - Clarify handling of [shorthand properties](https://www.w3.org/TR/css-cascade-5/#shorthand-property) in container style queries. ([Issue 7095](https://github.com/w3c/csswg-drafts/issues/7095)) - [Cascade-dependent keywords](https://drafts.csswg.org/css-cascade-5/#cascade-dependent-keyword) are not allowed as values in a style feature, and cause the container style query to be false. ([Issue 7080](https://github.com/w3c/csswg-drafts/issues/7080)) - Change the initial value of container-type to be [style](https://drafts.csswg.org/css-contain-3/#valdef-container-type-style). ([Issue 6393](https://github.com/w3c/csswg-drafts/issues/6393)) - Remove the block-size value from container-type, since single-axis block-size containment is not currently possible. ([Issue 1031](https://github.com/w3c/csswg-drafts/issues/1031)) - Remove the [](https://www.w3.org/TR/css-values-4/#string-value) option from the container-name syntax. Container names must be [](https://www.w3.org/TR/css-values-4/#identifier-value)s. ([Issue 6405](https://github.com/w3c/csswg-drafts/issues/6405)) - Reverse the order of <'container-name'> and <'container-type'> in the container shorthand property, with both being optional. ([Issue 6393](https://github.com/w3c/csswg-drafts/issues/6393)) - Allow [](https://www.w3.org/TR/mediaqueries-5/#typedef-general-enclosed) syntax in s, for the sake of forward compatability. ([Issue 6396](https://github.com/w3c/csswg-drafts/issues/6396)) - Remove the size function syntax from queries. ([Issue 6870](https://github.com/w3c/csswg-drafts/issues/6870)) - Update the query container selection process to account for necessary container-types, and removed the explicit type-selection syntax. ([Issue 6644](https://github.com/w3c/csswg-drafts/issues/6644)) - Remove state query features, which have been deferred. ([Issue 6402](https://github.com/w3c/csswg-drafts/issues/6402)) - Clarify container selection around pseudo-elements and the shadow-DOM. ([Issue 5984](https://github.com/w3c/csswg-drafts/issues/5984) and [Issue 6711](https://github.com/w3c/csswg-drafts/issues/6711)) ### Changes from [CSS Containment Level 2](https://www.w3.org/TR/css-contain-2/) - Introduces inline-size containment. - Defines the terms, properties, units, and at-rule needed for Container Queries [CSS Containment 2 §  Changes](https://drafts.csswg.org/css-contain-2/#changes) ## Acknowledgments Comments and previous work from Adam Argyle, Amelia Bellamy-Royds, Anders Hartvoll Ruud, Brian Kardell, Chris Coyier, Christopher Kirk-Nielsen, David Herron, Elika J. Etemad (fantasai), Eric Portis, Ethan Marcotte, Geoff Graham, Gregory Wild-Smith, Ian Kilpatrick, Jen Simmons, Kenneth Rohde Christiansen, L. David Baron, Lea Verou, Martin Auswöger, Martine Dowden, Mike Riethmuller, Morten Stenshorne, Nicole Sullivan, Rune Lillesveen, Scott Jehl Scott Kellum, Stacy Kvernmo, Theresa O’Connor, Una Kravets, and many others have contributed to this specification. ## 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 ``, like this: **UAs MUST provide an accessible alternative.** ### Conformance classes Conformance to this specification is defined for three conformance classes: style sheet A [CSS style sheet](https://www.w3.org/TR/CSS21/conform.html#style-sheet). renderer A [UA](https://www.w3.org/TR/CSS21/conform.html#user-agent) that interprets the semantics of a style sheet and renders documents that use them. authoring tool A [UA](https://www.w3.org/TR/CSS21/conform.html#user-agent) 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](https://www.w3.org/TR/CSS21/conform.html#ignore)) 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](https://www.w3.org/TR/CSS/#future-proofing) for the implementation of [unstable](https://www.w3.org/TR/CSS/#unstable) features and [proprietary extensions](https://www.w3.org/TR/CSS/#proprietary-extension) 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 [https://www.w3.org/Style/CSS/Test/](https://www.w3.org/Style/CSS/Test/). Questions should be directed to the [public-css-testsuite@w3.org](https://lists.w3.org/Archives/Public/public-css-testsuite) mailing list. ## Index ### Terms defined by this specification - aspect-ratio , in § 5.1.5 - block-size , in § 5.1.4 - @container , in § 4.4 - container , in § 4.3 - , in § 4.4 - container feature , in § 5 - , in § 4.4 - container-name , in § 4.2 - container query , in § 4.4 - container query length , in § 6 - container size query , in § 5.1 - container style query , in § 5.2 - container-type , in § 4.1 - CSSContainerRule , in § 7.1 - , in § 4.2 - height , in § 5.1.2 - inline-size - descriptor for @container , in § 5.1.3 - value for contain , in § 2 - value for container-type , in § 4.1 - inline-size containment , in § 3.1 - landscape , in § 5.1.6 - none , in § 4.2 - normal , in § 4.1 - orientation , in § 5.1.6 - portrait , in § 5.1.6 - query container , in § 4.1 - query container name , in § 4.2 - , in § 4.4 - size , in § 4.1 - , in § 5.1 - size features , in § 5.1 - , in § 4.4 - , in § 5.2 - style features , in § 5.2 - , in § 4.4 - , in § 4.4 - width , in § 5.1.1 ### Terms defined by reference - [CSS-ANIMATIONS-1] defines the following terms: - @keyframes - [CSS-BOX-4] defines the following terms: - content box - [CSS-BREAK-3] defines the following terms: - fragmentation - [CSS-CASCADE-5] defines the following terms: - @layer - cascade-dependent keyword - computed value - initial value - longhand property - revert - revert-layer - shorthand - shorthand property - [CSS-CONDITIONAL-3] defines the following terms: - @supports - CSSConditionRule - conditional group rule - css feature queries - [CSS-CONTAIN-1] defines the following terms: - contain - layout containment - size containment - [CSS-CONTAIN-2] defines the following terms: - content-visibility - layout containment box - style containment - [CSS-DISPLAY-3] defines the following terms: - atomic inline - display - formatting context - inline-level - inner display type - internal ruby box - internal table box - principal box - table - [CSS-FONTS-4] defines the following terms: - font-size - [CSS-FONTS-5] defines the following terms: - @font-face - [CSS-PSEUDO-4] defines the following terms: - ::after - ::before - ::file-selector-button - ::first-letter - ::first-line - ::marker - ::placeholder - fictional tag sequence - [CSS-SCOPING-1] defines the following terms: - ::slotted() - [CSS-SHADOW-PARTS-1] defines the following terms: - ::part() - [CSS-SIZING-3] defines the following terms: - height - intrinsic size - min-content size - min-width - size - width - [CSS-SIZING-4] defines the following terms: - aspect-ratio - [CSS-SYNTAX-3] defines the following terms: - - at-rule - declaration - style rule - [CSS-TRANSITIONS-1] defines the following terms: - style change event - [CSS-VALUES-4] defines the following terms: - * - + - - - - - ? - css-wide keywords - em - identifier - relative length - small viewport size - | - || - [CSS-WRITING-MODES-4] defines the following terms: - block axis - block size - block-axis - inline axis - inline size - inline-axis - inline-size - [CSS2] defines the following terms: - line-height - [CSSOM-VIEW-1] defines the following terms: - MediaQueryList - matchMedia(query) - [DOM] defines the following terms: - shadow-including descendant - shadow-including inclusive ancestor - [FULLSCREEN] defines the following terms: - ::backdrop - [MEDIAQUERIES-5] defines the following terms: - - media feature - media query - not - [SELECTORS-4] defines the following terms: - ultimate originating element - [WEB-ANIMATIONS-1] defines the following terms: - effect value - [WEBIDL] defines the following terms: - Exposed ## References ### Normative References [CSS-ANIMATIONS-1] Dean Jackson; et al. [CSS Animations Level 1](https://www.w3.org/TR/css-animations-1/). 11 October 2018. WD. URL: [https://www.w3.org/TR/css-animations-1/](https://www.w3.org/TR/css-animations-1/) [CSS-BOX-4] Elika Etemad. [CSS Box Model Module Level 4](https://www.w3.org/TR/css-box-4/). 21 April 2020. WD. URL: [https://www.w3.org/TR/css-box-4/](https://www.w3.org/TR/css-box-4/) [CSS-BREAK-3] Rossen Atanassov; Elika Etemad. [CSS Fragmentation Module Level 3](https://www.w3.org/TR/css-break-3/). 4 December 2018. CR. URL: [https://www.w3.org/TR/css-break-3/](https://www.w3.org/TR/css-break-3/) [CSS-CASCADE-4] CSS Cascading and Inheritance Level 4 URL: [https://www.w3.org/TR/css-cascade-4/](https://www.w3.org/TR/css-cascade-4/) [CSS-CASCADE-5] Elika Etemad; Miriam Suzanne; Tab Atkins Jr.. [CSS Cascading and Inheritance Level 5](https://www.w3.org/TR/css-cascade-5/). 13 January 2022. CR. URL: [https://www.w3.org/TR/css-cascade-5/](https://www.w3.org/TR/css-cascade-5/) [CSS-CONDITIONAL-3] David Baron; Elika Etemad; Chris Lilley. [CSS Conditional Rules Module Level 3](https://www.w3.org/TR/css-conditional-3/). 13 January 2022. CR. URL: [https://www.w3.org/TR/css-conditional-3/](https://www.w3.org/TR/css-conditional-3/) [CSS-CONTAIN-1] Tab Atkins Jr.; Florian Rivoal. [CSS Containment Module Level 1](https://www.w3.org/TR/css-contain-1/). 22 December 2020. REC. URL: [https://www.w3.org/TR/css-contain-1/](https://www.w3.org/TR/css-contain-1/) [CSS-CONTAIN-2] CSS Containment Module Level 2 URL: [https://drafts.csswg.org/css-contain-2/](https://drafts.csswg.org/css-contain-2/) [CSS-DISPLAY-3] Tab Atkins Jr.; Elika Etemad. [CSS Display Module Level 3](https://www.w3.org/TR/css-display-3/). 3 September 2021. CR. URL: [https://www.w3.org/TR/css-display-3/](https://www.w3.org/TR/css-display-3/) [CSS-FONTS-5] Myles Maxfield; Chris Lilley. [CSS Fonts Module Level 5](https://www.w3.org/TR/css-fonts-5/). 21 December 2021. WD. URL: [https://www.w3.org/TR/css-fonts-5/](https://www.w3.org/TR/css-fonts-5/) [CSS-SIZING-3] Tab Atkins Jr.; Elika Etemad. [CSS Box Sizing Module Level 3](https://www.w3.org/TR/css-sizing-3/). 17 December 2021. WD. URL: [https://www.w3.org/TR/css-sizing-3/](https://www.w3.org/TR/css-sizing-3/) [CSS-SYNTAX-3] Tab Atkins Jr.; Simon Sapin. [CSS Syntax Module Level 3](https://www.w3.org/TR/css-syntax-3/). 24 December 2021. CR. URL: [https://www.w3.org/TR/css-syntax-3/](https://www.w3.org/TR/css-syntax-3/) [CSS-TRANSITIONS-1] David Baron; et al. [CSS Transitions](https://www.w3.org/TR/css-transitions-1/). 11 October 2018. WD. URL: [https://www.w3.org/TR/css-transitions-1/](https://www.w3.org/TR/css-transitions-1/) [CSS-VALUES-3] Tab Atkins Jr.; Elika Etemad. [CSS Values and Units Module Level 3](https://www.w3.org/TR/css-values-3/). 6 June 2019. CR. URL: [https://www.w3.org/TR/css-values-3/](https://www.w3.org/TR/css-values-3/) [CSS-VALUES-4] Tab Atkins Jr.; Elika Etemad. [CSS Values and Units Module Level 4](https://www.w3.org/TR/css-values-4/). 16 December 2021. WD. URL: [https://www.w3.org/TR/css-values-4/](https://www.w3.org/TR/css-values-4/) [CSS-WRITING-MODES-4] Elika Etemad; Koji Ishii. [CSS Writing Modes Level 4](https://www.w3.org/TR/css-writing-modes-4/). 30 July 2019. CR. URL: [https://www.w3.org/TR/css-writing-modes-4/](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](https://www.w3.org/TR/CSS21/). 7 June 2011. REC. URL: [https://www.w3.org/TR/CSS21/](https://www.w3.org/TR/CSS21/) [CSSOM-VIEW-1] Simon Pieters. [CSSOM View Module](https://www.w3.org/TR/cssom-view-1/). 17 March 2016. WD. URL: [https://www.w3.org/TR/cssom-view-1/](https://www.w3.org/TR/cssom-view-1/) [DOM] Anne van Kesteren. [DOM Standard](https://dom.spec.whatwg.org/). Living Standard. URL: [https://dom.spec.whatwg.org/](https://dom.spec.whatwg.org/) [MEDIAQUERIES-5] Dean Jackson; et al. [Media Queries Level 5](https://www.w3.org/TR/mediaqueries-5/). 18 December 2021. WD. URL: [https://www.w3.org/TR/mediaqueries-5/](https://www.w3.org/TR/mediaqueries-5/) [RFC2119] S. Bradner. [Key words for use in RFCs to Indicate Requirement Levels](https://datatracker.ietf.org/doc/html/rfc2119). March 1997. Best Current Practice. URL: [https://datatracker.ietf.org/doc/html/rfc2119](https://datatracker.ietf.org/doc/html/rfc2119) [SELECTORS-4] Elika Etemad; Tab Atkins Jr.. [Selectors Level 4](https://www.w3.org/TR/selectors-4/). 7 May 2022. WD. URL: [https://www.w3.org/TR/selectors-4/](https://www.w3.org/TR/selectors-4/) [WEB-ANIMATIONS-1] Brian Birtles; et al. [Web Animations](https://www.w3.org/TR/web-animations-1/). 18 May 2021. WD. URL: [https://www.w3.org/TR/web-animations-1/](https://www.w3.org/TR/web-animations-1/) [WEBIDL] Edgar Chen; Timothy Gu. [Web IDL Standard](https://webidl.spec.whatwg.org/). Living Standard. URL: [https://webidl.spec.whatwg.org/](https://webidl.spec.whatwg.org/) ### Informative References [CSS-FONTS-4] John Daggett; Myles Maxfield; Chris Lilley. [CSS Fonts Module Level 4](https://www.w3.org/TR/css-fonts-4/). 21 December 2021. WD. URL: [https://www.w3.org/TR/css-fonts-4/](https://www.w3.org/TR/css-fonts-4/) [CSS-PSEUDO-4] Daniel Glazman; Elika Etemad; Alan Stearns. [CSS Pseudo-Elements Module Level 4](https://www.w3.org/TR/css-pseudo-4/). 31 December 2020. WD. URL: [https://www.w3.org/TR/css-pseudo-4/](https://www.w3.org/TR/css-pseudo-4/) [CSS-SCOPING-1] Tab Atkins Jr.; Elika Etemad. [CSS Scoping Module Level 1](https://www.w3.org/TR/css-scoping-1/). 3 April 2014. WD. URL: [https://www.w3.org/TR/css-scoping-1/](https://www.w3.org/TR/css-scoping-1/) [CSS-SHADOW-PARTS-1] Tab Atkins Jr.; Fergal Daly. [CSS Shadow Parts](https://www.w3.org/TR/css-shadow-parts-1/). 15 November 2018. WD. URL: [https://www.w3.org/TR/css-shadow-parts-1/](https://www.w3.org/TR/css-shadow-parts-1/) [CSS-SIZING-4] Tab Atkins Jr.; Elika Etemad; Jen Simmons. [CSS Box Sizing Module Level 4](https://www.w3.org/TR/css-sizing-4/). 20 May 2021. WD. URL: [https://www.w3.org/TR/css-sizing-4/](https://www.w3.org/TR/css-sizing-4/) [FULLSCREEN] Philip Jägenstedt. [Fullscreen API Standard](https://fullscreen.spec.whatwg.org/). Living Standard. URL: [https://fullscreen.spec.whatwg.org/](https://fullscreen.spec.whatwg.org/) ## Property Index | Name | Value | Initial | Applies to | Inh. | %ages | Anim­ation type | Canonical order | Com­puted value container <'container-name'> [ / <'container-type'> ]? see individual properties see individual properties see individual properties see individual properties see individual properties per grammar see individual properties container-name none \| + none all elements no n/a not animatable per grammar the keyword none, or an ordered list of identifiers container-type normal \|\| [ size \| inline-size ] normal all elements no n/a not animatable per grammar the keyword normal or one or more of size, inline-size | | --- | --- | --- | --- | --- | --- | --- | --- | --- | | container <'container-name'> [ / <'container-type'> ]? see individual properties see individual properties see individual properties see individual properties see individual properties per grammar see individual properties | | | | | | | | | | container-name none \| + none all elements no n/a not animatable per grammar the keyword none, or an ordered list of identifiers | | | | | | | | | | container-type normal \|\| [ size \| inline-size ] normal all elements no n/a not animatable per grammar the keyword normal or one or more of size, inline-size | | | | | | | | | ### @container Descriptors | Name | Value | Initial | Type aspect-ratio range block-size range height range inline-size range orientation portrait \| landscape discrete width range | | --- | --- | --- | --- | | aspect-ratio range | | | | | block-size range | | | | | height range | | | | | inline-size range | | | | | orientation portrait \| landscape discrete | | | | | width range | | | | ## IDL Index ``` [Exposed=Window] interface CSSContainerRule : CSSConditionRule { }; ``` ## Issues Index This is a diff spec over [CSS Containment Level 2](https://www.w3.org/TR/css-contain-2/) . It is currently an Exploratory Working Draft: if you are implementing anything, please use Level 2 as a reference. We will merge the Level 2 text into this draft once it reaches CR. ↵ [CSS Containment 2 § 2 Strong Containment: the contain property](https://drafts.csswg.org/css-contain-2/#contain-property) ↵ [CSS Containment 2 § 3 Types of Containment](https://drafts.csswg.org/css-contain-2/#containment-types) ↵ In general, the relationship between an element’s inline size and it’s block size is unpredictable and non-monotonic, with the block size capable of shifting up and down arbitrarily as the inline size is changed. Infinite cycles are prevented by ensuring that layout does not revert to a previous (known-problematic) state, even if a naive analysis of the constraints would allow for such; in other words, layout always “moves forward”. We believe that current CSS layout specifications incorporate such rules, but to the extent that they don’t, please [inform the CSSWG](https://github.com/w3c/csswg-drafts/issues) so that these errors can be corrected. ↵ Add CSSOM API for CSSContainerRule [[Issue #7033]](https://github.com/w3c/csswg-drafts/issues/7033) ↵ Container Queries should have a `matchContainer` method. This will be modeled on `[matchMedia()](https://www.w3.org/TR/cssom-view/#dom-window-matchmedia)` and the `[MediaQueryList](https://www.w3.org/TR/cssom-view/#mediaquerylist)` interface, but applied to Elements rather than the Window. When measuring layout sizes, it behaves Similar to `resizeObserver` , but it provides the additional Container Query syntax and features. [[Issue #6205]](https://github.com/w3c/csswg-drafts/issues/6205) ↵ [CSS Containment 2 § 4 Suppressing An Element’s Contents Entirely: the content-visibility property](https://drafts.csswg.org/css-contain-2/#content-visibility) ↵ [CSS Containment 2 § 5 Privacy and Security Considerations](https://drafts.csswg.org/css-contain-2/#priv-sec) ↵ [CSS Containment 2 §  Changes](https://drafts.csswg.org/css-contain-2/#changes) ↵