Skip to content

Lazy loading

Deferring image downloads until they're actually needed, cutting initial page weight and improving load times.

On this page

Definition

Lazy loading means an image is only fetched when it approaches the viewport. In modern browsers it needs no JavaScript: add loading="lazy" to the <img> tag. The browser estimates each image's position and loads off-screen images just before they scroll into view.

In practice

Lazy-load everything below the fold — never the hero image, which is usually the LCP element and should load eagerly with fetchpriority="high". Without lazy loading, a long page with 40 images downloads all of them immediately; with it, a visitor who reads two paragraphs never downloads most of them.

The hero-image rule here exists because the hero is usually the LCP element — one of the Core Web Vitals.

The exception that hurts most sites

The single most common performance mistake with lazy loading is applying it to the wrong image — and the mistake makes pages measurably slower, not faster.

Google's Largest Contentful Paint metric measures when the biggest element in the viewport finishes rendering. On most pages that element is the hero image. If you lazy-load it, you have told the browser to delay the one image the metric depends on: it must first compute layout, decide the image is near the viewport, then start the download. That delay lands directly on your LCP score.

The correct treatment for a hero image is the opposite of lazy: fetchpriority="high" so the browser prioritises it, plus a preload hint in the document head so the download begins before the parser reaches the tag. Lazy loading belongs on everything below the fold, which is where it does its real work.

What lazy loading does not fix

Lazy loading is often presented as a general performance cure. It is not, and treating it as one leads to disappointment.

It does not reduce page weight for a short page. If all your images are visible on load, lazy loading changes nothing at all — there is nothing off-screen to defer.

It does not compress anything. A 4 MB hero image is still 4 MB. Lazy loading might stop it loading immediately, but on the pages that matter it is usually the image that must load first. Compression and correct sizing are what reduce weight; lazy loading only changes when things arrive.

It does not reliably stop the layout shifting. If an image has no width and height, the browser reserves zero space for it and the page reflows when it finally loads. That is a Cumulative Layout Shift problem, and lazy loading makes it more likely, not less. Always set explicit dimensions or an aspect-ratio box.

How to tell whether it is working

This is one of the easier claims to verify, and worth checking rather than trusting.

Open your browser's network panel, load the page, and filter to images. On a lazy-loaded page you should see only the images in and near the viewport requested on initial load. Scroll down and further requests appear as you go.

If every image is requested at once, lazy loading is not taking effect — usually because the attribute is missing, or because a JavaScript carousel is setting image sources before the browser can defer them. If the hero image request appears late, after stylesheets and scripts, that is the LCP problem described above and it is worth fixing first.

Compress your images now — free and private

Process up to 200 images locally. Choose a format, compare the results and download a ZIP.

Open the compressor
100% private No signup

Frequently asked questions

It's deferring an image's download until it's about to enter the viewport. In modern browsers it's built in: add loading="lazy" to an <img> tag and the browser handles the rest, no JavaScript required.

No. The hero image is usually the Largest Contentful Paint element, and lazy loading it delays the single most important render on the page. Load it eagerly with fetchpriority="high" and a preload hint. Lazy-load only below-the-fold images.

It can improve LCP on long pages by stopping off-screen images from competing for bandwidth with the hero image. It does not help CLS — and can worsen it if images lack width and height attributes, because the browser reserves no space for them before they load.

No. It changes when an image is downloaded, not how large it is. The only way to reduce page weight is to compress images and serve them at appropriate dimensions. Lazy loading is a scheduling improvement, not a size reduction.

Open the browser network panel and load the page. Only images in or near the viewport should be requested initially; more should appear as you scroll. If every image loads immediately, the attribute is missing or a script is overriding it.