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
srcsetandsizeshandle. - 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.
| Scenario | Slot width (CSS px) | DPR | Pixels needed | Waste if you send a 2,400 px file |
|---|---|---|---|---|
| Phone, full-width hero | 390 | 3 | 1,170 | About 2x wider than needed (roughly 4x the pixels) |
| Phone, capped at 2x | 390 | 2 | 780 | About 3x wider (roughly 9x the pixels) |
| Tablet, two-column grid | 380 | 2 | 760 | About 3x wider |
| Laptop, article column | 700 | 2 | 1,400 | About 1.7x wider |
| Desktop, wide hero | 1,200 | 2 | 2,400 | None |
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
wdescriptor is the file's real pixel width, not the display width. Lying here breaks the maths. - Order in
sizesmatters. 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. Usevw,px,emorcalc(). - Without
sizes, browsers assume100vw, which on a desktop with a narrow content column means downloading a much bigger file than needed. Shopify's documentation flags a missingsizesvalue 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
widthandheightso 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.
| Platform | Generates srcset automatically? | Controls sizes? | Watch out for |
|---|---|---|---|
| WordPress core | Yes, for content images | Default formula; theme can override | Page builder and template images that skip core functions |
| Shopify (image_tag) | Yes, default width set | Yes, via sizes parameter | Hero images lazy-loaded by default logic; missing sizes |
| Next.js image component | Yes | Yes, via sizes prop | Omitting sizes on fluid images |
| Hosted builders | Usually | Rarely | Oversized background images set in CSS |
| Image CDN | You build the URLs | You write the markup | Too 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:
- 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.
- Switch on Device Mode and choose a phone profile (for example a 390-pixel viewport at DPR 3).
- Reload and find the hero image request. Note the file name or width parameter and the transferred size.
- In the Elements panel, select the
<img>and hover over it; DevTools shows the rendered size and the intrinsic size. Alternatively run$0.currentSrcin the Console to see the chosen file. - Compare intrinsic width to rendered width multiplied by DPR. If intrinsic is far larger, your
sizesis too generous or missing. - Repeat at tablet and desktop widths.
- 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.
| Version | File sent to a 390 px DPR 3 phone | Approximate transfer |
|---|---|---|
| Before: single file | 2,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 CDN | 1,200 px | ~70–90 KB |
| Capped at 2x with picture/max density logic | 800 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
imagesrcsetandimagesizesso the preloaded file matches what<img>will choose; Shopify'simage_tagdoes this whenpreload: trueis 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
widthandheightoraspect-ratioto 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
- Custom Extraction: Scrape Any On-Page Element With Your SEO Crawler
- Shopify Speed Optimisation: Apps, Themes and Images
- WordPress Speed Optimisation: Hosting, Plugins and Caching
Sources for this responsive images guide
- MDN Web Docs: Using responsive images in HTML
- Google Search Central: Image SEO best practices
- web.dev: Optimize Largest Contentful Paint
- Make WordPress Core: Responsive images in WordPress 4.4 (November 2015)
- Shopify: Serve correctly sized images with srcset and sizes
- Shopify Liquid reference: image_tag filter
- Performance @ Shopify: Responsive images on Shopify with Liquid (updated September 2023)
- Search Console Help: Core Web Vitals report




