DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk5 min

How to Lazy Load Images for Faster Page Loads

Defer below-the-fold images with native HTML lazy loading, while keeping important first-screen images prompt and preventing layout shifts with dimensions.
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 include its dimensions. Keep the hero or other important image visible on first load eager so it can load promptly. Native lazy loading can reduce early image requests, but it does not shrink image files or guarantee a particular speed improvement.

Use native lazy loading for below-the-fold images

For an ordinary image that is not initially visible, use the browser-managed loading attribute:

As an Amazon Associate I earn from qualifying purchases.

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

Replace the path, dimensions, and alternative text with values for your image. The width and height should reflect its intrinsic dimensions or at least the same aspect ratio. The browser defers fetching a lazy image until it is within a browser-calculated distance of the viewport; the attribute does not let you set that distance. MDN describes the feature as widely available: HTMLImageElement: loading property.

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

Choose lazy or eager by the image’s role

  • Use loading="lazy" for non-critical images well below the initial viewport.
  • Leave loading off, or set loading="eager", for images initially visible or important to the first screen, especially the likely Largest Contentful Paint (LCP) image.

Do not lazy-load every image indiscriminately. Deferring a visible hero image may delay the page’s main content, while off-screen images may never be requested if the reader does not scroll to them. MDN’s guidance on improving LCP explains the importance of making the principal image available promptly: Optimize Largest Contentful Paint.

Prevent image loading from shifting the page

Give each image accurate width and height attributes, as in the example above, or reserve the same aspect-ratio space in CSS. The browser can calculate the ratio before the file arrives and allocate room in the layout. Without known dimensions, an unloaded lazy image can initially have a zero-sized box, then push nearby content aside when it loads. See MDN’s <img> reference.

Lazy loading does not choose or optimize the image file

loading="lazy" controls when an image is fetched, not how many bytes it takes to download. For responsive images, provide candidates with srcset and a sizes description so the browser can select an appropriate source. Use <picture> when you need art direction or format alternatives. MDN’s responsive images guide explains these options.

<img
  src="/images/photo-800.jpg"
  srcset="/images/photo-400.jpg 400w, /images/photo-800.jpg 800w, /images/photo-1200.jpg 1200w"
  sizes="(max-width: 600px) 100vw, 800px"
  width="1200"
  height="800"
  loading="lazy"
  alt="A description of the image"
>

The values in srcset and sizes must match the images and layout on your site; this example is a pattern, not a universal sizing formula. Avoid using JavaScript to swap in a smaller source only after detecting that an image is near the viewport. The browser might already have started downloading the original, resulting in an unnecessary second request. Compression, format choice, and suitable image dimensions are complementary decisions; there is no single format or compression setting that fits every site. MDN covers these considerations in its image guide.

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

When to use JavaScript instead

For ordinary image deferral, native loading="lazy" is simpler: the browser handles proximity and scheduling. Use an Intersection Observer when your application needs custom behavior based on an element entering or leaving the viewport, such as triggering a coordinated interface change. The available guidance does not establish a general performance advantage for a JavaScript observer over native loading.

Frameworks and content management systems may expose their own image components or settings. Their configuration depends on the platform; apply the same principles—defer non-critical off-screen images, keep critical images promptly discoverable, and reserve layout space.

Priority hints for important images

If an important image needs an explicit priority hint, fetchpriority="high" can signal that the browser should prioritize it relative to other resources:

<img
  src="/images/hero.jpg"
  width="1600"
  height="900"
  fetchpriority="high"
  alt="A description of the hero image"
>

Use the hint sparingly, usually for a key image such as the likely LCP image. It is a browser hint, not a way to reduce file size, and it does not replace responsive image selection. MDN marks fetchPriority newly available since October 2024 and notes that older browsers may not support it: HTMLImageElement: fetchPriority property.

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

Check behavior and diagnose common problems

Verify loading in the browser

  1. Inspect the rendered image element and confirm it has loading="lazy" only when it is intended to be deferred.
  2. Confirm the element has width and height attributes or equivalent reserved space in CSS.
  3. Use your browser’s developer tools network panel to see when image requests begin as you load the page and scroll. Compare with the same page without lazy loading; results depend on the page, image set, browser, and network, so do not assume a fixed percentage gain.
  4. Check that responsive candidates are available and that the browser is not downloading an unnecessarily large source for the rendered size.

Image appears late or the main content is delayed

If an image is visible immediately but arrives late, remove loading="lazy" or use loading="eager". For a genuinely important image, consider fetchpriority="high" as a hint. Also check whether the selected source is larger than needed; priority does not make a file smaller.

Content jumps when an image appears

Add accurate dimensions or reserve the image’s aspect ratio in CSS. Check that the reserved ratio matches the delivered image; a mismatch can still cause layout changes.

All images load immediately, or a lazy image is still missing

Native lazy loading is deferred only when JavaScript is enabled, as an anti-tracking measure. Also remember that the browser—not the HTML attribute—decides how near the viewport an image must be before fetching it. Do not depend on a fixed pixel threshold. MDN describes these caveats in its lazy-loading guide.

The window load event fired, but an image is not complete

A lazy image can still be pending when the window’s load event fires. If application code needs to know whether a particular image completed, inspect that image’s complete property rather than treating the window event as proof that every image is ready. The same MDN lazy-loading guide documents this behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

For a rendered screenshot of a page, ScreenshotNeo offers a one-call API instead of setting up a browser capture workflow. For example, this cURL request saves a WebP screenshot of a page:

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 API documentation for request options. ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are not billed. It also has an MCP server so AI agents can take screenshots. The free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000. ScreenshotNeo is a website screenshot API and MCP server from ScreenshotNeo; it captures rendered pages rather than changing your site’s image-loading behavior.

Sign up for 1,000 free screenshots a month, with no card required.

Frequently Asked Questions

Does loading="lazy" guarantee a faster page?

No. It can defer unnecessary early image requests, but the effect depends on the page, images, network, and browser.

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

Can I lazy-load a background image in CSS with the same attribute?

No. The loading attribute shown here applies to HTML image elements; CSS background images need a different implementation if they require deferred loading.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.