Native Image Lazy Loading with loading="lazy"
What you'll learn: How to defer offscreen image loading using a single HTML attribute—no JavaScript required.
The Core Idea
Modern browsers support native lazy loading through the loading attribute on <img> elements. When you set loading="lazy", the browser automatically defers loading images that are below the fold (not immediately visible in the viewport). Images only download as the user scrolls near them, reducing initial page weight and improving load times.
This is performance optimization made simple: instead of writing custom JavaScript with Intersection Observers or scroll listeners, you let the browser handle everything.
How It Works
The browser calculates a "lazy load threshold" based on connection speed and device type. When an image enters this threshold (typically a few hundred pixels before becoming visible), the browser fetches it just in time.
<!-- This image loads immediately -->
<img src="hero.jpg" alt="Hero banner" loading="eager">
<!-- This image loads only when user scrolls near it -->
<img src="product-photo.jpg" alt="Product" loading="lazy">
<!-- Auto is the default (browser decides) -->
<img src="logo.png" alt="Logo" loading="auto">
When to Use Each Value
loading="lazy": For below-the-fold images, carousels, product galleries, blog post imagesloading="eager": For critical above-the-fold images that must appear immediatelyloading="auto": Browser default behavior (rarely needed explicitly)
Browser Support and Fallback
Native lazy loading works in all modern browsers (Chrome, Edge, Firefox, Safari). Older browsers simply ignore the attribute and load images normally—a perfect progressive enhancement.
Key Takeaway: Use loading="lazy" on offscreen images to automatically defer their loading without JavaScript, improving initial page performance with zero code complexity.