How to lazy load images

Kevin Powell on YouTubeWatch on YouTube

SaveMark complete

Sign in to save videos and track what you’ve finished.

IntermediateUI12 min

About this video

Shows how to lazy load images in the browser with the Intersection Observer API, using rootMargin so each image loads just before it scrolls into view. It is part of a series on Intersection Observer and assumes familiarity with HTML and JavaScript.

What you’ll learn

  • Lazy load images with the Intersection Observer API
  • Use rootMargin to load images before they enter the screen
  • Swap image sources as elements scroll into view