content-visibility & Skipping Offscreen Work
content-visibility: auto instructs the engine to skip Style, Layout, and Paint for off-screen subtrees until they approach the viewport. Paired with contain-intrinsic-size: auto, it slashes initial rendering cost without removing nodes from the DOM or breaking Ctrl+F search.
Eager Off-Screen Rendering vs content-visibility: auto
Compare initial frame cost on a 200-section document.
.article-section {
margin-bottom: 2rem;
/* All 200 sections laid out & painted at load */
}Main thread blocks on off-screen sections nobody sees yet.
.article-section {
content-visibility: auto;
contain-intrinsic-size: auto 420px;
}Off-screen sections reserve 420px and skip Layout/Paint.
Under the Hood
Like a stage crew only lighting sets as actors walk toward them, content-visibility: auto keeps DOM nodes intact while deferring pixel work.
- Relevance Check: The engine checks whether the element is near the viewport, focused, or selected.
- Work Suppression: When irrelevant, it enforces CSS Containment (
layout,style,paint,size) and skips Render Tree & Layout for descendants. - Placeholder Sizing:
contain-intrinsic-size: auto 400pxsupplies a fallback height until the element renders once, after whichautoremembers its real measured height.
.long-list-chunk {
content-visibility: auto;
/* Remembers real height after first render; 360px before */
contain-intrinsic-size: auto 360px;
}Problem Genealogy
- 2015–2019: Developers built fragile JS virtual-scrollers that broke browser
Ctrl+F, anchor links, and screen-reader navigation. - 2020–2024:
content-visibility: automoved off-screen work skipping into the native C++ layout engine.
Production Pitfalls
- Missing
contain-intrinsic-size: Without an intrinsic size hint, skipped containers collapse to0px, causing the scrollbar thumb to jump as you scroll. - One giant wrapper: Wrapping 10,000 items in a single
content-visibility: autocontainer defeats incremental rendering; chunk them into groups of 25–50.
- When not to use
content-visibility: auto: Do not apply it to small above-the-fold elements or containers with overflowing popovers (it impliescontain: paint).
Connections & Logical Next Steps
content-visibility: auto internally activates layout, style, and paint containment.
Skipped subtrees retain their DOM nodes but bypass Layout and Paint until near the viewport.
content-visibility: auto skips Layout and Paint for offscreen subtrees instead of running the full pipeline.