Skip to content

Search

Articles, tools, solutions and knowledge base guides

Start typing to search across articles, tools and apps.

How to optimize image loading: srcset, sizes, preload, lazy loading and LCP

Choosing AVIF, WebP, JPEG or PNG is only the first step of image optimization. Just as important is when the browser discovers an image, which candidate it selects, which fetch priority it receives and whether layout can reserve its space before the transfer completes. This article focuses only on image delivery: responsive images, LCP, preload, fetchpriority, lazy loading, resource discovery and browser diagnostics.

Published Written by Reading time 25 min read
On this page Contents: quick navigation between sections

A continuation of the format guide: now delivery is the problem

LayerQuestionGuide
Format and compressionAVIF, WebP, JPEG or PNG?WebP vs AVIF vs JPEG vs PNG [5]
DeliveryWhich candidate, when and at what priority?This article
MeasurementDid the browser actually behave as expected?Network, Performance, PageSpeed

POLPROG already has a separate guide comparing WebP, AVIF, JPEG and PNG. That article answers which format to choose and how to match it to the type of image. [5]

This article starts one step later: assume the format is already selected, then analyze how quickly the browser can discover the image, which candidate it downloads, which priority it receives and when it can render it.

The distinction matters technically. A very small AVIF file can still produce poor LCP if JavaScript reveals it late, while a correctly configured srcset can reduce transfer regardless of the codec. [6][14]

How the browser discovers an image

Embedding methodWhen it can be discoveredLCP risk
`` in initial HTMLDuring HTML parsingLowest
background-image in external CSSAfter CSS discovery, download and processingHigher
Image inserted by JavaScriptAfter JS download and executionHighest
Preload + later usePreload can start the request earlierUseful only when a real discovery delay exists

For a critical image, the best case is direct discovery while the initial HTML is being parsed. web.dev identifies resource discoverability as a major component of LCP resource load delay. [6]

A background image in external CSS may only be discovered after the stylesheet has been fetched and processed. An image created by JavaScript can appear even later because the script must first be fetched, parsed and executed. [6]

For hero and other critical imagery, improve the discovery path before adding more resource hints.

How srcset and sizes lead to a candidate choice

ViewportExample slotDPRApprox. required pixelsTypical candidate from 480w / 960w / 1440w
390 px390 px (100vw)1390 px480w
390 px390 px (100vw)2780 px960w
1440 px720 px (50vw)1720 px960w
1440 px720 px (50vw)21440 px1440w

With width descriptors such as 480w, 960w and 1440w, the browser first estimates the rendered slot from sizes and then considers factors including device pixel density. [1][13]

The table below is a simplified model, not a guarantee that every browser will pick exactly the same resource. Final selection belongs to the user agent. [1]

If the layout renders an image at 50vw but sizes="100vw" is supplied, the browser may estimate a slot twice as wide and choose an unnecessarily large candidate.

srcset and sizes: stop sending desktop images to phones

Responsive image with srcset and sizes

<img
  src="/images/product-960.jpg"
  srcset="
    /images/product-480.jpg 480w,
    /images/product-960.jpg 960w,
    /images/product-1440.jpg 1440w
  "
  sizes="(max-width: 700px) 100vw, 50vw"
  width="1440"
  height="960"
  alt="Application dashboard showing a sales chart"
/>

srcset with width descriptors lists available candidates, while sizes describes the expected rendered slot width. The browser can then consider viewport, layout and pixel density when selecting a file. [1][13]

When srcset uses w descriptors, accurate sizes is essential. If the browser assumes a much larger slot than the real layout, it may download a larger resource than necessary.

<picture> for format fallback and art direction

AVIF -> WebP -> JPEG example

<picture>
  <source
    type="image/avif"
    srcset="/images/hero-800.avif 800w, /images/hero-1600.avif 1600w"
    sizes="100vw"
  />
  <source
    type="image/webp"
    srcset="/images/hero-800.webp 800w, /images/hero-1600.webp 1600w"
    sizes="100vw"
  />
  <img
    src="/images/hero-1600.jpg"
    width="1600"
    height="900"
    alt="Team working on an application interface"
  />
</picture>

<picture> lets the browser evaluate <source> elements by type and media conditions, while the child <img> provides fallback content, dimensions, alt text and other image attributes. [3]

It works well for AVIF or WebP alternatives with a JPEG fallback, and for art direction where mobile needs a different crop or composition rather than merely a smaller copy of the desktop image.

