<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>https://web.dev/</id>
  <title>Vladimir Levin on web.dev</title>
  <updated>2026-04-15T23:21:06Z</updated>
  <author>
    <name>Vladimir Levin</name>
  </author>
  <link href="https://web.dev/authors/vladimirlevin/feed.xml" rel="self"/>
  <link href="https://web.dev/"/>
  <icon>https://web-dev.imgix.net/image/admin/dmYne3aSCS1fj5ZfL8If.jpg?auto=format</icon>
  <logo>https://web.dev/images/shared/rss-banner.png</logo>
  <subtitle>Our latest news, updates, and stories by Vladimir Levin.</subtitle>
  
  
  <entry>
    <title>`content-visibility`: the new CSS property that boosts your rendering performance</title>
    <link href="https://web.dev/content-visibility/"/>
    <updated>2020-08-05T00:00:00Z</updated>
    <id>https://web.dev/content-visibility/</id>
    <content type="html" mode="escaped">&lt;p&gt;The
&lt;a href=&quot;https://drafts.csswg.org/css-contain/#propdef-content-visibility&quot; rel=&quot;noopener&quot;&gt;&lt;code&gt;content-visibility&lt;/code&gt;&lt;/a&gt;
property, launching in Chromium 85, might be one of the most impactful new CSS
properties for improving page load performance. &lt;code&gt;content-visibility&lt;/code&gt; enables the
user agent to skip an element&#39;s rendering work, including layout and painting,
until it is needed. Because rendering is skipped, if a large portion of your
content is off-screen, leveraging the &lt;code&gt;content-visibility&lt;/code&gt; property makes the
initial user load much faster. It also allows for faster interactions with the
on-screen content. Pretty neat.&lt;/p&gt;
&lt;figure&gt;
  &lt;img alt=&quot;demo with figures representing network results&quot; decoding=&quot;async&quot; height=&quot;554&quot; loading=&quot;lazy&quot; sizes=&quot;(min-width: 800px) 800px, calc(100vw - 48px)&quot; src=&quot;https://web-dev.imgix.net/image/admin/v6WcSx9Fq76lCD0iqFCQ.jpg?auto=format&quot; srcset=&quot;https://web-dev.imgix.net/image/admin/v6WcSx9Fq76lCD0iqFCQ.jpg?auto=format&amp;w=200 200w, https://web-dev.imgix.net/image/admin/v6WcSx9Fq76lCD0iqFCQ.jpg?auto=format&amp;w=228 228w, https://web-dev.imgix.net/image/admin/v6WcSx9Fq76lCD0iqFCQ.jpg?auto=format&amp;w=260 260w, https://web-dev.imgix.net/image/admin/v6WcSx9Fq76lCD0iqFCQ.jpg?auto=format&amp;w=296 296w, https://web-dev.imgix.net/image/admin/v6WcSx9Fq76lCD0iqFCQ.jpg?auto=format&amp;w=338 338w, https://web-dev.imgix.net/image/admin/v6WcSx9Fq76lCD0iqFCQ.jpg?auto=format&amp;w=385 385w, https://web-dev.imgix.net/image/admin/v6WcSx9Fq76lCD0iqFCQ.jpg?auto=format&amp;w=439 439w, https://web-dev.imgix.net/image/admin/v6WcSx9Fq76lCD0iqFCQ.jpg?auto=format&amp;w=500 500w, https://web-dev.imgix.net/image/admin/v6WcSx9Fq76lCD0iqFCQ.jpg?auto=format&amp;w=571 571w, https://web-dev.imgix.net/image/admin/v6WcSx9Fq76lCD0iqFCQ.jpg?auto=format&amp;w=650 650w, https://web-dev.imgix.net/image/admin/v6WcSx9Fq76lCD0iqFCQ.jpg?auto=format&amp;w=741 741w, https://web-dev.imgix.net/image/admin/v6WcSx9Fq76lCD0iqFCQ.jpg?auto=format&amp;w=845 845w, https://web-dev.imgix.net/image/admin/v6WcSx9Fq76lCD0iqFCQ.jpg?auto=format&amp;w=964 964w, https://web-dev.imgix.net/image/admin/v6WcSx9Fq76lCD0iqFCQ.jpg?auto=format&amp;w=1098 1098w, https://web-dev.imgix.net/image/admin/v6WcSx9Fq76lCD0iqFCQ.jpg?auto=format&amp;w=1252 1252w, https://web-dev.imgix.net/image/admin/v6WcSx9Fq76lCD0iqFCQ.jpg?auto=format&amp;w=1428 1428w, https://web-dev.imgix.net/image/admin/v6WcSx9Fq76lCD0iqFCQ.jpg?auto=format&amp;w=1600 1600w&quot; width=&quot;800&quot; /&gt;
  &lt;figcaption&gt;In our article demo, applying &lt;code&gt;content-visibility: auto&lt;/code&gt; to chunked content areas gives a &lt;b&gt;7x&lt;/b&gt; rendering performance boost on initial load. Read on to learn more.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;support&quot;&gt;Browser support &lt;a class=&quot;headline-link&quot; href=&quot;https://web.dev/content-visibility/#support&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;wdi-browser-compat&quot;&gt;
  &lt;span class=&quot;wdi-browser-compat__label&quot;&gt;Browser support&lt;/span&gt;
  &lt;ul class=&quot;wdi-browser-compat__items&quot;&gt;
    &lt;li class=&quot;wdi-browser-compat__item&quot;&gt;
    &lt;span class=&quot;wdi-browser-compat__icon&quot; data-browser=&quot;chrome&quot;&gt;
      &lt;span class=&quot;visually-hidden&quot;&gt;Chrome 85, Supported&lt;/span&gt;
    &lt;/span&gt;
    &lt;span class=&quot;wdi-browser-compat__version&quot; data-compat=&quot;yes&quot; title=&quot;Supported&quot; aria-label=&quot;Supported&quot;&gt;
      85
    &lt;/span&gt;
    &lt;/li&gt;&lt;li class=&quot;wdi-browser-compat__item&quot;&gt;
    &lt;span class=&quot;wdi-browser-compat__icon&quot; data-browser=&quot;firefox&quot;&gt;
      &lt;span class=&quot;visually-hidden&quot;&gt;Firefox preview, Preview&lt;/span&gt;
    &lt;/span&gt;
    &lt;span class=&quot;wdi-browser-compat__version&quot; data-compat=&quot;preview&quot; title=&quot;Preview&quot; aria-label=&quot;Preview&quot;&gt;
