Course contentsShow
← Web Development
Lesson 1249 of 2,98222. Responsive Images and MediaFree lesson

Understanding Native Lazy Loading

How the loading attribute works and its browser support for images and iframes.

Understanding Native Lazy Loading

What you'll learn: How to defer loading images and iframes until they're needed using the native loading attribute.

Native lazy loading is a browser feature that delays loading images and iframes until the user scrolls near them, rather than loading everything the moment the page loads. Think of it like a restaurant that only starts cooking your meal when you sit down, instead of preparing every possible order in advance.

How the loading Attribute Works

The loading attribute accepts three values:

  • lazy – Defers loading until the element is close to the viewport
  • eager – Loads immediately (browser default behavior)
  • auto – Lets the browser decide (same as omitting the attribute)

When you add loading="lazy" to an image or iframe, the browser waits to download it until the user scrolls within a certain distance (typically a few hundred pixels, but browser-dependent).

Basic Syntax

<img src="large-photo.jpg" alt="Scenic view" loading="lazy">

<iframe src="embed-video.html" loading="lazy"></iframe>

Browser Support

Native lazy loading has strong support in modern browsers:

  • Chrome/Edge: Supported since version 77 (2019)
  • Firefox: Supported since version 75 (2020)
  • Safari: Supported since version 15.4 (2022)

Older browsers simply ignore the loading attribute and load images normally, making it a safe progressive enhancement. No JavaScript libraries needed!

What Gets Lazy Loaded

Only off-screen images and iframes benefit. The browser automatically loads anything visible in the initial viewport immediately, even with loading="lazy", ensuring users see content right away.

Key Takeaway: The loading="lazy" attribute is a simple, widely-supported way to improve page performance by deferring off-screen images and iframes until needed, with no JavaScript required.