What does content-visibility: auto do, and when is it better than virtualisation?
IntermediateCSS interview questionBy UIRound, updated 23 November 2026
Short answer
content-visibility: auto tells the browser it may skip rendering an element's contents (style, layout and paint) while the element is off-screen, and render them just in time as it approaches the viewport. The content stays in the DOM, so find-in-page, anchor links, tab order and screen readers still work. It beats virtualisation when rendering is the cost; virtualisation wins when the number of DOM nodes itself is the problem.
What the browser skips
Normally the browser styles, lays out and paints every element on the page, including sections thousands of pixels below the fold. On a long article, a documentation page or a feed of a few hundred cards, that work dominates the first render and every later full-page layout.
.feed-item {
content-visibility: auto;
contain-intrinsic-size: auto 480px;
}With auto, each .feed-item always gets layout, style and paint containment, so changes inside it cannot affect the rest of the page. While it is not relevant to the user (off-screen, not focused, not selected), it also gets size containment and the browser skips its subtree entirely. When it nears the viewport, the browser renders it before it is painted. The page looks the same; the browser just does less. The containment rules underneath are explained in the practice question on cheap selectors and CSS containment, and reflow vs repaint covers the work being avoided.
The other values: visible is the default, and hidden always skips the contents (like display: none, but the rendering state is kept, so showing it again is cheap).
contain-intrinsic-size: avoiding a collapsing scrollbar
A skipped element is laid out as if it had no contents, which means zero height. A page of zero-height sections has a tiny scrollbar that grows and jumps as you scroll. contain-intrinsic-size gives skipped elements a placeholder size:
contain-intrinsic-size: 480pxuses that size whenever the element is skipped.contain-intrinsic-size: auto 480pxuses 480px until the element has rendered once, then remembers its last rendered size and uses that. This is almost always what you want, because real items vary in height.
Pick a placeholder close to a typical item. The closer it is, the less the scrollbar moves as items render in.
Why it keeps what virtualisation loses
List virtualisation removes off-screen items from the DOM and renders only a window of rows. That saves DOM nodes, memory and framework render time, but the content is gone:
content-visibility: auto |
Virtualisation | |
|---|---|---|
| Off-screen content in the DOM | Yes | No |
| Find-in-page (Ctrl+F) | Works, the browser renders the match | Only finds rendered rows |
Anchor links and scrollIntoView |
Work | Need custom code |
| Screen readers and tab order | Content stays in the accessibility tree | Missing items; needs ARIA counts and care |
| Variable heights | Free, measured by the browser | Measurement and position caches |
| DOM nodes, memory, JS render cost | Unchanged | Constant, small |
| Effort | Two CSS lines | A library or a component, plus edge cases |
That table is the decision. If the page has a few hundred to a few thousand heavy sections and the slow part is style and layout, content-visibility: auto gets much of the benefit for almost no cost and keeps native behaviour. Search engines and the browser's own features still see the content.
When virtualisation is still the answer
content-visibility does not reduce the DOM. Every node is still created, kept in memory and, in a framework, rendered and reconciled. So it does not help when:
- The list is very long, such as tens of thousands of rows in a log viewer, a spreadsheet or a chat history. Creating the nodes is already too slow, and memory grows without limit. That is what a virtualised list of 100,000 items solves.
- The cost is JavaScript, not rendering: React re-rendering 5,000 rows on every keystroke is just as slow with the rows skipped by CSS.
- Script that walks the whole document, such as
querySelectorAllover every row or a mutation observer on the list, is the bottleneck, since it still touches every node.
A common combination is to paginate or load more on the server, use content-visibility: auto within each loaded page, and reach for virtualisation only when the data really is huge. A news feed with infinite scroll and a virtualised list component for a design system explore both ends.
Gotchas
- Paint containment clips. Box shadows, dropdowns and tooltips that overflow the element are cut off. Apply it to self-contained blocks, not to wrappers of menus.
- Containing block. Layout containment makes the element the containing block for
position: fixeddescendants, so a fixed toast rendered inside a card is positioned relative to the card. - Do not use it above the fold. On-screen elements are rendered anyway, and the containment only adds risk.
- Reading layout forces rendering. Calling
getBoundingClientRect()oroffsetHeighton content inside a skipped element makes the browser render it, losing the saving. - Measure. Compare a Performance panel trace before and after; the rendering time of the first load should drop.
Browser support: content-visibility is in Chromium, Firefox (from version 125) and Safari (from version 18), so it is Baseline. Browsers without it ignore the property and render normally, so it is a safe progressive enhancement.
Follow-up questions interviewers ask
How is content-visibility: auto different from loading="lazy"?
loading="lazy" delays downloading images and iframes. content-visibility: auto delays rendering work for any content that is already in the DOM. They solve different costs and combine well.
Can JavaScript tell when a section is skipped?
Yes. Elements with content-visibility: auto fire a contentvisibilityautostatechange event whose skipped property says whether rendering is now skipped. You can pause expensive work such as canvas drawing or polling while a section is skipped.
Does it help Interaction to Next Paint?
It can, when interactions trigger large style or layout work across the page, because skipped sections are left out. It does not help when the interaction is slow because of event-handler JavaScript.
What is hidden="until-found"?
hidden="until-found"?An HTML attribute that hides content like content-visibility: hidden but lets find-in-page and fragment links reveal it, firing a beforematch event first. It suits collapsed accordion panels that should still be searchable.
Sources
Practise it in code
Interviewers rarely stop at the definition. These questions open in an editor with tests.
- Choose cheap selectors and CSS containment:
:has(),containandcontent-visibility: autoMedium30 min - Implement a virtualized list rendering 100,000 items efficientlyMedium45 minFree
- Design a news feed with infinite scrollHard60 minFree
- Design a virtualised list component for a design system: variable heights, scroll restoration and an API teams cannot misuseHard55 min