CSS content-visibility Property

The content-visibility property controls whether an element's contents are rendered, allowing browsers to skip unnecessary rendering work and improve page performance.

It is particularly useful for long pages containing multiple sections, cards, tables, or other content that may initially be outside the visible area. The auto value allows the browser to defer rendering work until content becomes relevant to the user.

The property supports three values: visible, hidden, and auto. Each value determines how the browser handles the element's contents while preserving the element itself in the document.

content-visibility Syntax

The content-visibility property accepts one of three keywords that determine whether the browser renders an element's contents.

selector {
  content-visibility: auto;
}

General Syntax

selector {
  content-visibility: visible | hidden | auto;
}

Visible Content

.content-section {
  content-visibility: visible;
}

Hidden Content

.content-section {
  content-visibility: hidden;
}

Automatic Rendering

.content-section {
  content-visibility: auto;
}

CSS-Wide Keywords

.content-section {
  content-visibility: inherit;
}
.content-section {
  content-visibility: initial;
}
.content-section {
  content-visibility: unset;
}
.content-section {
  content-visibility: revert;
}
.content-section {
  content-visibility: revert-layer;
}

Only one value can be specified at a time. The property does not accept lengths, percentages, or multiple keywords.

Property Values

Value Description
visible Uses normal rendering behavior without skipping the element's contents through this property.
hidden Skips rendering the element's contents while retaining the element's own box and applicable containment behavior.
auto Allows the browser to skip rendering contents when they are not relevant to the user, while rendering them when needed.

Property Characteristics

Characteristic Value
Initial value visible
Inherited No
Applies to Elements for which size containment can apply
Computed value Specified keyword
Animation type Discrete, with special transition behavior between visible and non-visible states
Percentages Not applicable

The auto value is commonly used for performance optimization, while hidden is useful when content must remain in the document but should not currently be rendered.

How It Works

Browsers normally calculate layout, style, and painting information for page content, including elements that are not currently visible.

The content-visibility property allows some of that work to be skipped when an element's contents do not need to be rendered.

Step 1: Create a Content Section

<section class="reference-section">
  <h2>CSS Properties</h2>
  <p>Explore CSS properties and examples.</p>
</section>

Step 2: Enable Automatic Rendering

.reference-section {
  content-visibility: auto;
}

Step 3: Provide a Size Estimate

.reference-section {
  content-visibility: auto;
  contain-intrinsic-size: auto 400px;
}

Step 4: Let the Browser Manage Rendering

The browser may skip rendering the section's contents while the section is not relevant to the user. When the section becomes relevant, the browser renders its contents.

Step 5: Preserve Layout Stability

The contain-intrinsic-size declaration provides an estimated block size while rendering is skipped. The auto keyword also allows a previously remembered natural size to be reused when available.

Important Distinction

The property does not remove HTML elements from the DOM. It changes rendering behavior rather than deleting document content.

The visible Value

The visible value is the initial value of content-visibility.

.content-section {
  content-visibility: visible;
}

Normal Rendering

The element's contents are rendered normally, subject to other CSS properties and browser rendering behavior.

Restore Rendering

.content-section {
  content-visibility: hidden;
}
.content-section.is-visible {
  content-visibility: visible;
}

Default Behavior

.content-section {
  content-visibility: initial;
}

The initial keyword restores the initial value, visible.

When to Use

Use visible when content should render normally or when overriding an earlier hidden or auto declaration.

The hidden Value

The hidden value skips rendering the contents of an element while preserving the element itself.

.content-section {
  content-visibility: hidden;
}

Hidden Contents

<section class="content-section">
  <h2>Additional Information</h2>
  <p>This content is temporarily hidden.</p>
</section>
.content-section {
  content-visibility: hidden;
}

Restore the Contents

.content-section.is-open {
  content-visibility: visible;
}

Preserve an Estimated Size

.content-section {
  content-visibility: hidden;
  contain-intrinsic-size: 400px 250px;
}

Hidden vs. display: none

Unlike display: none, content-visibility: hidden does not remove the element's own principal box from layout.

Accessibility Behavior

Content skipped by content-visibility: hidden is not exposed as normal accessible content while hidden.

When to Use

Use hidden when a region should retain its container and layout characteristics while its contents are temporarily not rendered.

The auto Value

The auto value allows the browser to skip rendering content that is not currently relevant to the user.

.content-section {
  content-visibility: auto;
}

Automatic Rendering Optimization

.article-section {
  content-visibility: auto;
  contain-intrinsic-size: auto 500px;
}

Offscreen Content

