Free SEO audit for new clients — claim yours
Home/Blog/Technical SEO/Responsive Images With srcset and sizes: Serve t…
Technical SEO

Responsive Images With srcset and sizes: Serve the Right Image to Every Device

Responsive Images With srcset and sizes: Serve the Right Image to Every Device
Table of contents
  1. Why one image file cannot serve a phone and a 4K monitor
  2. How srcset and sizes work together
    1. When the x descriptor is the better tool
  3. The picture element for art direction and format switching
  4. How WordPress, Shopify and other platforms generate responsive images
    1. WordPress
    2. Shopify
    3. Other platforms and image CDNs
  5. Testing which image file the browser actually downloads
  6. A worked example: fixing a blog hero image
  7. What responsive images change for LCP and Google Images
  8. Questions about srcset, sizes and picture
    1. Do I need both srcset and sizes?
    2. How many widths should I include in srcset?
    3. Does Google index images in srcset or picture elements?
    4. Should the LCP hero image be lazy-loaded?
    5. Does WordPress add srcset automatically?
  9. Fixing oversized images on your site this week
  10. Further reading on responsive images srcset
  11. Sources for this responsive images guide

Upload a 2,400-pixel-wide photo to a blog post, drop it into a column that is 390 pixels wide on a phone, and many sites will send the full 2,400-pixel file to every visitor. The phone downloads several times more data than it can display, decodes it on a modest processor, and only then paints the hero image. That image is very often the Largest Contentful Paint element, so the waste lands directly on a Core Web Vital.

Responsive image markup fixes this by giving the browser a menu of file sizes and enough information to pick the right one before it has laid out the page. The attributes involved, srcset and sizes, are not difficult, but they are easy to get subtly wrong, and a wrong sizes value can make things worse than having none at all.

This guide explains the markup in plain language, shows how WordPress and Shopify generate it for you (and where they need help), walks through testing which file a browser actually downloaded, and covers what responsive images mean for LCP and Google Images.

Why one image file cannot serve a phone and a 4K monitor

Two variables decide how many pixels an image really needs: the width of the slot it occupies in the layout (in CSS pixels) and the device pixel ratio (DPR) of the screen. A phone with a 390 CSS-pixel-wide viewport and a DPR of 3 has 1,170 physical pixels across. A laptop showing the same image in a 700-pixel column at DPR 2 needs 1,400. A desktop monitor at DPR 1 in an 1,100-pixel column needs 1,100.

Shopify's performance team notes that nearly all mobile devices, and some laptops and desktops, have a DPR of 2 or more, and many phones are at 3 or higher (Responsive images on Shopify with Liquid). They also point out that people with normal vision struggle to see much difference above 2x at typical viewing distances, which is why capping density at 2x is a common, sensible saving.

MDN frames the two distinct problems that responsive images solve:

  • Resolution switching: the same picture, served at different file sizes for different slot widths and densities. This is what srcset and sizes handle.
  • Art direction: a different crop or composition for different layouts, such as a tight portrait crop on mobile and a wide landscape on desktop. This is what the <picture> element handles.
ScenarioSlot width (CSS px)DPRPixels neededWaste if you send a 2,400 px file
Phone, full-width hero39031,170About 2x wider than needed (roughly 4x the pixels)
Phone, capped at 2x3902780About 3x wider (roughly 9x the pixels)
Tablet, two-column grid3802760About 3x wider
Laptop, article column70021,400About 1.7x wider
Desktop, wide hero1,20022,400None

Pixel count grows with the square of width, so an image twice as wide as needed carries roughly four times the pixels to decode. File size does not scale perfectly with pixels, but the direction is the same.

How srcset and sizes work together

Think of srcset as a list of files and their real widths, and sizes as a description of how wide the image will be displayed. The browser combines the two with its own knowledge of the screen and picks the best file.

<img
  src="sofa-1200.jpg"
  srcset="sofa-400.jpg 400w,
          sofa-800.jpg 800w,
          sofa-1200.jpg 1200w,
          sofa-1600.jpg 1600w"
  sizes="(min-width: 1024px) 700px, 100vw"
  width="1600" height="1067"
  alt="Grey three-seat sofa with oak legs in a bright living room">

Reading it aloud: "Here are four versions of this image, 400 to 1,600 pixels wide. On screens at least 1,024 pixels wide, the image is shown at 700 CSS pixels; otherwise it fills the viewport width." A phone at 390 CSS pixels and DPR 3 needs about 1,170 pixels, so it will normally take the 1,200 version. A laptop at DPR 2 needs 1,400 and takes the 1,600 version.

MDN describes the selection logic: the browser finds the first media condition in sizes that is true, reads the slot width, and loads the srcset candidate closest to that size, choosing the next larger one if there is no exact match. Rules worth memorising:

  • The w descriptor is the file's real pixel width, not the display width. Lying here breaks the maths.
  • Order in sizes matters. The first matching condition wins, so put the most specific ones first and end with a default without a condition.
  • Percentages are not allowed in sizes. Use vw, px, em or calc().
  • Without sizes, browsers assume 100vw, which on a desktop with a narrow content column means downloading a much bigger file than needed. Shopify's documentation flags a missing sizes value as a reason the browser defaults to the largest image.
  • Always keep src. It is the fallback for older clients and, as Google notes, for crawlers.
  • Always set width and height so the browser can reserve space and avoid layout shift.

