Browsers often perform layout, styling, and paint work for elements far below the viewport, even when users only view top-level content. To address this overhead, the CSS property content-visibility: auto allows browsers to skip rendering off-screen DOM subtrees until they become relevant to the user.
How content-visibility Manages Off-Screen Subtrees
Applying content-visibility: auto leverages browser containment to skip layout, style, and paint work for elements outside the viewport. The element remains in the DOM and its network resources are not deferred by this rule alone, distinguishing it from lazy loading resources. Instead, it instructs the browser engine to avoid rendering work for content that is not yet visible.
In a controlled test conducted by freeCodeCamp using 150 complex HTML cards without frameworks, applying content-visibility: auto reduced initial Chrome DevTools Rendering activity from 42 ms to 20 ms. The author noted that this measurement reflects initial devtools rendering time rather than overall page load speed or Core Web Vitals, and performance gains will vary depending on layout complexity, device, and viewport size.
Managing Layout Stability with contain-intrinsic-size
Skipping off-screen rendering can introduce layout shifts because the browser lacks explicit geometry for skipped nodes. Developers manage this space by pairing content-visibility with contain-intrinsic-size. For example, using contain-intrinsic-size: auto 900px supplies a fallback size when content is skipped and allows the browser to remember actual rendered dimensions once an element scrolls into view.
In freeCodeCamp's test, adding explicit intrinsic size fallbacks altered the initial rendering measurements further down to a 10 ms median. However, selecting an inaccurate fallback height may cause geometric adjustments when off-screen nodes scroll into view and render their true dimensions.
Accessibility and Deployment Boundaries
While rendering for off-screen subtrees is skipped, elements under content-visibility: auto can still remain accessible within the browser's accessibility tree. Because of this behavior, it should not be relied upon to semantically hide elements from assistive technologies. Furthermore, deferring initial render work does not eliminate processing entirely; deferred work is performed when elements scroll into the viewport.
The content-visibility property achieved broad cross-browser compatibility as part of Baseline 2024. It provides the highest value on DOM-heavy pages with extensive off-screen content, such as long product listings, article feeds, or multi-section dashboards.
AI-generated editorial illustration; not a documentary photograph.
Source:
How CSS content-visibility Works and How It Can Improve Rendering Performance

Leave a Reply