CSS Containment Reference

contain, content-visibility and @container query syntax with every containment type.

Reference for CSS containment — the contain property values (layout, paint, size, style, inline-size), content-visibility, contain-intrinsic-size and @container query syntax for container queries.

What does the contain property do?

It tells the browser that an element's subtree is independent of the rest of the page for layout, paint, size or style. This lets the engine skip work outside the element when something inside changes, improving rendering performance on large or dynamic pages.

Isolate subtrees for faster rendering

CSS containment lets you promise the browser that an element’s subtree is independent of the rest of the document, so the engine can skip work when that subtree changes. This reference covers the contain keywords, the content-visibility shortcut, intrinsic sizing and @container query syntax.

How it works

The contain property accepts one or more independent keywords, plus the shorthands content (layout paint style) and strict (layout paint style size):

.widget { contain: layout paint; }      /* isolate layout + paint */
.card   { content-visibility: auto;      /* skip off-screen render */
          contain-intrinsic-size: auto 200px; }
.panel  { container-type: inline-size; } /* become a query container */

@container (min-width: 40rem) {
  .panel .title { font-size: 1.5rem; }
}

content-visibility: auto applies layout paint size containment and skips rendering until the element nears the viewport; contain-intrinsic-size supplies a placeholder size so scrolling stays stable.

Tips and notes

  • contain: size collapses an element with no explicit dimensions — prefer inline-size for container queries.
  • content-visibility: auto is the highest-leverage value for long lists; always pair it with contain-intrinsic-size.
  • container-type: inline-size enables width-based @container queries without breaking block height; container-type: size requires a fixed height too.
  • Name containers with container-name to target a specific ancestor: @container sidebar (min-width: …).
  • Containment can hide overflow and break position: fixed descendants — test sticky/fixed children after applying it.