&lt;p&gt;&lt;/p&gt;&lt;/span&gt;
&lt;/li&gt;&lt;li class=&quot;wdi-browser-compat__item&quot;&gt;
&lt;span class=&quot;wdi-browser-compat__icon&quot; data-browser=&quot;edge&quot;&gt;
&lt;span class=&quot;visually-hidden&quot;&gt;Edge 85, Supported&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;wdi-browser-compat__version&quot; data-compat=&quot;yes&quot; title=&quot;Supported&quot; aria-label=&quot;Supported&quot;&gt;
85
&lt;/span&gt;
&lt;/li&gt;&lt;li class=&quot;wdi-browser-compat__item&quot;&gt;
&lt;span class=&quot;wdi-browser-compat__icon&quot; data-browser=&quot;safari&quot;&gt;
&lt;span class=&quot;visually-hidden&quot;&gt;Safari, Not supported&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;wdi-browser-compat__version&quot; data-compat=&quot;no&quot; title=&quot;Not supported&quot; aria-label=&quot;Not supported&quot;&gt;&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;/span&gt;
&lt;/li&gt;&lt;p&gt;&lt;/p&gt;
  &lt;/ul&gt;
  &lt;a class=&quot;wdi-browser-compat__link&quot; href=&quot;https://developer.mozilla.org/docs/Web/CSS/content-visibility#browser_compatibility&quot; target=&quot;_blank&quot;&gt;Source&lt;/a&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;content-visibility&lt;/code&gt; relies on primitives within the &lt;a href=&quot;http://drafts.csswg.org/css-contain/&quot; rel=&quot;noopener&quot;&gt;the CSS Containment
