Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For images below the initial viewport, add loading="lazy" to the <img> element and give it accurate dimensions. Keep the hero image and other content visible at the top of the page eager so they can load promptly. Lazy loading can avoid fetching images a visitor never reaches, but it does not shrink or compress the files.

Use native lazy loading for below-the-fold images

For a typical image that is not initially visible, the browser-managed loading attribute is the simplest option:

<img
  src="/images/article-photo.jpg"
  width="1200"
  height="800"
  loading="eager"
  alt="A description of the image"
>

The attribute accepts lazy or eager. With lazy, the browser waits to fetch the image until it estimates the image is close enough to the viewport. You do not set that distance in the HTML, and it can vary by browser and conditions. MDN describes native loading as widely available: MDN: HTMLImageElement loading property.

Choose based on where the image appears

  • Below the fold and non-critical: use loading="lazy". The browser can defer the request, and may not need to fetch the image if the visitor never scrolls to it.
  • Visible when the page opens: omit the attribute or set loading="eager". Do not make users wait for content already in view.
  • Likely Largest Contentful Paint (LCP) image: keep it eager so the browser can discover and request it promptly. Applying lazy loading to the hero image can delay the page’s main visible content. See MDN / DebugBear’s LCP image-loading guidance.

Do not add loading="lazy" to every image as a blanket rule. For an important image whose request should receive higher relative priority, consider fetchpriority="high" selectively. It is a hint, not a way to make an image smaller, and older browsers may not support it. MDN marks the property newly available since October 2024: MDN: fetchPriority property.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Reserve space to prevent images from shifting the page

Set the image’s intrinsic width and height, or reserve the same aspect ratio in CSS. That gives the browser enough information to allocate space before the file arrives. Without known dimensions, an unloaded lazy image can initially have a zero-sized box; when it loads, content below it may jump.

<img
  src="/images/article-photo.jpg"
  width="1200"
  height="800"
  loading="eager"
  alt="A description of the image"
>

The values should describe the image’s intrinsic dimensions, not necessarily the size at which it will be displayed. CSS can scale it responsively while preserving its ratio:

img {
  max-width: 100%;
  height: auto;
}

MDN explains that dimensions let the browser calculate the aspect ratio early and reserve layout space: MDN: <img> element.

Pair loading strategy with responsive images

Lazy loading controls when the browser fetches an image. It does not choose a smaller file or compress one. Use responsive markup to offer suitable sources for different display sizes and resolutions:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<img
  src="/images/photo-1200.jpg"
  srcset="/images/photo-480.jpg 480w,
          /images/photo-800.jpg 800w,
          /images/photo-1200.jpg 1200w"
  sizes="(max-width: 600px) 100vw, 800px"
  width="1200"
  height="800"
  loading="eager"
  alt="A description of the image"
>

In this example, srcset lists candidate files and their widths; sizes tells the browser how wide the image is expected to appear at different viewport sizes. The browser selects a suitable candidate. Use <picture> when you need art direction or alternative formats. Avoid JavaScript that waits for viewport detection and then swaps in a smaller source: the browser may already have started downloading the original. See MDN: Using responsive images in HTML.

Compression, image format, and appropriately sized source files are separate optimizations. The right choices depend on the images and delivery requirements; lazy loading alone does not determine them. MDN treats these as complementary image-performance considerations: MDN: Multimedia images.

When JavaScript observation is useful

For ordinary image deferral, native loading="lazy" lets the browser manage proximity and avoids custom observation code. Use JavaScript with IntersectionObserver when the behavior genuinely needs custom rules based on an element entering or leaving the viewport—for example, when revealing or activating other content as it approaches. MDN discusses native lazy loading and Intersection Observer in its performance guidance: MDN: HTML performance optimization.

Native lazy loading is deferred only when JavaScript is enabled, as an anti-tracking measure. Also, a lazy image can still be pending after the window’s load event. If your application needs to know whether a particular image has finished, inspect that image’s complete property rather than treating the window event as proof. See MDN: Lazy loading.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to check whether lazy loading is helping

  1. Inspect the page at its initial viewport and identify which images are visible, especially the likely LCP image.
  2. Confirm that only appropriate off-screen images have loading="lazy", and that visible or critical images are not being deferred.
  3. Check that image dimensions or equivalent CSS aspect-ratio space are reserved to avoid layout shifts.
  4. Inspect responsive markup and requested image files to confirm the browser can choose appropriately sized candidates; lazy loading does not reduce file size.
  5. Compare page behavior under the same browser, viewport, network conditions, and page content before and after the change. There is no universal percentage improvement: results depend on the page, images, network, and browser.

Troubleshooting common problems

The hero image appears late

Check whether the hero or another initially visible, likely-LCP image has loading="lazy". Remove the attribute or set loading="eager"; consider fetchpriority="high" only when the image warrants a priority hint.

The page jumps when an image appears

Add accurate width and height attributes, or reserve the image’s aspect ratio in CSS. Ensure responsive styling does not discard the reserved ratio.

Images still download even if visitors do not scroll

The browser chooses when an image is close enough to fetch, and that proximity threshold is not an author-set pixel value. Lazy loading is not a guarantee that every off-screen image will remain unfetched in every session. Check that the target images are genuinely below the fold and are marked lazy.

Code tied to the window load event misses images

Do not use the window load event as proof that lazy images have completed. Check the relevant image’s complete property or use image-specific load/error handling appropriate to the application.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

There is no deferral when JavaScript is disabled

This is expected: native lazy-loading deferral is disabled when JavaScript is off. If no-JavaScript behavior is a requirement, account for that in the page’s design rather than assuming the browser will defer the images.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your goal is to capture a web page rather than change its implementation, ScreenshotNeo is a website screenshot API and MCP server. One GET request returns a screenshot or PDF; it does not alter the target site’s loading strategy.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo documentation for request options. Cookie and consent banners, newsletter popups, and chat widgets can be removed before capture; those steps can be turned off. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.