The content-visibility property controls whether an element renders its contents, enabling significant performance improvements. Here's how to use it.
Basic Usage#
Long Page Optimization#
contain-intrinsic-size#
Hidden vs display:none#
Lazy Rendering Pattern#
Dashboard Widgets#
Combining with Containment#
Accordion Pattern#
Modal and Dialog#
Table Optimization#
Animation Considerations#
JavaScript Integration#
Performance Measurement#
Best Practices#
Usage:
✓ Use for off-screen content
✓ Set contain-intrinsic-size
✓ Use 'auto' for most cases
✓ Apply to repeated elements
Performance:
✓ Reduces initial render time
✓ Skips off-screen layout
✓ Improves scroll performance
✓ Preserves element state
Intrinsic Size:
✓ Estimate accurately
✓ Use 'auto' prefix when possible
✓ Match typical content size
✓ Update if content varies
Avoid:
✗ On visible above-fold content
✗ On animated elements
✗ Without intrinsic size
✗ Causing layout shifts
Conclusion#
The content-visibility property significantly improves rendering performance by skipping off-screen content. Use it for long pages, lists, and hidden UI elements. Always set contain-intrinsic-size to prevent layout shifts. The 'auto' value lets the browser optimize automatically based on visibility.