CSS Reference ยท Box Model and Sizing
The content-visibility property
Reference for the CSS content-visibility property: skip layout and paint of offscreen content to speed up long pages. Values, auto, hidden, examples and notes.
The content-visibility property lets the browser skip the rendering work of an element's contents until they are needed. On a long page made of many independent sections, content-visibility: auto can make the first load noticeably faster, because off-screen sections are not laid out or painted until the user scrolls near them.
.section { content-visibility: auto; contain-intrinsic-size: auto 600px; }
Try it
While content-visibility: hidden is applied, panel 2 shows only its box at the placeholder size; its contents are skipped. Toggling the class makes the text appear.
Syntax
content-visibility: visible | auto | hidden
- Initial value:
visible - Applies to: elements for which size containment can apply
- Inherited: no
- Animatable: yes (discrete), and it can be used in transitions with
transition-behavior: allow-discrete - Computed value: as specified
Values
| Value | Description |
|---|---|
visible |
No effect: the element's contents are rendered as usual. |
auto |
The element gets layout, style and paint containment. Its contents are skipped while it is off screen (and not focused, selected or the target of anchor navigation) and rendered when it is near the viewport. Skipped content stays searchable and reachable by find-in-page. |
hidden |
The contents are skipped always, like display: none but the browser keeps their rendering state so showing them again is cheap. The content is not searchable or focusable. |
Usage notes
- Set a placeholder size. A skipped element has size containment, so it collapses to its border and padding. Add
contain-intrinsic-size(for exampleauto 600px) so the scrollbar does not jump. autostays accessible. Skipped content remains in the accessibility tree, and in-page search finds text inside it.hiddendoes not.- Apply to large, independent blocks such as article sections or feed items, not to tiny elements. Only measure-proven pages benefit from it.
- Side effects of containment. Because
autoapplies layout and paint containment, descendants cannot paint outside the box and fixed-position children are anchored to it. - Faster show/hide.
hiddensuits tabs and off-screen panels that you switch often, since it avoids the cost of rebuilding rendering state.
Browser support
auto is supported in current versions of Chromium-based browsers, Firefox and Safari. hidden and the discrete animation behavior arrived a little later in some browsers, so check support tables for older versions.