When a section is sufficiently far from the visible area and does not otherwise require rendering, the browser may skip layout and painting work for its contents.

Content Becoming Relevant

When the section approaches the visible area or otherwise becomes relevant, the browser stops skipping its contents.

Find-in-Page

Content using content-visibility: auto remains available for browser find-in-page operations. The browser can activate rendering when a matching result needs to be displayed.

Accessibility Tree

Unlike hidden, the auto value is designed to preserve content accessibility even when rendering work is skipped.

When to Use

Use auto for long pages with independent sections, especially when many sections are initially outside the viewport.

Comparing Values

The three values differ in how they control rendering and content availability.

Behavior visible hidden auto
Normal content rendering Yes No When relevant
Can skip descendant rendering No Yes Yes
Automatic visibility management No No Yes
Element remains in the DOM Yes Yes Yes
Element's own box remains in layout Yes Yes Yes
Typical use Normal content Temporarily skipped content Rendering performance

Recommended Starting Point

.long-page-section {
  content-visibility: auto;
  contain-intrinsic-size: auto 400px;
}

For performance optimization on long pages, auto is generally the most useful value.

Rendering Performance

Rendering a large document can require substantial work, particularly when it contains many elements, complex layouts, or detailed visual components.

Skipping Unnecessary Work

With content-visibility: auto, browsers can avoid some style, layout, and painting work for content that is not currently relevant.

Long Documentation Pages

.documentation-section {
  content-visibility: auto;
  contain-intrinsic-size: auto 500px;
}

Large Card Collections

.card-group {
  content-visibility: auto;
  contain-intrinsic-size: auto 350px;
}

Rendering When Needed

Skipped contents must eventually be rendered when they become relevant. This can introduce work during scrolling or other interactions.

Performance Is Context-Dependent

The benefit depends on page structure, browser implementation, the number of elements, and how frequently content becomes visible.

Measure Results

Use browser developer tools to compare rendering performance before and after applying the property. Avoid assuming that applying it to every element will improve performance.

CSS Containment

The content-visibility property works with CSS containment to isolate rendering work.

Containment with auto

.content-section {
  content-visibility: auto;
}

The auto value applies layout, style, and paint containment. Size containment is applied while the element's contents are skipped.

Containment with hidden

.content-section {
  content-visibility: hidden;
}

The hidden value applies containment that allows the browser to skip the element's contents.

Containment with visible

.content-section {
  content-visibility: visible;
}

The visible value does not introduce additional containment through this property.

Related contain Property

.isolated-component {
  contain: layout style;
}

The contain property provides direct control over containment behavior. The content-visibility property uses containment as part of its rendering optimization.

Practical Consideration

Containment can affect layout, painting, and intrinsic sizing. Test components carefully when applying rendering optimizations to complex layouts.

Intrinsic Sizing

When an element's contents are skipped, the browser may not calculate the natural dimensions contributed by those contents.

The contain-intrinsic-size property can provide substitute dimensions while rendering is skipped.

Basic Size Estimate

.content-section {
  content-visibility: auto;
  contain-intrinsic-size: 400px;
}

Separate Inline and Block Sizes

.content-section {
  content-visibility: auto;
  contain-intrinsic-size: 600px 400px;
}

Remembered Block Size

.content-section {
  content-visibility: auto;
  contain-intrinsic-size: auto 400px;
}

The auto keyword allows the browser to reuse a remembered natural block size when one is available. Otherwise, 400 pixels is used as the substitute intrinsic block size.

Separate Remembered Dimensions

.content-section {
  content-visibility: auto;
  contain-intrinsic-size: auto 600px auto 400px;
}

Preventing Scrollbar Jumps

Without a suitable size estimate, skipped sections may occupy much less space than their actual content. When rendering begins, the resulting size change can affect scroll position and page layout.

Practical Consideration

Choose reasonable fallback dimensions based on the expected content size. The estimate does not need to match perfectly, but large differences may cause noticeable layout shifts.

Long Pages

Long documentation and tutorial pages are common candidates for content-visibility: auto.

Apply to Independent Sections

.tutorial-section {
  content-visibility: auto;
  contain-intrinsic-size: auto 500px;
}

HTML Structure

<article>
  <section class="tutorial-section">
    <h2>Introduction</h2>
    <p>Introductory content.</p>
  </section>
  <section class="tutorial-section">
    <h2>Examples</h2>
    <p>Example content.</p>
  </section>
  <section class="tutorial-section">
    <h2>Browser Support</h2>
    <p>Compatibility information.</p>
  </section>
</article>

Different Size Estimates

