DEV Community

Cover image for Why content-visibility: auto Can Make Your Site Instantly Faster
Pawar Shivam
Pawar Shivam

Posted on

Why content-visibility: auto Can Make Your Site Instantly Faster

=> What If Browser Didn’t Render Everything?

Normally, the browser renders:

πŸ‘‰ entire page
πŸ‘‰ even off-screen content

This wastes performance.


=> The Hidden Performance Hack

.section {
  content-visibility: auto;
}
Enter fullscreen mode Exit fullscreen mode

Now the browser:

πŸ‘‰ skips rendering off-screen content
πŸ‘‰ renders only when needed


=> Why This Is Powerful

For long pages:

  • blogs
  • dashboards
  • feeds

This can:

πŸ‘‰ improve load time
πŸ‘‰ reduce memory usage
πŸ‘‰ boost performance


=> Real Example

.card {
  content-visibility: auto;
  contain-intrinsic-size: 300px;
}
Enter fullscreen mode Exit fullscreen mode

=> Why contain-intrinsic-size Matters

Without it:

πŸ‘‰ layout shift can happen

This gives a placeholder size until content loads.


=> What Developers Often Miss

Optimization is not always JavaScript.

Sometimes CSS can do it better.


=> When to Use It

Use for:

  • long scrolling pages
  • repeated components
  • off-screen sections

=> When NOT to Use

Avoid on:

  • above-the-fold content
  • critical UI elements

=> Real UI Tip

If your page feels heavy:

πŸ‘‰ try skipping rendering instead of optimizing everything


=> What Do You Think?

Would you use content-visibility in your next project for performance?

Top comments (0)