CKTIS / CSS
contain — isolating rendering effects
The contain property limits dependencies between an element and the rest of the document during sizing, layout, styling, and painting. It can enable optimizations, but it changes rendering behavior.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
contain: none | strict | content | [ [ size | inline-size ] || layout || style || paint ];contain establishes specific containment boundaries around a subtree. Its initial value is none; it is neither inherited nor animatable. It does not guarantee faster rendering.
size determines intrinsic sizes as if the element were empty; inline-size does this only in the inline axis, preserving content influence in the block axis. layout establishes an independent formatting context. paint clips descendant painting to the overflow clip edge. style scopes effects such as counter operations, but does not isolate selectors or inheritance.
You can combine keywords in any order without repetition; size and inline-size are mutually exclusive. none, strict, and content stand alone. In Level 2, strict means size layout style paint, and content means layout style paint; Level 1 omits style from both shorthands.
Be careful: layout and paint create a stacking context and a containing block for descendants with position: absolute and position: fixed. size can collapse an automatic height to zero; provide suitable dimensions or use contain-intrinsic-size. Individual containment types have box-type-specific applicability restrictions.
The example demonstrates that size neither removes nor clips content: #box has a height of 0px, while #child remains 40px tall and overflows its parent.
Examples
<!doctype html>
<meta charset="utf-8">
<title>contain: size</title>
<style>
#box { contain: size; width: 120px; }
#child { height: 40px; background: teal; }
</style>
<div id="box"><div id="child"></div></div>
<pre id="result"></pre>
<script>
const box = document.getElementById('box');
const child = document.getElementById('child');
document.getElementById('result').textContent =
`box: ${box.offsetHeight}px; child: ${child.offsetHeight}px`;
</script>Result
box: 0px; child: 40px
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.