Spec&lt;/a&gt;. While &lt;code&gt;content-visibility&lt;/code&gt; is only
supported in Chromium 85 for now (and deemed &lt;a href=&quot;https://github.com/mozilla/standards-positions/issues/135&quot; rel=&quot;noopener&quot;&gt;&amp;quot;worth
prototyping&amp;quot;&lt;/a&gt; for
Firefox), the Containment Spec is supported in &lt;a href=&quot;https://caniuse.com/#feat=css-containment&quot; rel=&quot;noopener&quot;&gt;most modern
browsers&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;containment&quot;&gt;CSS Containment &lt;a class=&quot;headline-link&quot; href=&quot;https://web.dev/content-visibility/#containment&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The key and overarching goal of CSS containment is to enable rendering
performance improvements of web content by providing &lt;strong&gt;predictable isolation of
a DOM subtree&lt;/strong&gt; from the rest of the page.&lt;/p&gt;
&lt;p&gt;Basically a developer can tell a browser what parts of the page are encapsulated
as a set of content, allowing the browsers to reason about the content without
needing to consider state outside of the subtree. Knowing which bits of content
(subtrees) contain isolated content means the browser can make optimization
decisions for page rendering.&lt;/p&gt;
&lt;p&gt;There are four types of &lt;a href=&quot;https://web.dev/css-containment/&quot;&gt;CSS
containment&lt;/a&gt;,
each a potential value for the &lt;code&gt;contain&lt;/code&gt; CSS property, which can be combined
in a space-separated list of values:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;size&lt;/code&gt;: Size containment on an element ensures that the element&#39;s box can be
laid out without needing to examine its descendants. This means we can
potentially skip layout of the descendants if all we need is the size of the
element.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;layout&lt;/code&gt;: Layout containment means that the descendants do not affect the
external layout of other boxes on the page. This allows us to potentially skip
layout of the descendants if all we want to do is lay out other boxes.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;style&lt;/code&gt;: Style containment ensures that properties which can have effects on
more than just its descendants don&#39;t escape the element (e.g. counters). This
allows us to potentially skip style computation for the descendants if all we
want is to compute styles on other elements.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;paint&lt;/code&gt;: Paint containment ensures that the descendants of the containing box
don&#39;t display outside its bounds. Nothing can visibly overflow the element,
and if an element is off-screen or otherwise not visible, its descendants will
also not be visible. This allows us to potentially skip painting the
descendants if the element is offscreen.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;skipping-rendering-work-with-content-visibility&quot;&gt;Skipping rendering work with &lt;code&gt;content-visibility&lt;/code&gt; &lt;a class=&quot;headline-link&quot; href=&quot;https://web.dev/content-visibility/#skipping-rendering-work-with-content-visibility&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;It may be hard to figure out which containment values to use, since browser
optimizations may only kick in when an appropriate set is specified. You can
play around with the values to see &lt;a href=&quot;https://web.dev/css-containment/&quot;&gt;what works
best&lt;/a&gt;, or you
can use another CSS property called &lt;code&gt;content-visibility&lt;/code&gt; to apply the needed
containment automatically. &lt;code&gt;content-visibility&lt;/code&gt; ensures that you get the largest
performance gains the browser can provide with minimal effort from you as a
developer.&lt;/p&gt;
&lt;p&gt;The content-visibility property accepts several values, but &lt;code&gt;auto&lt;/code&gt; is the one
that provides immediate performance improvements. An element that has
&lt;code&gt;content-visibility: auto&lt;/code&gt; gains &lt;code&gt;layout&lt;/code&gt;, &lt;code&gt;style&lt;/code&gt; and &lt;code&gt;paint&lt;/code&gt; containment. If
the element is off-screen (and not otherwise relevant to the user—relevant
elements would be the ones that have focus or selection in their subtree), it
also gains &lt;code&gt;size&lt;/code&gt; containment (and it stops
&lt;a href=&quot;https://developer.chrome.com/blog/inside-browser-part3/#paint&quot; rel=&quot;noopener&quot;&gt;painting&lt;/a&gt;
and
&lt;a href=&quot;https://developer.chrome.com/blog/inside-browser-part4/#finding-the-event-target&quot; rel=&quot;noopener&quot;&gt;hit-testing&lt;/a&gt;
its contents).&lt;/p&gt;
&lt;p&gt;What does this mean? In short, if the element is off-screen its descendants are
not rendered. The browser determines the size of the element without considering
any of its contents, and it stops there. Most of the rendering, such as styling
and layout of the element&#39;s subtree are skipped.&lt;/p&gt;
&lt;p&gt;As the element approaches the viewport, the browser no longer adds the &lt;code&gt;size&lt;/code&gt;
containment and starts painting and hit-testing the element&#39;s content. This
enables the rendering work to be done just in time to be seen by the user.&lt;/p&gt;
&lt;aside class=&quot;aside flow bg-state-bad-bg color-state-bad-text&quot;&gt;&lt;p class=&quot;cluster color-state-bad-text&quot;&gt;&lt;span class=&quot;aside__icon box-block &quot;&gt;&lt;svg width=&quot;24&quot; height=&quot;24&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;currentColor&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; role=&quot;img&quot; aria-label=&quot;Error sign&quot;&gt;   &lt;path fill-rule=&quot;evenodd&quot; clip-rule=&quot;evenodd&quot; d=&quot;M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 15v-2h2v2h-2zm0-10v6h2V7h-2z&quot;&gt;&lt;/path&gt; &lt;/svg&gt;&lt;/span&gt;&lt;strong&gt;Caution&lt;/strong&gt;&lt;/p&gt;&lt;div class=&quot; flow&quot;&gt; The browser is only able to skip rendering work if you are also careful not to call any DOM API that &lt;a href=&quot;https://gist.github.com/paulirish/5d52fb081b3570c81e3a#file-what-forces-layout-md&quot;&gt;forces some of rendering to occur&lt;/a&gt; on one of the skipped subtrees. If you&#39;re using &lt;code&gt;content-visibility&lt;/code&gt; to improve performance, audit your code to make sure these APIs are not getting called. To help find them, Chromium will print console messages if you call one of these APIs for a subtree of an element with &lt;code&gt;content-visibility:hidden&lt;/code&gt;. To see the messages, &lt;a href=&quot;https://developer.chrome.com/docs/devtools/console/log/&quot;&gt;turn on verbose logging&lt;/a&gt;. &lt;/div&gt;&lt;/aside&gt;
&lt;h2 id=&quot;a-note-on-accessibility&quot;&gt;A note on accessibility &lt;a class=&quot;headline-link&quot; href=&quot;https://web.dev/content-visibility/#a-note-on-accessibility&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;One of the features of &lt;code&gt;content-visibility: auto&lt;/code&gt; is that the off-screen content remains available in the document object model and therefore, the accessibility tree (unlike with &lt;code&gt;visibility: hidden&lt;/code&gt;). This means, that content can be searched for on the page, and navigated to, without waiting for it to load or sacrificing rendering performance.&lt;/p&gt;
&lt;p&gt;The flip-side of this, however, is that &lt;a href=&quot;https://www.w3.org/TR/wai-aria-1.1/#landmark_roles&quot; rel=&quot;noopener&quot;&gt;landmark&lt;/a&gt; elements with style features such as &lt;code&gt;display: none&lt;/code&gt; or &lt;code&gt;visibility: hidden&lt;/code&gt; will also appear in the accessibility tree when off-screen, since the browser will not render these styles until they enter the viewport. To prevent these from being visible in the accessibility tree, potentially causing clutter, be sure to also add &lt;code&gt;aria-hidden=&amp;quot;true&amp;quot;&lt;/code&gt;.&lt;/p&gt;
&lt;aside class=&quot;aside flow bg-state-bad-bg color-state-bad-text&quot;&gt;&lt;p class=&quot;cluster color-state-bad-text&quot;&gt;&lt;span class=&quot;aside__icon box-block &quot;&gt;&lt;svg width=&quot;24&quot; height=&quot;24&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;currentColor&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; role=&quot;img&quot; aria-label=&quot;Error sign&quot;&gt;   &lt;path fill-rule=&quot;evenodd&quot; clip-rule=&quot;evenodd&quot; d=&quot;M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 15v-2h2v2h-2zm0-10v6h2V7h-2z&quot;&gt;&lt;/path&gt; &lt;/svg&gt;&lt;/span&gt;&lt;strong&gt;Caution&lt;/strong&gt;&lt;/p&gt;&lt;div class=&quot; flow&quot;&gt; In Chromium 85-89, off-screen children within &lt;code&gt;content-visibility: auto&lt;/code&gt; were marked as invisible. In particular, &lt;a href=&quot;https://marcysutton.com/content-visibility-accessible-semantics&quot;&gt;headings&lt;/a&gt; and landmark roles were not exposed to accessibility tools. In Chromium 90 this was updated so that they are exposed. &lt;/div&gt;&lt;/aside&gt;
&lt;h2 id=&quot;example&quot;&gt;Example: a travel blog &lt;a class=&quot;headline-link&quot; href=&quot;https://web.dev/content-visibility/#example&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;figure&gt;
  &lt;video controls=&quot;&quot; autoplay=&quot;&quot; loop=&quot;&quot; muted=&quot;&quot; playsinline=&quot;&quot;&gt;
    &lt;source src=&quot;https://storage.googleapis.com/web-dev-assets/content-visibility/travel_blog.mp4&quot; /&gt;
  &lt;/video&gt;
  &lt;figcaption&gt;In this example, we baseline our travel blog on the right, and apply &lt;code&gt;content-visibility: auto&lt;/code&gt; to chunked areas on the left. The results show rendering times going from &lt;b&gt;232ms&lt;/b&gt; to &lt;b&gt;30ms&lt;/b&gt; on initial page load.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;A travel blog typically contains a set of stories with a few pictures, and some