.tutorial-section {
  content-visibility: auto;
  contain-intrinsic-size: auto 400px;
}
.tutorial-section.examples {
  contain-intrinsic-size: auto 700px;
}

Choosing Section Boundaries

Apply the property to meaningful content groups rather than every paragraph or small element. Larger independent sections often provide more useful rendering boundaries.

Above-the-Fold Content

Content that is immediately visible usually offers little benefit from skipped rendering. Prioritize sections that begin outside the initial viewport.

Practical Consideration

Test anchor navigation, scrolling, find-in-page, and browser zoom after applying the property to long pages.

Dynamic Content

The content-visibility property can be used with dynamic interfaces that reveal or update content.

Hidden Panel

.details-panel {
  content-visibility: hidden;
}
.details-panel.is-open {
  content-visibility: visible;
}

Automatic Rendering for Repeated Items

.result-card {
  content-visibility: auto;
  contain-intrinsic-size: auto 250px;
}

Dynamic Class Changes

const panel = document.querySelector(".details-panel");
panel.classList.add("is-open");

Dynamic Content Updates

JavaScript can still modify DOM content while rendering is skipped. The browser processes the updated content when rendering becomes necessary.

Layout Measurement

Scripts that measure descendant geometry may require the browser to perform additional rendering work. Repeated measurements can reduce the performance benefits of skipping content.

Important Consideration

For interactive disclosure widgets, use appropriate semantic HTML and accessibility states. Rendering control alone does not provide complete interactive behavior.

content-visibility vs. Other Visibility Properties

The content-visibility, visibility, display, and opacity properties affect presentation in different ways.

content-visibility: hidden

.panel {
  content-visibility: hidden;
}

Skips rendering the panel's contents while retaining the panel's own box and applicable containment behavior.

visibility: hidden

.panel {
  visibility: hidden;
}

Hides the element visually while generally preserving its layout space.

display: none

.panel {
  display: none;
}

Removes the element and its descendants from the box tree, so they do not occupy layout space.

opacity: 0

.panel {
  opacity: 0;
}

Makes the element transparent without removing it from layout or automatically disabling interaction.

Comparison Table

Property Visual Result Layout Behavior
content-visibility: hidden Descendant contents are skipped Element's own box remains, with containment effects
visibility: hidden Element is hidden Layout space remains
display: none Element is not displayed Element's box is removed
opacity: 0 Element is transparent Layout space remains

Choosing the Right Property

Use content-visibility: auto for rendering optimization, display: none to remove an element from layout, and visibility or opacity when their visual behavior is specifically required.

Practical Uses

The content-visibility property is useful when a page contains large amounts of content that do not all need to be rendered immediately.

Documentation Sections

.documentation-section {
  content-visibility: auto;
  contain-intrinsic-size: auto 500px;
}

Tutorial Examples

.tutorial-example {
  content-visibility: auto;
  contain-intrinsic-size: auto 350px;
}

Product Listings

.product-group {
  content-visibility: auto;
  contain-intrinsic-size: auto 600px;
}

Large Data Sections

.data-section {
  content-visibility: auto;
  contain-intrinsic-size: auto 450px;
}

Temporarily Hidden Panels

.inactive-panel {
  content-visibility: hidden;
}
.inactive-panel.is-active {
  content-visibility: visible;
}

When Not to Use

Avoid applying the property indiscriminately to small elements, critical above-the-fold content, or layouts where containment causes unwanted sizing behavior.

Performance Testing

Measure real rendering improvements and check for unexpected layout shifts, scrolling delays, or accessibility issues.

content-visibility Example

This example demonstrates how content-visibility: auto can be applied to multiple content sections on a long page.

Each section uses contain-intrinsic-size to provide an estimated block size while its contents are skipped. Scroll through the example to see the sections as they become visible.

<div class="content-visibility-demo">
  <section class="demo-section">
    <h3>HTML Reference</h3>
    <p>Learn about HTML elements, attributes, and document structure.</p>
    <p>Explore examples and practical explanations.</p>
  </section>
  <section class="demo-section">
    <h3>CSS Properties</h3>
    <p>Explore CSS properties for layout, typography, and styling.</p>
    <p>Review syntax, values, and examples.</p>
  </section>
  <section class="demo-section">
    <h3>CSS Selectors</h3>
    <p>Learn how selectors target elements in a document.</p>
    <p>Practice combining selectors and pseudo-classes.</p>
  </section>
  <section class="demo-section">
    <h3>CSS Layout</h3>
    <p>Explore Flexbox, Grid, and responsive layout techniques.</p>
    <p>Build layouts that adapt to different screen sizes.</p>
  </section>
