Skip to content
WebsiteHosting.com

concept Frontend & browsers

CSS containment and content-visibility tradeoffs

With content-visibility: auto, an offscreen section can stay in the document while its rendering is skipped. Relevance determines what can be skipped; size containment affects how much room the box takes.

Latest recorded source check · P0185

What it means

content-visibility: auto lets a browser skip layout and paint work for the contents of an offscreen section without removing those contents from the document. The section still has a box, and the space that box occupies matters to the rest of the page. Being offscreen is not enough, by itself, to determine whether work can be skipped: a section with keyboard focus inside it can still be relevant.

Try it

Simulation. Start with six equal-size sections, auto, and no explicit containment. Two sections are near the viewport, the part of the page in view. One additional section farther away is marked relevant, as if it contained a focused link. The model therefore counts three sections whose contents are rendered and three whose contents are skipped. Here, “rendered” means not skipped by the policy, not necessarily visible on screen.

CSS containment and content-visibility tradeoffs

Explain offscreen rendering skips and retained accessibility/document semantics

Simulation
Modeled outcome: Scope

Report containment types, modeled relevant/skipped contents and reserved geometry separately; no performance measurement.

CSS containment and content-visibility tradeoffs: synthetic scenario inputs
Replaces all inputs with the documented starting example and the indicated change. Reset restores the starting example.
Section rendering and reserved layout space

Containment and layout

  1. Always-applied containmentlayout, paint, style
  2. Modeled box total1350 px
  3. Accessibility boundaryno removal inferred from skipping
Rendered3 sections
Skipped3 sections
Size-contained3 sections

Counts assume non-overlapping near and focused sets. The aggregate size is a toy geometry estimate; skipped content does not establish an accessibility verdict.

Evaluated inputs

Required scenario evidence
provided
Equal-size sections
6 count
content-visibility policy
auto
Sections near viewport
2 count
Additional offscreen relevant sections
1 count
Explicit containment
none
Reserved skipped size
200 px
Natural section content size
250 px

CSS Containment Level 2 Working Draft semantics (2022 snapshot) plus simplified equal box heights. Additional offscreen relevant count can represent focus/selection/top-layer relevance, not an actual DOM observation. Reserved size is stipulated for size-contained boxes; real intrinsic-size behavior more complex. Layout/paint/style scopes do not promise perfect isolation or actual speedup. Accessibility is scoped to skipped-content semantics, not an audited accessibility tree.

About this model

The controls set only a local, bounded scenario. The computed branch is not a verdict about a live system. Inputs listed as not evaluated did not participate in this branch after validation.

Reset restores the original inputs. It does not change the open or closed state of help or FAQ answers.

Change Additional offscreen relevant sections from 1 to 0. Leave the viewport count and both heights alone. Now only two sections have their contents rendered, and four are skipped. The six boxes are still there, but their combined height drops from 1,350 px to 1,300 px. Reset returns to the original six-section example.

Why the height changes

Even with explicit containment set to none, auto applies layout, paint, and style containment. These have different jobs. Layout containment gives the contents their own formatting context; it does not, by itself, stop them from determining the section’s height. Paint containment limits where descendants can draw. Style containment limits the scope of certain styling effects, not all CSS. None of these three is a height reservation.

What changes the arithmetic is size containment. In the starting example, it applies to the skipped sections. Instead of sizing those boxes from their contents, the simulation uses the stated reserve of 200 px apiece. The other three use their natural height of 250 px. That gives 3 × 250 + 3 × 200 = 1,350 px. When the offscreen section is no longer relevant, its box contributes 200 px instead of 250 px. That one substitution accounts for the entire 50 px difference.

The reverse inference doesn’t work: you can’t tell what was skipped from the total height. Consider two variations on the starting example:

  • With content-visibility: hidden and no explicit containment, all six sections’ contents are skipped. The model reserves 200 px for each box, totaling 1,200 px. Under the draft’s rules, the skipped descendants are unavailable to browser features such as find-in-page.
  • With auto and explicit strict containment, all six boxes are size-contained, including the three whose contents are rendered. The total is also 1,200 px, but the additional relevant section is still rendered, and auto skipping does not itself make the other descendants unavailable to browser features.

Set explicit size containment to strict and compare visible with auto while all other inputs stay fixed. Even when all six sections render, explicit size containment keeps the toy reserved size at 200 px per section, so the total stays 1,200 px. Rendering more sections need not change this modeled size. The example excludes actual layout, scroll anchoring and assistive-technology observations.

In practice

On a long page, choose the observation that matches your question. If you care about how much the page moves, compare a section’s reserved height with its height when its contents are rendered. A close estimate leaves less difference to account for. If you care about access to the content, try finding text in a distant section and reaching a link there by keyboard. Seeing a reserved box tells you neither result, and those checks alone are not an accessibility audit.

The simulation follows the September 2022 CSS Containment Level 2 Working Draft and uses equal, stipulated heights. It does not inspect a browser’s relevance decisions or measure layout shifts or rendering time. Use relevance to reason about which work can be deferred, and size containment to reason about the space left behind. If the decision depends on a speedup, measure the actual page rather than counting its skipped sections.

Frequently asked questions

Editorial questions based on the listed sources and explicitly labeled local examples.

Does content-visibility:auto remove content from the DOM?

No. Skipping rendering work does not remove the DOM. The draft keeps auto-skipped content available to user-agent features; real accessibility behavior needs browser testing.

Why reserve an intrinsic size?

When layout no longer depends on skipped contents, a supplied size can reduce unexpected geometry changes. The example compares stated natural and reserved heights, not measured layout shift.

Does paint containment make offscreen rendering disappear?

No. Containment scopes and content visibility are distinct. Paint containment restricts certain painting effects; size containment changes sizing dependencies.

Is hidden equivalent to auto?

No. Auto can render contents as they become relevant, including focus. Hidden skips contents with different user-agent availability semantics. Neither the skipped count nor the reserved box size establishes a performance or accessibility outcome.

Sources & model boundaries

Primary references used for this explanation. The interactive example is an educational model, not a live check.

  1. CSS Containment Module Level 2

    content-visibility. content-visibility auto may skip rendering when content is not relevant; hidden and auto have distinct behavior. Size containment and painting are separate.

    Checked .

  2. MDN: CSS content-visibility

    Accessibility; examples. Offscreen content under content-visibility:auto can remain in the DOM while rendering is skipped. Do not equate that optimization with removing content or proving accessibility compliance.

    Checked .

Report an issue. Include the article URL and ID, not passwords or access keys.