Vanta Logo
SPONSOR
Automate SOC 2 & ISO 27001 compliance with Vanta. Get $1,000 off.
Published
2 min read
Up to date

Trevor I. Lasn

Staff Software Engineer, Engineering Manager

CSS content-visibility: The Web Performance Boost You Might Be Missing

The content-visibility CSS property delays rendering an element, including layout and painting, until it is needed

Web performance optimization can be a real headache. Shaving off milliseconds here and there, minifying everything in sight, and praying to the performance gods.

Picture this: you’re scrolling through a massive webpage with hundreds of images, complex layouts, and enough content to fill a book. Without content-visibility, browsers dutifully render every single pixel, whether you can see it or not. It’s like a restaurant cooking every dish on the menu just in case someone orders it.

The content-visibility property tells browsers they can skip rendering elements until they’re about to enter the viewport. This might sound simple, but it’s a game-changer for long scrolling pages.

The contain-intrinsic-size property is content-visibility’s partner in crime. It provides a size estimate so the browser can reserve space before rendering, preventing layout shifts.

content-visibility works best on pages with lots of complex, off-screen content. News feeds, product listings, and documentation sites are perfect candidates. I’ve seen initial render times improve by 30-50% on content-heavy pages.

One important detail: content-visibility doesn’t just defer paint operations - it skips layout calculations entirely. This means the browser doesn’t waste time figuring out how to position elements nobody can see yet.

content-visibility isn’t free magic though. Each element with content-visibility: auto becomes a separate containing block. This can affect positioning and scroll anchoring. Here’s what to watch for:

After experimenting with content-visibility across different scenarios, I’ve found it works best when:

  1. Sections are clearly defined and independent
  2. Content below the fold is complex
  3. Users typically don’t need immediate access to hidden content

Feeds are a great example - users rarely jump straight to the bottom, and each post is self-contained.

If you found this article helpful, you might enjoy my free newsletter. I share developer tips and insights to help you grow your skills and career.


More Articles You Might Enjoy

If you enjoyed this article, you might find these related pieces interesting as well. If you like what I have to say, please check out the sponsors who are supporting me. Much appreciated!

Webdev
4 min read

Open Dyslexic Font: Improve Your Web Accessibility

How to implement the Open-Dyslexic font to enhance readability for users with dyslexia

Oct 12, 2024
Read article
Webdev
3 min read

scrollbar-width & scrollbar-gutter: CSS Properties for Layout Control

Prevent content shifts and refine scrollable UIs with scrollbar-width and scrollbar-gutter

Dec 19, 2024
Read article
Webdev
13 min read

10 Essential Terminal Commands Every Developer Should Know

List of useful Unix terminal commands to boost your productivity. Here are some of my favorites.

Aug 21, 2024
Read article
Webdev
3 min read

Preloading Responsive Images

How to properly preload responsive images to improve initial page load

Nov 28, 2024
Read article
Webdev
3 min read

CVE-2025-29927 - Next.js Middleware Bypass Explained In Simple Terms

The vulnerability skips Next.js middleware security checks by adding a single HTTP header

Apr 6, 2025
Read article
Webdev
4 min read

Self-Taught Developer's Guide to Thriving in Tech

How to turn your non-traditional background into your biggest asset

Sep 28, 2024
Read article
Webdev
4 min read

Explicit is better than implicit

Clarity is key: being explicit makes your code more readable and maintainable.

Sep 4, 2024
Read article
Webdev
2 min read

link rel='modulepreload': Optimize JavaScript Module Loading

The rel='modulepreload' indicates that a module script should be fetched, parsed, and compiled preemptively, and stored for later execution

Dec 4, 2024
Read article
Webdev
3 min read

CSS ::target-text for Text Highlighting

A look at how browsers can highlight text fragments using CSS ::target-text, making text sharing and navigation more user-friendly

Dec 17, 2024
Read article

Become a better engineer

Here are engineering resources I've personally vetted and use. They focus on skills you'll actually need to build and scale real projects - the kind of experience that gets you hired or promoted.

Many companies have a fixed annual stipend per engineer (e.g. $2,000) for use towards learning resources. If your company offers this stipend, you can forward them your invoices directly for reimbursement. By using my affiliate links, you support my work and get a discount at the same!


This article was originally published on https://www.trevorlasn.com/blog/css-content-visibility. It was written by a human and polished using grammar tools for clarity.