CSS Containment Module Level 2

Editor’s Draft,

More details about this document
This version:
https://drafts.csswg.org/css-contain-2/
Latest published version:
https://www.w3.org/TR/css-contain-2/
Previous Versions:
Test Suites:
https://test.csswg.org/harness/results/css-contain-1_dev/
https://wpt.fyi/results/css/css-contain/
Feedback:
CSSWG Issues Repository
Inline In Spec
Editors:
Tab Atkins (Google)
Florian Rivoal (On behalf of Bloomberg)
(Google)
Suggest an Edit for this Spec:
GitHub Editor

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 18 August 2025 W3C Process 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.

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

1.1. Module Interactions

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

1.2. Value Definitions

This specification follows the CSS property definition conventions from [CSS2] using the value definition syntax from [CSS-VALUES-3]. Value types not defined in this specification are defined in CSS Values & Units [CSS-VALUES-3]. Combination with other CSS modules may expand the definitions of these value types.

In addition to the property-specific values listed in their definitions, all properties defined in this specification also accept the CSS-wide keywords as their property value. For readability they have not been repeated explicitly.

2. Strong Containment: the contain property

Tests

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


Name: contain
Value: none | strict | content | [ [size | inline-size] || layout || style || paint ]
Initial: none