When the x descriptor is the better tool

For images displayed at a fixed CSS size everywhere, such as a 64-pixel logo or an avatar, use density descriptors and skip sizes:

<img src="logo-64.png"
     srcset="logo-64.png 1x, logo-128.png 2x"
     width="64" height="64" alt="Acme Home logo">

MDN quotes the core syntax rule plainly:

“Each set of image information is separated from the previous one by a comma.”

— MDN Web Docs, Using responsive images in HTML

The picture element for art direction and format switching

When a mobile layout needs a different crop, not just a smaller file, use <picture>. Each <source> has a media condition; the first one that matches wins, and the inner <img> is both the default and the element that carries alt, width and height.

<picture>
  <source media="(max-width: 767px)"
          srcset="kitchen-portrait-600.jpg 600w, kitchen-portrait-900.jpg 900w"
          sizes="100vw">
  <source media="(min-width: 768px)"
          srcset="kitchen-wide-1200.jpg 1200w, kitchen-wide-2000.jpg 2000w"
          sizes="(min-width: 1280px) 1200px, 100vw">
  <img src="kitchen-wide-1200.jpg" width="1200" height="600"
       alt="Open-plan kitchen with island and pendant lights">
</picture>

<picture> can also switch formats with the type attribute, for example offering AVIF, then WebP, then JPEG. Many CDNs and platforms now negotiate format automatically instead, which keeps markup simpler; see our guide to WebP and AVIF formats.

MDN advises using media on <source> only for art direction, and not duplicating media conditions inside sizes for the same purpose.

How WordPress, Shopify and other platforms generate responsive images

You rarely need to hand-write this markup on a CMS. The question is whether the platform's defaults fit your theme.

WordPress

Since version 4.4, WordPress has added srcset and sizes to images in post content, built from the intermediate sizes it creates on upload. The core team’s announcement lists the defaults: a sizes value of (max-width: {image-width}px) 100vw, {image-width}px, and a max_srcset_image_width limit, of which they say: "The default value is 1600px." Themes and developers can change both through the wp_calculate_image_sizes and wp_calculate_image_srcset filters.

The default sizes assumes the image can be as wide as its own file. In a theme with a 720-pixel content column, a 1,600-pixel upload would be described as up to 1,600 pixels wide, so desktops may download more than needed. A good theme overrides sizes to match its layout. Images inserted by page builders or hard-coded in templates may bypass all of this; check them separately. More platform detail is in our WordPress speed optimisation guide.

Shopify

Shopify themes use Liquid filters. The image_url filter sets the maximum width and serves modern formats from Shopify's CDN, and image_tag outputs the <img> with srcset, sizes, width and height. According to the image_tag reference, Shopify generates a default srcset "with a smart set of default widths up to the maximum defined in the image URL", and lazy-loads images lower on the page unless preload is used. Shopify's own example:

{{ product.featured_image
  | image_url: width: 1000
  | image_tag:
      widths: '400, 600, 800, 1000',
      sizes: '(min-width: 1000px) 900px, calc(100vw - 2rem)' }}

Shopify's responsive image guidance recommends four to six widths, because too many hurt cache efficiency. For store-wide fixes see our Shopify speed optimisation guide.

Other platforms and image CDNs

Squarespace, Wix and most hosted builders generate responsive variants automatically, with limited control over sizes. Frameworks such as Next.js provide image components that generate srcset for you (covered in our Next.js SEO guide). Image CDNs (Cloudinary, imgix, Cloudflare Images and others) resize on the fly from URL parameters, so you only upload one master file.

PlatformGenerates srcset automatically?Controls sizes?Watch out for
WordPress coreYes, for content imagesDefault formula; theme can overridePage builder and template images that skip core functions
Shopify (image_tag)Yes, default width setYes, via sizes parameterHero images lazy-loaded by default logic; missing sizes
Next.js image componentYesYes, via sizes propOmitting sizes on fluid images
Hosted buildersUsuallyRarelyOversized background images set in CSS
Image CDNYou build the URLsYou write the markupToo many unique widths fragmenting cache

Testing which image file the browser actually downloads

Responsive markup fails silently: the page looks fine whichever file loads. Check it directly:

  1. Open Chrome DevTools, go to the Network panel, filter by Img and tick Disable cache. MDN notes that without this, Chrome may reuse a larger file it already downloaded.
  2. Switch on Device Mode and choose a phone profile (for example a 390-pixel viewport at DPR 3).
  3. Reload and find the hero image request. Note the file name or width parameter and the transferred size.
  4. In the Elements panel, select the <img> and hover over it; DevTools shows the rendered size and the intrinsic size. Alternatively run $0.currentSrc in the Console to see the chosen file.
  5. Compare intrinsic width to rendered width multiplied by DPR. If intrinsic is far larger, your sizes is too generous or missing.
  6. Repeat at tablet and desktop widths.
  7. Run Lighthouse and look for the "Properly size images" (or newer "Improve image delivery") audit, which lists files with potential savings.

