Lazy Loading Images: How It Works, How to Implement It and When It Makes Websites Slower
Where lazy loading belongs, where it actively damages LCP, and how to verify what was actually deferred.
In short
Lazy loading tells the browser not to download an image until the visitor scrolls near it. On a page with thirty images, that means downloading three instead of thirty.
It is one line:
<img src="/photo.webp" loading="lazy" width="800" height="600" alt="...">
And it has one rule that matters more than everything else about it: never lazy-load an image that is visible when the page opens. Doing that to your main image delays the exact thing Google measures, and it is the most common way people make a site slower while believing they are making it faster.
So lazy loading is not a setting you turn on everywhere. It is a decision you make per image, and the decision is simply: can the visitor see this without scrolling?
How it actually works
loading="lazy" is built into browsers. You add the attribute; the browser decides when to fetch.
The browser does not wait until the image is exactly on screen — it starts loading when the image comes within a certain distance of the viewport, so that in normal scrolling the image has usually arrived by the time you reach it. That distance is chosen by the browser and varies with connection speed: on a slow connection it starts earlier.
You do not control the threshold, and that is usually fine. It also means that on a fast connection you may see images pop in slightly; on a slow one the browser compensates.
Why it needs dimensions
A lazy image has no file to measure, so without width and height the browser reserves no space — and the page jumps when the image arrives. Lazy loading without dimensions trades a loading problem for a layout-stability problem.
Always set both. This is not optional with lazy loading; it is part of it.
Iframes too
The same attribute works on <iframe>, which matters more than it sounds: an embedded map or video player is far heavier than a photograph.
<iframe src="https://www.youtube-nocookie.com/embed/..." loading="lazy" width="560" height="315" title="..."></iframe>
When it makes things worse
This is the half of the topic most articles skip.
Lazy-loading the main image
Your largest visible element is what Largest Contentful Paint measures. loading="lazy" explicitly tells the browser it may wait before fetching it. You have asked the browser to delay the most important content on the page.
The result is a worse LCP, and it is entirely self-inflicted. You can see the difference in our performance lab — two identical pages, one with a lazy hero and one with an eager, prioritised one.
Lazy-loading anything in the first viewport
Not only the LCP element. Anything visible without scrolling will be fetched later than it should be, so the page assembles in front of the visitor instead of arriving complete.
Applying it with a blanket rule
The usual cause of both problems above. A site-wide rule, a plugin setting, or a theme option that adds loading="lazy" to every image on the site, including heroes. Many platforms do this automatically, which is why checking what your HTML actually contains matters more than knowing what you intended.
Lazy-loading too aggressively with JavaScript
A custom Intersection Observer implementation with a tight threshold waits until the image is almost on screen, so visitors see blank boxes while scrolling. The native behaviour is better tuned than most hand-written versions.
Using a placeholder that costs more than the image
Blurred low-quality placeholders are fashionable and sometimes worth it. But a base64 placeholder inlined into the HTML makes the HTML bigger for every visitor, and that HTML is on the critical path. For a page with forty products, this can cost more than it saves.
CSS background images
loading="lazy" only works on <img> and <iframe>. A CSS background-image is not lazy-loaded by the attribute.
Background images have a related problem: the browser cannot discover them until the stylesheet has downloaded and been parsed, so they are found late. If a background image is your main visible content, consider using a real <img> instead — you get discovery, priority control and lazy loading, none of which CSS backgrounds give you.
For decorative backgrounds far down the page, loading them only when the section is near the viewport requires JavaScript, or you can let content-visibility: auto on the section skip the rendering work.
Doing it properly, in practice
The pattern for a page with a hero and a grid below it:
<!-- Visible immediately: eager, prioritised, dimensions set -->
<img src="/hero.webp" fetchpriority="high" width="1600" height="900" alt="..."
sizes="100vw" srcset="/hero-800.webp 800w, /hero-1200.webp 1200w, /hero-1600.webp 1600w">
<!-- Below the fold: lazy, dimensions still set -->
<img src="/item-1.webp" loading="lazy" width="600" height="600" alt="..."
sizes="(min-width: 768px) 33vw, 100vw" srcset="/item-1-300.webp 300w, /item-1-600.webp 600w">
Note what is the same in both: width, height, srcset and sizes. Lazy loading replaces none of that. It is one additional decision on top of correct image delivery.
The first-image exception, generalised
A useful rule for templates: eager for images in the first screen, lazy for the rest. On a product gallery that means the first image eager and the others lazy. On a collection grid it means the first row eager — or, more simply, mark only the single largest visible image as high priority and lazy-load from the second row down.
Platform differences
WordPress adds loading="lazy" automatically. Recent versions try to skip images near the top of the page, but themes and page builders frequently defeat that, particularly sliders that render in JavaScript. Check the rendered HTML of your actual hero rather than assuming the automatic behaviour did the right thing.
Shopify. image_tag takes a loading parameter, so this is explicit and under your control. The thing to check is section settings and theme options that apply lazy loading globally.
Hosted builders. Lazy loading is typically applied by the platform and not configurable. If your hero is being lazy-loaded and you cannot change it, that is a platform limit rather than a mistake on your part — see what your platform allows.
Custom builds. Use the native attribute. A JavaScript implementation is only justified if you need behaviour the native one cannot express, and it costs main-thread time the native one does not.
Common mistakes
A blanket site-wide rule that catches every hero image.
Lazy loading without width and height, which causes layout shift.
Expecting it to help a single-image page. With one image above the fold, there is nothing to defer.
Lazy-loading images in an above-the-fold carousel, where the first slide is visible immediately.
Writing a custom implementation when the native attribute would do.
Assuming the attribute is present because a setting is switched on. Check the HTML.
Using loading="lazy" on a CSS background and expecting anything to happen.
Verification
- Reload without scrolling, with the cache disabled, and look at the Network panel. Below-the-fold images should be absent.
- Confirm the main image is still requested immediately. This is the check people skip, and it is the one that catches the damaging mistake.
- Scroll and watch images arrive. They should be there before you reach them, not after.
- Check LCP did not get worse. If it did, you have lazy-loaded something visible.
- Check CLS. Any shift as images arrive means dimensions are missing.
- Test on a slow connection, where both the benefit and any over-aggressive threshold are most visible.
- Then watch field data for four weeks.
When it still does not improve
- LCP got worse after enabling it → your hero is being lazy-loaded. Find the rule or setting doing it and exclude the first image.
- Images still all download on load → a gallery or slider script may be fetching them itself, regardless of the attribute. Check what the script does.
- Blank boxes appear while scrolling → likely a custom implementation with too tight a threshold. Prefer the native attribute.
- The page jumps as images arrive → dimensions are missing.
- No improvement at all → there may have been little to defer. Count how many images were below the fold before you started; if it is two, lazy loading was never going to be your win.
Keeping it right
The risk with lazy loading is not that it stops working. It is that someone later applies it globally, with good intentions, and catches every hero on the site.
Two things prevent that: make the eager-above-the-fold rule explicit in your templates so new pages inherit it, and include "is the LCP element still eager?" in your pre-release check. It takes ten seconds and catches the one mistake that matters.
Frequently asked questions
How does lazy loading images work?
Adding loading="lazy" tells the browser not to download an image until the visitor scrolls near it. The browser starts loading before the image is on screen, and starts earlier on slower connections, so in normal scrolling the image has usually arrived by the time you reach it.
Does lazy loading hurt SEO or Core Web Vitals?
Applied below the fold it helps. Applied to an image visible when the page opens — especially your LCP element — it directly delays the metric Google measures. That is the single most common way people make a site slower while believing they are making it faster.
Should I lazy-load all images?
No. Lazy-load everything below the fold and nothing above it. A blanket site-wide rule is the usual cause of a lazy-loaded hero, and many platforms apply one automatically, so check what your HTML actually contains.
Why do I need width and height with lazy loading?
A lazy image has no file to measure, so without dimensions the browser reserves no space and the page jumps when the image arrives. Lazy loading without dimensions trades a loading problem for a layout-stability problem.
Does lazy loading work on CSS background images?
No. The loading attribute only works on img and iframe elements. Background images also cannot be discovered until the stylesheet has downloaded and been parsed, so if a background image is your main visible content, consider using a real img element instead.
Should I write my own lazy loading with JavaScript?
Rarely. The native attribute is better tuned than most hand-written Intersection Observer implementations, costs no main-thread time, and adapts its threshold to connection speed. Write your own only if you need behaviour the native one cannot express.
References
- Browser-level image lazy loading — web.dev
- The loading attribute — MDN
- Optimize Largest Contentful Paint — web.dev