Working Draft · css-contain

CSS Containment

2 properties defined by this specification, all known to at least one browser .

Each feature in detail

contain

Property Baseline: widely availablesince September 2024

MDN The contain CSS property indicates that an element and its contents are, as much as possible, independent from the rest of the document tree. Containment enables isolating a subsection of the DOM, providing performance benefits by limiting calculations of layout, style, paint, size, or any combination to a DOM subtree rather than the entire page. Containment can also be used to scope CSS counters and quotes.

Live preview Example from MDN
h2 {
  margin-top: 0;
}

#default-example {
  text-align: left;
  padding: 4px;
  font-size: 16px;
}

.card {
  text-align: left;
  border: 3px dotted;
  padding: 20px;
  margin: 10px;
  width: 85%;
  min-height: 150px;
}

.fixed {
  position: fixed;
  border: 3px dotted;
  right: 4px;
  padding: 4px;
  margin: 4px;
}

Syntax

none | strict | content | [ [size | inline-size] || layout || style || paint ]

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

Initial
none
Applies to
See below
Inherited
no
Percentages
n/a
Computed value
the keyword none or one or more of size, layout, style, paint
Canonical order
per grammar
Animation type
not animatable

Browser support

First browser version supporting contain
Chrome 52
Edge 79
Firefox 69
Safari 15.4
Chrome Android 52
Safari iOS 15.4

First version with support, from MDN browser-compat-data.

content-visibility

Property Baseline: newly availablesince September 2025 Modern CSS: content-visibilityModern CSS: display animation

MDN The content-visibility CSS property controls whether or not an element renders its contents at all, along with forcing a strong set of containments, allowing user agents to potentially omit large swathes of layout and rendering work until it becomes needed. It enables the user agent to skip an element's rendering work (including layout and painting) until it is needed — which makes the initial page load much faster.

Live preview Example from MDN
.container {
  width: 140px;
  height: 140px;
  border: 3px solid rgb(64 28 163);
  background-color: rgb(135 136 184);
  display: flex;
  align-items: center;
  justify-content: center;
}

.child {
  border: 3px solid rgb(64 28 163);
  background-color: wheat;
  color: black;
  width: 80%;
  height: 80%;
  display: flex;
  align-items: center;
  justify-content: center;
}

Syntax

visible | auto | hidden

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

Initial
visible
Applies to
elements for which size containment can apply
Inherited
no
Percentages
n/a
Computed value
as specified
Canonical order
per grammar
Animation type
see § 4.1 Animating and Interpolating content-visibility

Browser support

First browser version supporting content-visibility
Chrome 85
Edge 85
Firefox 125
Safari 18
Chrome Android 85
Safari iOS 18

First version with support, from MDN browser-compat-data.