descriptive text. Here is what happens in a typical browser when it navigates to
a travel blog:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;A part of the page is downloaded from the network, along with any needed
resources.&lt;/li&gt;
&lt;li&gt;The browser styles and lays out all of the contents of the page, without
considering if the content is visible to the user.&lt;/li&gt;
&lt;li&gt;The browser goes back to step 1 until all of the page and resources are
downloaded.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;In step 2, the browser processes all of the contents looking for things that may
have changed. It updates the style and layout of any new elements, along with
the elements that may have shifted as a result of new updates. This is rendering
work. This takes time.&lt;/p&gt;
&lt;figure&gt;
  &lt;img alt=&quot;A screenshot of a travel blog.&quot; decoding=&quot;async&quot; height=&quot;563&quot; loading=&quot;lazy&quot; sizes=&quot;(min-width: 800px) 800px, calc(100vw - 48px)&quot; src=&quot;https://web-dev.imgix.net/image/admin/57Zh2hjcXJjJIBSE648j.jpg?auto=format&quot; srcset=&quot;https://web-dev.imgix.net/image/admin/57Zh2hjcXJjJIBSE648j.jpg?auto=format&amp;w=200 200w, https://web-dev.imgix.net/image/admin/57Zh2hjcXJjJIBSE648j.jpg?auto=format&amp;w=228 228w, https://web-dev.imgix.net/image/admin/57Zh2hjcXJjJIBSE648j.jpg?auto=format&amp;w=260 260w, https://web-dev.imgix.net/image/admin/57Zh2hjcXJjJIBSE648j.jpg?auto=format&amp;w=296 296w, https://web-dev.imgix.net/image/admin/57Zh2hjcXJjJIBSE648j.jpg?auto=format&amp;w=338 338w, https://web-dev.imgix.net/image/admin/57Zh2hjcXJjJIBSE648j.jpg?auto=format&amp;w=385 385w, https://web-dev.imgix.net/image/admin/57Zh2hjcXJjJIBSE648j.jpg?auto=format&amp;w=439 439w, https://web-dev.imgix.net/image/admin/57Zh2hjcXJjJIBSE648j.jpg?auto=format&amp;w=500 500w, https://web-dev.imgix.net/image/admin/57Zh2hjcXJjJIBSE648j.jpg?auto=format&amp;w=571 571w, https://web-dev.imgix.net/image/admin/57Zh2hjcXJjJIBSE648j.jpg?auto=format&amp;w=650 650w, https://web-dev.imgix.net/image/admin/57Zh2hjcXJjJIBSE648j.jpg?auto=format&amp;w=741 741w, https://web-dev.imgix.net/image/admin/57Zh2hjcXJjJIBSE648j.jpg?auto=format&amp;w=845 845w, https://web-dev.imgix.net/image/admin/57Zh2hjcXJjJIBSE648j.jpg?auto=format&amp;w=964 964w, https://web-dev.imgix.net/image/admin/57Zh2hjcXJjJIBSE648j.jpg?auto=format&amp;w=1098 1098w, https://web-dev.imgix.net/image/admin/57Zh2hjcXJjJIBSE648j.jpg?auto=format&amp;w=1252 1252w, https://web-dev.imgix.net/image/admin/57Zh2hjcXJjJIBSE648j.jpg?auto=format&amp;w=1428 1428w, https://web-dev.imgix.net/image/admin/57Zh2hjcXJjJIBSE648j.jpg?auto=format&amp;w=1600 1600w&quot; width=&quot;800&quot; /&gt;
  &lt;figcaption&gt;An example of a travel blog. See &lt;a href=&quot;https://codepen.io/una/pen/rNxEWLo&quot;&gt;Demo on Codepen&lt;/a&gt;&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Now consider what happens if you put &lt;code&gt;content-visibility: auto&lt;/code&gt; on each of the