Shopify's guidance also suggests the Performance panel's Insights tab for an "image sizes are too large" signal, and the Responsive Image Linter browser extension to calculate a correct sizes value from your layout.

A worked example: fixing a blog hero image

Hypothetical example for illustration. A home-improvement blog uses a full-width 2,400 × 1,350 pixel JPEG hero on every post. It is the LCP element on mobile. The theme outputs only src.

VersionFile sent to a 390 px DPR 3 phoneApproximate transfer
Before: single file2,400 px JPEG~420 KB
srcset 480/800/1200/1600/2400, sizes="100vw"1,200 px~140 KB
Same, served as WebP or AVIF by the CDN1,200 px~70–90 KB
Capped at 2x with picture/max density logic800 px~40–55 KB

The byte figures are illustrative; real savings depend on image content and compression settings. The pattern holds, though: the first and biggest gain comes from sending the right width, and format conversion compounds it. On a slow mobile connection, cutting the LCP resource from hundreds of kilobytes to tens can be the difference between an LCP inside 2.5 seconds and one outside it.

What responsive images change for LCP and Google Images

Responsive images reduce the resource load duration part of LCP. They do not fix discovery or priority problems, so pair them with these rules from web.dev's Optimize LCP guide:

“Never lazy-load your LCP image, as that will always lead to unnecessary resource load delay”

— web.dev, Optimize Largest Contentful Paint
  • Mark the hero eager and high priority. Use fetchpriority="high" on the likely LCP image, but only on one or two images, since web.dev warns that more makes prioritisation unhelpful.
  • Preload responsively if the image is in CSS or injected by JavaScript. A preload link can carry imagesrcset and imagesizes so the preloaded file matches what <img> will choose; Shopify's image_tag does this when preload: true is set. Our guide to preload and preconnect resource hints explains the trade-offs.
  • Lazy-load everything below the fold, as covered in our lazy loading guide.
  • Reserve space with width and height or aspect-ratio to keep CLS under the 0.1 threshold used in the Core Web Vitals report.

For Google Images, responsive markup is fully supported, with one caveat Google states in its image SEO best practices: some browsers and crawlers do not understand srcset or <picture>, so Google recommends always specifying a fallback URL in src. Google also says it does not index CSS background images, so a hero built as a background-image cannot rank in image search and cannot benefit from srcset. If the image matters for search, use a real <img>. Descriptive file names and alt text still matter; see our full image SEO guide.

Questions about srcset, sizes and picture

Do I need both srcset and sizes?

For images whose display width changes with the layout, yes. srcset lists the files and their widths; sizes tells the browser how wide the image will be shown. Without sizes, browsers assume the image fills the viewport and often download a larger file than needed.

How many widths should I include in srcset?

Four to six is usually enough, which is also Shopify's recommendation. More widths fragment CDN and browser caches without meaningful savings.

Does Google index images in srcset or picture elements?

Yes, but Google recommends always including a fallback src on the img element because some crawlers do not understand srcset or picture. CSS background images are not indexed.

Should the LCP hero image be lazy-loaded?

No. Lazy-loading the LCP image delays its request. Load it eagerly, consider fetchpriority=“high”, and lazy-load images further down the page instead.

Does WordPress add srcset automatically?

Yes, for images inserted through core functions since WordPress 4.4, using a default sizes formula and a 1,600-pixel default maximum for srcset candidates. Themes should override sizes to match their actual layout.

Fixing oversized images on your site this week

Start with the template that produces the most mobile LCP failures in Search Console, usually the blog post, product or category page. Check which file a phone downloads for its hero image, add or correct sizes, cap the largest candidate at a sensible width, and make sure the hero is eager rather than lazy. Then move to listing grids and editorial images. To see whether the change reached real users, follow the approach in our guide to field data versus lab data.

If your theme or CMS fights you, our page speed optimisation team can fix image delivery at template level. Request a quote and tell us which platform you run.

Further reading on responsive images srcset

Sources for this responsive images guide

  1. MDN Web Docs: Using responsive images in HTML
  2. Google Search Central: Image SEO best practices
  3. web.dev: Optimize Largest Contentful Paint
  4. Make WordPress Core: Responsive images in WordPress 4.4 (November 2015)
  5. Shopify: Serve correctly sized images with srcset and sizes
  6. Shopify Liquid reference: image_tag filter
  7. Performance @ Shopify: Responsive images on Shopify with Liquid (updated September 2023)
  8. Search Console Help: Core Web Vitals report
Rohit Choudhary
Written byRohit ChoudharyCo-Founder, My SEO Experts

Rohit Choudhary is the co-founder of My SEO Experts and has more than 14 years of hands-on experience in SEO, paid advertising and digital marketing. Since starting out in 2011 he has helped hundreds of businesses grow through practical, data-driven search strategies, and he also serves as a consulting Digital Marketing Director for several US-based companies.

Keep reading

Related articles

Ready to grow your business online?

Get a free, no-obligation proposal tailored to your goals and budget.

CallFree Quote