A 300-row seating list for the evening show with content-visibility: auto: a chair is set out when the browser renders its row and folded when it skips it…
Why it matters
Long lists (feeds, tables, comments) are expensive to render though only part is seen. One CSS line cuts that work with no library, and the DOM stays whole for Ctrl+F and screen readers. The catch: an estimated size with contain-intrinsic-size, so the scrollbar does not jump and not every row is rendered when first seen.
The key idea
Skipped, not removed
Common mistakes
The scrollbar jumps with content-visibility: auto Without contain-intrinsic-size, an element never rendered is 0 tall, then grows when rendered; when the page opens they all stack up on screen, so all of them are rendered first. Give it an estimated size: contain-intrinsic-size: auto 44px.
On elements always on screen, it does nothing Elements on screen are never skipped, so nothing is saved, and the containment still has a cost. Use it on long parts that are mostly off screen.
Taken for a virtual list content-visibility removes no nodes: they all stay in the DOM, findable and readable by screen readers, but the node count does not drop. For tens of thousands of rows, a virtual list is still needed.
Try it in this playground
Scroll the list with content-visibility: auto Of 300 rows, only those near the screen are rendered: the chairs stand and fold as you scroll.
Open the list with no contain-intrinsic-size Before it is rendered every row is 0 tall, so all of them are “in view” and rendered first.
Open The four front seats What is always seen is never skipped.
Time the layout with and without auto A forced layout is much quicker when rows off screen are skipped.