Under The Hood
frontend css CSS Containment Level 2 (content-visibility, Chrome 85+)

content-visibility: auto: Skipping Off-Screen Layout & Paint

Last updated
Prerequisites:
CSS containment (contain property)
Understanding of layout, paint, and the rendering pipeline
  • css
  • content-visibility
  • rendering
  • performance
  • containment
  • layout

Read at your depth

The practical view

content-visibility: auto on a section tells the browser to skip rendering (layout + paint + some style work) for that section while it is off-screen, then render it when it approaches the viewport. .feed-item { content-visibility: auto; contain-intrinsic-size: auto 500px; }. This dramatically speeds up long pages (feeds, docs, lists). The contain-intrinsic-size gives the browser an estimated size for off-screen elements so the scrollbar stays roughly correct. It is a pure-CSS performance win for long scrollable content — no virtualization JS needed.

The same idea in other frameworks

react equivalent
React long lists can use content-visibility: auto instead of windowing when item heights are predictable.

Legacy vs modern

Rendering every list item vs skipping off-screen items

Without content-visibility, the browser lays out and paints the entire list; with it, only items near the viewport render, and intrinsic sizes keep the scrollbar stable.

before → after
All items always rendered
.item { /* ❌ OLD: every item is laid out and painted regardless of visibility */ }
content-visibility: auto per item
.item { content-visibility: auto; contain-intrinsic-size: auto 120px; } /* ✅ NEW */

Interview gotchas

Context

Interviewers use this to check whether you understand the layout implications of skipping — the collapse bug is the classic mistake that breaks layouts.

The mechanical answer

content-visibility: auto applies size-like skipping: while an element is off-screen, the engine does not lay out its subtree, so it has no real height. Without contain-intrinsic-size, the element's height computes as zero (its content is not measured), collapsing the page — the scrollbar shrinks and items pile up. contain-intrinsic-size supplies a proxy size: a fixed value (e.g. 500px) or auto (the engine remembers the last rendered size and uses it while skipped). The layout stays stable because the engine can position the element without measuring its skipped contents, and when it unskips, the real size replaces the proxy. This is the deliberate trade-off: you trade exact initial sizing for dramatically reduced rendering work.

Trap

The naive answer is 'content-visibility: auto is free'. Without contain-intrinsic-size, layouts collapse — the most common production bug with this property. Another trap: using a fixed contain-intrinsic-size on variable-height content causes scroll jumps when items unskip to their real (different) sizes; 'auto' mitigates this by remembering rendered sizes. Candidates who can explain the sizing proxy and the unskip behavior show real understanding.

Under The Hood — a multi-depth technical interview hub.

Third-party licenses Press ⌘ K to search.