The LCP image must be discovered early

web.dev recommends making the LCP resource discoverable from the initial HTML whenever possible. An image revealed only after JavaScript runs or after external CSS is processed creates extra request dependencies. [6]

If the LCP element is a normal image, put the <img> in the HTML. For an important CSS background, preload can be appropriate because the browser would otherwise discover the resource only after fetching and parsing CSS. [6][8]

Use fetchpriority="high" selectively

Hero image likely to become LCP

<img
  src="/images/hero-1600.avif"
  width="1600"
  height="900"
  fetchpriority="high"
  loading="eager"
  alt="Main view of an analytics application"
/>

fetchpriority provides a browser hint about relative fetch importance. MDN lists an LCP image as a typical case where high can help. [4]

Do not mark many images as high priority. Network prioritization is competitive, so boosting too many resources weakens the signal. Chrome guidance recommends reserving high priority for truly critical resources. [8]

Lazy loading is for offscreen images, not LCP

Below-the-fold gallery image

<img
  src="/images/gallery-960.avif"
  srcset="/images/gallery-480.avif 480w, /images/gallery-960.avif 960w"
  sizes="(max-width: 700px) 100vw, 50vw"
  width="960"
  height="640"
  loading="lazy"
  decoding="async"
  alt="Detailed view of an application interface"
/>

loading="lazy" defers an image until it approaches the viewport, reducing initial bytes and competition for network resources. [2]

Do not lazy-load an LCP or another important initially visible image. web.dev and Chrome warn that this introduces unnecessary resource-load delay and hurts LCP. [6][8]

width and height reduce CLS

With explicit width and height, the browser can derive an aspect ratio before the resource has loaded and reserve the expected space, reducing layout shifts. [2][14]

Those intrinsic dimensions do not prevent responsive CSS. The element can still use max-width: 100% and height: auto; the attributes mainly provide the browser with an early aspect ratio.

Preload only when early discovery is not enough

Responsive preload for a critical image

<link
  rel="preload"
  as="image"
  imagesrcset="/images/hero-800.avif 800w, /images/hero-1600.avif 1600w"
  imagesizes="100vw"
  fetchpriority="high"
/>

Preload can start an important image earlier when it would otherwise be discovered through CSS or JavaScript. For responsive images, HTML defines imagesrcset and imagesizes so the preload can use the same candidate-selection logic as the later image. [11][12]

Avoid preloading everything. If an image is already visible to the preload scanner in early HTML, extra preload may add no value. Preloading multiple alternative formats can also waste bandwidth through duplicate downloads. [7][12]

decoding="async" is a hint, not an LCP fix

The decoding attribute lets developers express a preference for image decoding. async allows decoding to happen asynchronously relative to presenting other content, while auto leaves the decision to the browser. [2]

Do not use it as a substitute for proper discovery and priority. For LCP, resource discovery, transfer and priority usually matter more than the decoding hint itself.

CSS background images are weaker for discovery and image SEO

A background image referenced in external CSS is discovered later than an <img> in the initial HTML. If it becomes LCP, preload or a semantic markup change may be warranted. [6]

Google Search Central also states that Google Images discovers standard <img> resources, including those inside <picture>, but does not index CSS background images as images. [9]

Semantics and SEO: the technical difference between <img> and CSS backgrounds

Use caseBetter mechanismReason
Content hero` / `Early discovery, alt text, responsive images, LCP control
Product or article image` / `Semantics and indexability
Decorative textureCSS backgroundNot document content
Background that becomes LCPConsider `` or targeted preloadCSS can delay discovery

This article does not repeat a complete image SEO guide, but one technical consequence matters: Google Search Central processes images in <img>, including inside <picture>, while CSS background images are not indexed as images in Google Images. [9]

When an image is page content rather than decoration, <img> also provides semantics, alt text, intrinsic dimensions and responsive-image controls. CSS backgrounds remain appropriate for decoration, but should not automatically replace content images.

Common mistakes

Frequent problems include one huge file for every viewport, lazy-loading the hero, missing sizes, missing dimensions, too many fetchpriority="high" hints, preloading every format and converting every image type to one codec. [1][6][7][8]

Another mistake is judging optimization only by kilobytes. An aggressively compressed image can look bad, and a very small file can still hurt LCP if it is discovered too late.

A practical image optimization workflow