individual stories in the blog. The general loop is the same: the browser
downloads and renders chunks of the page. However, the difference is in the
amount of work that it does in step 2.&lt;/p&gt;
&lt;p&gt;With content-visibility, it will style and layout all of the contents that are
currently visible to the user (they are on-screen). However, when processing the
story that is fully off-screen, the browser will skip the rendering work and
only style and layout the element box itself.&lt;/p&gt;
&lt;p&gt;The performance of loading this page would be as if it contained full on-screen
stories and empty boxes for each of the off-screen stories. This performs much
better, with &lt;em&gt;expected reduction of 50% or more&lt;/em&gt; from the rendering cost of
loading. In our example, we see a boost from a &lt;strong&gt;232ms&lt;/strong&gt; rendering time to a
&lt;strong&gt;30ms&lt;/strong&gt; rendering time. That&#39;s a &lt;strong&gt;7x&lt;/strong&gt; performance boost.&lt;/p&gt;
&lt;p&gt;What is the work that you need to do in order to reap these benefits? First, we
chunk the content into sections:&lt;/p&gt;
&lt;figure&gt;
  &lt;img alt=&quot;An annotated screenshot of chunking content into sections with a CSS class.&quot; decoding=&quot;async&quot; height=&quot;563&quot; loading=&quot;lazy&quot; sizes=&quot;(min-width: 800px) 800px, calc(100vw - 48px)&quot; src=&quot;https://web-dev.imgix.net/image/admin/29uexe2kBwIsrAuILPnp.jpg?auto=format&quot; srcset=&quot;https://web-dev.imgix.net/image/admin/29uexe2kBwIsrAuILPnp.jpg?auto=format&amp;w=200 200w, https://web-dev.imgix.net/image/admin/29uexe2kBwIsrAuILPnp.jpg?auto=format&amp;w=228 228w, https://web-dev.imgix.net/image/admin/29uexe2kBwIsrAuILPnp.jpg?auto=format&amp;w=260 260w, https://web-dev.imgix.net/image/admin/29uexe2kBwIsrAuILPnp.jpg?auto=format&amp;w=296 296w, https://web-dev.imgix.net/image/admin/29uexe2kBwIsrAuILPnp.jpg?auto=format&amp;w=338 338w, https://web-dev.imgix.net/image/admin/29uexe2kBwIsrAuILPnp.jpg?auto=format&amp;w=385 385w, https://web-dev.imgix.net/image/admin/29uexe2kBwIsrAuILPnp.jpg?auto=format&amp;w=439 439w, https://web-dev.imgix.net/image/admin/29uexe2kBwIsrAuILPnp.jpg?auto=format&amp;w=500 500w, https://web-dev.imgix.net/image/admin/29uexe2kBwIsrAuILPnp.jpg?auto=format&amp;w=571 571w, https://web-dev.imgix.net/image/admin/29uexe2kBwIsrAuILPnp.jpg?auto=format&amp;w=650 650w, https://web-dev.imgix.net/image/admin/29uexe2kBwIsrAuILPnp.jpg?auto=format&amp;w=741 741w, https://web-dev.imgix.net/image/admin/29uexe2kBwIsrAuILPnp.jpg?auto=format&amp;w=845 845w, https://web-dev.imgix.net/image/admin/29uexe2kBwIsrAuILPnp.jpg?auto=format&amp;w=964 964w, https://web-dev.imgix.net/image/admin/29uexe2kBwIsrAuILPnp.jpg?auto=format&amp;w=1098 1098w, https://web-dev.imgix.net/image/admin/29uexe2kBwIsrAuILPnp.jpg?auto=format&amp;w=1252 1252w, https://web-dev.imgix.net/image/admin/29uexe2kBwIsrAuILPnp.jpg?auto=format&amp;w=1428 1428w, https://web-dev.imgix.net/image/admin/29uexe2kBwIsrAuILPnp.jpg?auto=format&amp;w=1600 1600w&quot; width=&quot;800&quot; /&gt;
  &lt;figcaption&gt;Example of chunking content into sections with the &lt;code&gt;story&lt;/code&gt; class applied, to receive &lt;code&gt;content-visibility: auto&lt;/code&gt;. See &lt;a href=&quot;https://codepen.io/vmpstr/pen/xxZoyMb&quot;&gt;Demo on Codepen&lt;/a&gt;&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Then, we apply the following style rule to the sections:&lt;/p&gt;