</div>
.content-visibility-demo {
  display: grid;
  gap: 20px;
}
.content-visibility-demo .demo-section {
  content-visibility: auto;
  contain-intrinsic-size: auto 200px;
  padding: 20px;
  border: 1px solid #cccccc;
  background-color: #f8f9fa;
}
.content-visibility-demo h3 {
  margin: 0 0 12px;
  color: #336699;
  font-size: 1.125rem;
}
.content-visibility-demo p {
  margin: 0 0 10px;
}
.content-visibility-demo p:last-child {
  margin-bottom: 0;
}
Browser Result

HTML Reference

Learn about HTML elements, attributes, and document structure.

Explore examples and practical explanations.

CSS Properties

Explore CSS properties for layout, typography, and styling.

Review syntax, values, and examples.

CSS Selectors

Learn how selectors target elements in a document.

Practice combining selectors and pseudo-classes.

CSS Layout

Explore Flexbox, Grid, and responsive layout techniques.

Build layouts that adapt to different screen sizes.

The sections remain in the document and can be scrolled normally. The browser may skip rendering work for sections that are not currently relevant.

The optimization is not directly visible as a style change. Its purpose is to reduce unnecessary rendering work, which can be evaluated using browser performance tools.

The contain-intrinsic-size declaration helps maintain reasonable section dimensions while rendering is skipped.

Accessibility

The content-visibility property affects rendering and can influence how content is exposed to assistive technologies.

Use auto for Performance Optimization

The auto value is designed to keep skipped content available to accessibility features, including find-in-page and assistive technology navigation.

Understand hidden Behavior

The hidden value skips content in a way that prevents it from being exposed as normal accessible content until rendering is restored.

Avoid Unnecessary aria-hidden

Do not add aria-hidden="true" to content using content-visibility: auto solely because it is initially offscreen. Doing so could remove useful content from the accessibility tree.

Test Keyboard Navigation

Ensure that focusable elements remain reachable and that keyboard navigation works correctly when content becomes relevant.

Support Find-in-Page

Test browser search and anchor navigation on long pages to confirm that content can be located and displayed as expected.

Avoid Unexpected Layout Shifts

Use appropriate intrinsic size estimates so content becoming visible does not cause excessive movement that disrupts reading or navigation.

Preserve Semantic HTML

Continue using meaningful headings, landmarks, lists, and other semantic HTML elements. Rendering optimization does not replace document structure.

Important Considerations

Keep the following points in mind when using content-visibility:

  • Purpose: Controls whether an element's contents are rendered.
  • Initial value: visible.
  • Inheritance: The property is not inherited.
  • visible: Uses normal rendering behavior.
  • hidden: Skips rendering contents until the value changes.
  • auto: Allows the browser to skip rendering when content is not relevant.
  • DOM: The property does not remove elements from the document.
  • Layout: The element's own box remains in layout, subject to containment behavior.
  • Containment: Skipping contents relies on CSS containment.
  • Intrinsic sizing: Skipped content may require substitute intrinsic dimensions.
  • contain-intrinsic-size: Helps maintain layout stability while rendering is skipped.
  • Performance: Benefits depend on page structure and browser behavior.
  • Long pages: Independent sections are common candidates for auto.
  • Dynamic content: DOM updates remain possible while rendering is skipped.
  • JavaScript measurements: Layout measurements may trigger additional rendering work.
  • Accessibility: auto and hidden have different accessibility behavior.
  • Scrolling: Inaccurate size estimates may contribute to layout shifts.
  • Browser support: Test across target browsers and devices.

For performance optimization, start with content-visibility: auto on independent offscreen sections and provide reasonable intrinsic size estimates. Measure the results before applying the property more broadly.

Browser Support

The CSS content-visibility property is supported in current versions of major browsers, including Chrome, Edge, Firefox, and Safari.

Older browsers may not support the property. When unsupported, the declaration is ignored and the content follows normal rendering behavior.

Basic Example

.content-section {
  content-visibility: auto;
  contain-intrinsic-size: auto 400px;
}

Feature Detection

@supports (content-visibility: auto) {
  .content-section {
    content-visibility: auto;
    contain-intrinsic-size: auto 400px;
  }
}

Feature detection can prevent unsupported declarations from being used in a targeted rule, although unsupported CSS declarations are normally ignored automatically.

For current compatibility information, visit Can I Use? .

Specifications

The content-visibility property is defined in CSS Containment Module Level 2, with related containment and intrinsic sizing behavior described in CSS Containment specifications.

CSS Containment Module Level 2

The specification defines rendering-skipping behavior, containment requirements, and the relationship between content visibility and rendering performance.