Start by measuring the page and identifying which images load during startup and which element becomes LCP. Then create realistic size variants, test formats and quality, add dimensions, configure srcset and sizes, and apply lazy loading only to offscreen content.

Finally recheck Network, Performance and PageSpeed Insights. For SEO, verify that important images use standard HTML, descriptive alt text, stable URLs and nearby textual context. Google emphasizes both image quality and page performance. [8][9]

  • Identify the LCP image and never lazy-load it.
  • Generate several useful widths instead of one oversized master for every viewport.
  • Use srcset together with accurate sizes for width-based variants.
  • Set width and height on important <img> elements.
  • Choose formats after testing quality and size rather than following one universal rule.
  • Reserve fetchpriority="high" for the most important image.
  • Use preload only when it removes a real discovery delay.
  • Measure on the real page and under slower network conditions.

Once the image format is chosen, the main task is to deliver the right candidate at the right time. srcset and sizes reduce unnecessary transfer, early HTML discovery and correct priority help LCP, dimensions stabilize layout, and lazy loading reduces startup work when used offscreen. A strong image pipeline is not based on one attribute, but on correct resource discovery, candidate selection and measurement of the real request waterfall.

Tools for this topic

Responsive Images srcset sizes Lazy Loading Largest Contentful Paint LCP fetchpriority Preload CLS Image Loading Web Performance Resource Priority Frontend Performance

Frequently asked questions

Is AVIF always better than WebP?

No. AVIF often compresses extremely well, but the best format depends on image content, quality, transparency, encoding cost and compatibility requirements. [5]

Should every image use loading="lazy"?

No. Lazy loading is mainly for offscreen images. An LCP image should not be lazy-loaded. [2][6]

Why use srcset and sizes?

They let the browser choose a resource based on rendered slot width, viewport and pixel density instead of always downloading the largest file. [1][13]

Do width and height break responsive design?

No. They provide intrinsic dimensions and aspect ratio, while CSS can still scale the image responsively. [2][14]

When should I use <picture>?

Use it for format alternatives, different crops or other art-direction decisions based on media conditions. [3]

Should every above-the-fold image use fetchpriority="high"?

No. Use it sparingly, normally for the most important LCP candidate. Too many high priorities reduce the usefulness of prioritization. [4][8]

When should an image be preloaded?

When an important resource would otherwise be discovered late, such as a CSS background or an image created after JavaScript runs. [6][12]

Can responsive images be preloaded?

Yes. HTML supports imagesrcset and imagesizes on <link rel="preload" as="image">. [11][12]

Are CSS background images good for image SEO?

Not for important indexable imagery. Google says it discovers <img> resources, including inside <picture>, but does not index CSS background images in Google Images. [9]

Should alt text contain keywords?

It should naturally describe the image in context. Google discourages keyword stuffing. [9][10]

Will decoding="async" improve LCP?

Do not assume so. It changes a decoding preference, while LCP is usually more affected by discovery, priority, transfer and rendering. [2][6]

Can images be hosted on a CDN?

Yes. Google even allows cross-domain image URLs in image sitemaps. Keep URLs stable, crawlable and correctly cached. [9]

Sources and references

  1. MDN, Using responsive images in HTML↩1↩2↩3↩4↩5
  2. MDN, <img> element↩1↩2↩3↩4↩5↩6
  3. MDN, <picture> element↩1↩2
  4. MDN, fetchpriority attribute↩1↩2
  5. POLPROG, WebP vs AVIF vs JPEG vs PNG↩1↩2↩3
  6. web.dev, Optimize Largest Contentful Paint↩1↩2↩3↩4↩5↩6↩7↩8↩9↩10↩11
  7. web.dev, Responsive images↩1↩2
  8. Chrome for Developers, Modern Web Guidance: Performance↩1↩2↩3↩4↩5↩6
  9. Google Search Central, Image SEO best practices↩1↩2↩3↩4↩5↩6
  10. Google Search Central, SEO Starter Guide↩
  11. WHATWG HTML Standard, responsive image preload↩1↩2
  12. web.dev, Preload responsive images↩1↩2↩3↩4
  13. MDN, HTMLImageElement.sizes↩1↩2↩3
  14. MDN, Multimedia performance: images↩1↩2↩3

Was this helpful?

Get new articles by email

One short email per new Learning article. No spam, unsubscribe in one click.

We only use your email to send new articles. No third-party sharing.

Back to Learning