October 7th, 2024

The new CSS property that boosts your rendering performance (2020)

The `content-visibility` CSS property enhances web performance by skipping off-screen content, improving load times, and working with CSS Containment. It preserves rendering state while optimizing rendering decisions.

Read original articleLink Icon
The new CSS property that boosts your rendering performance (2020)

The new CSS property `content-visibility`, introduced in Chromium 85, significantly enhances web page rendering performance by allowing browsers to skip rendering off-screen content until it is needed. This property enables faster initial load times and improved interaction speeds with visible content. When applied, `content-visibility: auto` can lead to a remarkable 7x performance boost in rendering times, as demonstrated in a travel blog example where rendering times dropped from 232ms to 30ms. The property works in conjunction with CSS Containment, which isolates DOM subtrees, allowing browsers to optimize rendering decisions. While `content-visibility` is currently supported in Chromium, it is still being prototyped for Firefox. Developers can also use `contain-intrinsic-size` to specify the size of elements affected by size containment, ensuring that layout remains stable. Additionally, `content-visibility: hidden` allows developers to keep content unrendered while preserving its rendering state, making it useful for single-page applications and virtual scrolling. However, developers must be cautious not to call any DOM APIs that could trigger rendering for skipped subtrees. Overall, `content-visibility` offers a powerful tool for optimizing web performance while maintaining accessibility.

- `content-visibility` improves rendering performance by skipping off-screen content.

- The property can lead to significant reductions in initial load times.

- It works alongside CSS Containment for better optimization.

- Developers should avoid certain DOM API calls to maintain performance benefits.

- `content-visibility: hidden` preserves rendering state for unrendered content.

Link Icon 7 comments
By @taspeotis - 6 months

    The new CSS property that boosts your rendering performance (web.dev)
    4 points by cmpit 1 hour ago
Needs (2020)

> Last updated 2020-08-05 UTC.

By @taraparo - 6 months
why is a manual property needed. why is the browser engine not able to figure out what is off-screen?
By @kevindamm - 6 months
For those who were wondering, it is available more broadly [0] than it was when the article was written (2020).. 75+%, almost 85% on tracked desktop.

Containment spec, which `content-visibility` is built on top of, reaches around 95%, (98% mobile) [1].

[0]: https://caniuse.com/?search=content-visibility

[1] https://caniuse.com/css-containment

By @cloudking - 6 months
Great, lazy loading without JS
By @echoangle - 6 months
Unrelated to the content: who had the idea to machine-translate programming posts? The property name the post is about is localized for me, which makes no sense at all.