&lt;div&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.story&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;token property&quot;&gt;content-visibility&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; auto&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;token property&quot;&gt;contain-intrinsic-size&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1000px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;/* Explained in the next section. */&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;aside class=&quot;aside flow bg-state-info-bg color-state-info-text&quot;&gt;&lt;div class=&quot; flow&quot;&gt; Note that as content moves in and out of visibility, it will start and stop being rendered as needed. However, this does not mean that the browser will have to render and re-render the same content over and over again, since the rendering work is saved when possible. &lt;/div&gt;&lt;/aside&gt;
&lt;h3 id=&quot;specifying-the-natural-size-of-an-element-with-contain-intrinsic-size&quot;&gt;Specifying the natural size of an element with &lt;code&gt;contain-intrinsic-size&lt;/code&gt; &lt;a class=&quot;headline-link&quot; href=&quot;https://web.dev/content-visibility/#specifying-the-natural-size-of-an-element-with-contain-intrinsic-size&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;In order to realize the potential benefits of &lt;code&gt;content-visibility&lt;/code&gt;, the browser
needs to apply size containment to ensure that the rendering results of contents
do not affect the size of the element in any way. This means that the element
will lay out as if it was empty. If the element does not have a height specified
in a regular block layout, then it will be of 0 height.&lt;/p&gt;
&lt;p&gt;This might not be ideal, since the size of the scrollbar will shift, being
reliant on each story having a non-zero height.&lt;/p&gt;
&lt;p&gt;Thankfully, CSS provides another property, &lt;code&gt;contain-intrinsic-size&lt;/code&gt;, which
effectively specifies the natural size of the element &lt;em&gt;if the element is
affected by size containment&lt;/em&gt;. In our example, we are setting it to &lt;code&gt;1000px&lt;/code&gt; as
an estimate for the height and width of the sections.&lt;/p&gt;
&lt;p&gt;This means it will lay out as if it had a single child of &amp;quot;intrinsic-size&amp;quot;
dimensions, ensuring that your unsized divs still occupy space.
&lt;code&gt;contain-intrinsic-size&lt;/code&gt; acts as a placeholder size in lieu of rendered content.&lt;/p&gt;
&lt;p&gt;In Chromium 98 and onward, there is a new &lt;a href=&quot;https://drafts.csswg.org/css-sizing-4/#valdef-contain-intrinsic-width-auto-length&quot; rel=&quot;noopener&quot;&gt;&lt;code&gt;auto&lt;/code&gt;&lt;/a&gt;
keyword for &lt;code&gt;contain-intrinsic-size&lt;/code&gt;. When specified, the browser will remember
the last-rendered size, if any, and use that instead of the developer-provided placeholder
size. For example, if you specified &lt;code&gt;contain-intrinsic-size: auto 300px&lt;/code&gt;, the
element will start out with a &lt;code&gt;300px&lt;/code&gt; intrinsic sizing in each dimension, but once
the element&#39;s contents are rendered, it will retain the rendered intrinsic size.
Any subsequent rendering size changes will also be remembered. In practice, this means that if you
scroll an element with &lt;code&gt;content-visibility: auto&lt;/code&gt; applied, and then scroll it back
offscreen, it will automatically retain its ideal width and height, and not revert
to the placeholder sizing. This feature is especially useful for infinite scrollers,
which can now automatically improve sizing estimation over time as the user
explores the page.&lt;/p&gt;
&lt;aside class=&quot;aside flow bg-state-info-bg color-state-info-text&quot;&gt;&lt;div class=&quot; flow&quot;&gt; We can use &lt;code&gt;IntersectionObserver&lt;/code&gt; and &lt;code&gt;MutationObserver&lt;/code&gt; to set the correct sizes inline for each element. &lt;a href=&quot;https://twitter.com/slightlylate&quot;&gt;Alex Russell&lt;/a&gt; explains how this works in &lt;a href=&quot;https://infrequently.org/2020/12/content-visibility-scroll-fix/&quot;&gt;&lt;code&gt;content-visibility&lt;/code&gt; without jittery scrollbars&lt;/a&gt;, and &lt;a href=&quot;https://infrequently.org/2020/12/resize-resilient-deferred-rendering/&quot;&gt;Resize-Resilient &lt;code&gt;content-visibility&lt;/code&gt; Fixes&lt;/a&gt;. &lt;/div&gt;&lt;/aside&gt;
&lt;h2 id=&quot;hiding-content-with-content-visibility-hidden&quot;&gt;Hiding content with &lt;code&gt;content-visibility: hidden&lt;/code&gt; &lt;a class=&quot;headline-link&quot; href=&quot;https://web.dev/content-visibility/#hiding-content-with-content-visibility-hidden&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;What if you want to keep the content unrendered regardless of whether or not it
is on-screen, while leveraging the benefits of cached rendering state? Enter:
&lt;code&gt;content-visibility: hidden&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;content-visibility: hidden&lt;/code&gt; property gives you all of the same benefits of
unrendered content and cached rendering state as &lt;code&gt;content-visibility: auto&lt;/code&gt; does
off-screen. However, unlike with &lt;code&gt;auto&lt;/code&gt;, it does not automatically start to
render on-screen.&lt;/p&gt;
&lt;p&gt;This gives you more control, allowing you to hide an element&#39;s contents and
later unhide them quickly.&lt;/p&gt;
&lt;p&gt;Compare it to other common ways of hiding element&#39;s contents:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;display: none&lt;/code&gt;: hides the element and destroys its rendering state. This
means unhiding the element is as expensive as rendering a new element with the
same contents.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;visibility: hidden&lt;/code&gt;: hides the element and keeps its rendering state. This
doesn&#39;t truly remove the element from the document, as it (and it&#39;s subtree)
still takes up geometric space on the page and can still be clicked on. It
also updates the rendering state any time it is needed even when hidden.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;content-visibility: hidden&lt;/code&gt;, on the other hand, hides the element while
preserving its rendering state, so, if there are any changes that need to
happen, they only happen when the element is shown again (i.e. the
&lt;code&gt;content-visibility: hidden&lt;/code&gt; property is removed).&lt;/p&gt;
&lt;p&gt;Some great use cases for &lt;code&gt;content-visibility: hidden&lt;/code&gt; are when implementing
advanced virtual scrollers, and measuring layout. They&#39;re also great for
single-page applications (SPA&#39;s). Inactive app views can be left in the DOM with
&lt;code&gt;content-visibility: hidden&lt;/code&gt; applied to prevent their display but maintain their
cached state. This makes the view quick to render when it becomes active again.&lt;/p&gt;
&lt;aside class=&quot;aside flow bg-state-info-bg color-state-info-text&quot;&gt;&lt;div class=&quot; flow&quot;&gt; In an experiment, Facebook engineers observed an up to 250ms improvement in navigation times when going back to previously cached views. &lt;/div&gt;&lt;/aside&gt;
&lt;h2 id=&quot;effects-on-interaction-to-next-paint-inp&quot;&gt;Effects on Interaction to Next Paint (INP) &lt;a class=&quot;headline-link&quot; href=&quot;https://web.dev/content-visibility/#effects-on-interaction-to-next-paint-inp&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://web.dev/inp/&quot;&gt;INP&lt;/a&gt; is a metric that evaluates a page&#39;s ability to be reliably responsive to user input. Responsiveness can be affected by any excessive amount of work that occurs on the main thread, including rendering work.&lt;/p&gt;
&lt;p&gt;Whenever you can reduce rendering work on any given page, you&#39;re giving the main thread an opportunity to respond to user inputs more quickly. This includes rendering work, and using the &lt;code&gt;content-visiblity&lt;/code&gt; CSS property where appropriate can reduce rendering work—especially during startup, when most rendering and layout work is done.&lt;/p&gt;
&lt;p&gt;Reducing rendering work has a direct effect on INP. When users attempt to interact with a page that uses the &lt;code&gt;content-visibility&lt;/code&gt; property properly to defer layout and rendering of offscreen elements, you&#39;re giving the main thread a chance to respond to critical user-visible work. This can improve your page&#39;s INP in some situations.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion &lt;a class=&quot;headline-link&quot; href=&quot;https://web.dev/content-visibility/#conclusion&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;content-visibility&lt;/code&gt; and the CSS Containment Spec mean some exciting performance
boosts are coming right to your CSS file. For more information on these
properties, check out:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://drafts.csswg.org/css-contain/&quot; rel=&quot;noopener&quot;&gt;The CSS Containment Spec&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.mozilla.org/docs/Web/CSS/CSS_Containment&quot; rel=&quot;noopener&quot;&gt;MDN Docs on CSS
Containment&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/w3c/csswg-drafts&quot; rel=&quot;noopener&quot;&gt;CSSWG Drafts&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
    <author>
      <name>Una Kravets</name>
    </author><author>
      <name>Vladimir Levin</name>
    </author><author>
      <name>Jeremy Wagner</name>
    </author>
  </entry>
</feed>
