Native Lazy Loading with loading Attribute
You'll learn how to defer image and iframe loading until they're about to enter the viewport using one simple HTML attribute.
What Is Native Lazy Loading?
By now, you've learned about custom lazy loading implementations using the Intersection Observer API. But modern browsers offer a simpler built-in solution: the loading attribute. Think of it as a "defer until visible" instruction written directly into your HTML—no JavaScript required.
How the loading Attribute Works
Add loading="lazy" to any <img> or <iframe> tag, and the browser automatically delays loading that resource until the user scrolls near it:
<img src="product.jpg" alt="Product photo" loading="lazy">
<iframe src="map.html" loading="lazy"></iframe>
The browser monitors scroll position and begins fetching the resource when it's within a certain distance of the viewport (usually a few hundred pixels). This distance varies by browser and connection speed.
When to Use It
Use loading="lazy" for:
- Below-the-fold images and iframes
- Long pages with many images
- Image galleries or product listings
- Embedded maps or social media widgets
Don't use it for critical above-the-fold content or your Largest Contentful Paint (LCP) image—those should load immediately with loading="eager" (or no attribute, since eager is the default).
Browser Support Considerations
Most modern browsers support native lazy loading. For older browsers, the attribute is safely ignored—images simply load normally. You can combine it with JavaScript-based lazy loading as a fallback if needed.
Key Takeaway: The loading="lazy" attribute provides zero-JavaScript, browser-native lazy loading for images and iframes, reducing initial page weight without any complex implementation.