Lesson 8 of 8

Skipping what nobody sees

Goal

Render only what's on screen

01

Explanation

On a page with thirty sections, the browser works out the position and size of every section and paints them all on load, even though the visitor only sees the first one. content-visibility: auto tells it to skip laying out and painting a section while it's far from the screen, and to do that work once the section gets close.

The content stays in the page, so Ctrl+F still finds it, screen readers still read it and links can still reach it. Neither display: none nor removing the elements gives you that.

Watch out: a section the browser skips is treated as if it were empty, so its height becomes zero and the scrollbar jumps every time a new section gets rendered. That's why you reserve an estimated height for it with contain-intrinsic-size, and the keyword auto before the length makes the browser remember the real height after the first render.

02

Your task

Make the browser skip rendering each .section while it's off screen, reserve an estimated height for it that's close to its real height, and use auto so the browser remembers the real height.

Checks

4 checks
  1. The browser skips rendering every off-screen section
  2. Every section has a reserved height
  3. The reserved height uses auto to remember the real height
  4. No section collapses to zero height
03

Hints

0/3
Track lessons0 of 8 done

Find out where your page really loses time, and how to win it back by adding elements in one go, making fewer calls and never computing the same thing twice.

Advanced level, 8 lessons, 1.5 hours in total.

index.html
Preview
index.html100%
–/4

Press “Run and check” to grade your code.

4 checks listed under “Your task”.

Track lessons0 of 8 done

Find out where your page really loses time, and how to win it back by adding elements in one go, making fewer calls and never computing the same thing twice.

Advanced level, 8 lessons, 1.5 hours in total.