This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.
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 the browser to recalculate layout, style, paint, size, or any combination of them for a limited area of the DOM and not the entire page.
/* No layout containment. */ contain: none; /* Turn on containment for layout, style, paint, and size. */ contain: strict; /* Turn on containment for layout, style, and paint. */ contain: content; /* Turn on size containment for an element. */ contain: size; /* Turn on layout containment for an element. */ contain: layout; /* Turn on style containment for an element. */ contain: style; /* Turn on paint containment for an element. */ contain: paint;
This property is useful on pages that contain a lot of widgets that are all independent as it can be used to prevent one widget's CSS rules from changing other things on the page.
|Applies to||all elements|
|Computed value||as specified|
|Canonical order||per grammar|
- Indicates the element renders as normal, with no containment applied.
- Indicates that all containment rules are applied to the element. This is equivalent to
contain: size layout style paint.
- Indicates that all containment rules except size are applied to the element. This is equivalent to
contain: layout style paint.
- Indicates that the element can be sized without the need to examine its dependants for size changes.
- Indicates that nothing outside the element may affect its internal layout and vice versa.
- Indicates that, for properties that can have effects on more than just an element and its descendants, those effects don't escape the containing element.
- Indicates that descendents of the element don't display outside its bounds. If an element is off-screen or otherwise not visible, it's descendants are also guaranteed to not be visible.
|CSS Containment Module Level 1||Working Draft||Initial definition|
|Feature||Chrome||Firefox (Gecko)||Internet Explorer||Opera||Safari (WebKit)|
|Basic support||52.0||No support||?||40||?|
|Feature||Android Webview||Chrome for Android||Firefox Mobile (Gecko)||Firefox OS||IE Mobile||Opera Mobile||Safari Mobile|
|Basic support||52.0||52.0||No support||?||?||40||?|
 This feature implemented behind the preference
layout.css.contain.enabled, defaulting to
false, currently only supporting the values
paint (see bug 1170781). See bug 1150081 for the overall implementation status.