Storefront Speed Journal

Reviewed November 15, 2026

Image Widths in Liquid: The srcset Fix That Shrinks Every Hero

A srcset tells the browser which image widths are available, and the browser picks the smallest one that fits the screen. Most Shopify themes either omit srcset on the hero or ask for the full-size image, so a phone that needs a 400-pixel image downloads a 2,000-pixel one, five times the bytes, and the LCP element is that oversized image. The fix is to add a srcset with widths from 400 to 2,000 pixels and a sizes attribute that matches the layout, so the browser downloads the right size instead of the largest one.

Why the hero is the LCP element

On most Shopify homepages the largest contentful paint element is the hero image, because it is the biggest thing on the first screen, and it is the thing that takes longest to arrive. The LCP threshold is 2.5 seconds at the 75th percentile, and a 2,000-pixel hero image on a 4G connection can take a second or more to download alone, before it is even decoded and painted. The image is the budget, and the budget is spent on pixels nobody can see.

The mismatch is the problem. A phone screen is about 400 CSS pixels wide, and a retina display needs twice that, 800 image pixels, to look sharp. A 2,000-pixel image is two and a half times wider than the retina requirement, and four times the bytes, because bytes scale with area, not width. The extra pixels are invisible on the phone and expensive to download, and the theme serves them because it asked for the largest size instead of the right size.

Shopify's CDN makes the fix easy, because it resizes images on request. The image URL carries a width parameter, and the CDN returns the image at that width, so the theme can ask for exactly the sizes it needs. The CDN is not the problem. The theme is, because it asks for the wrong size, and the CDN faithfully delivers it.

The srcset edit

The pattern is standard: an img tag with a srcset listing the widths the CDN should serve, and a sizes attribute telling the browser how wide the image will display at each viewport. For a full-width hero, the sizes are 100vw, and the srcset lists 400, 800, 1200, 1600, and 2000 pixels. The browser picks the smallest width that covers the display size at the device pixel ratio, and the phone gets the 800-pixel version instead of the 2000-pixel one.

In Liquid, the widths come from the image_url filter with a width argument, so the template builds each srcset entry from the same image object. The edit is in the hero section, and it is usually five lines: the img tag, the srcset with the width entries, the sizes attribute, a fetchpriority of high on the hero, and the removal of lazy loading from the hero, because lazy loading the LCP element delays the paint by definition. Never lazy-load the image that is visible on first load, and never mark it fetchpriority low.

The sizes attribute is where the fix most often fails. A sizes value of 100vw on an image that displays at 50vw tells the browser the image is twice as wide as it is, so the browser picks a width twice as large as it needs. The sizes value has to match the layout, at each breakpoint, or the srcset is decorative. Check the layout, write the sizes to match it, and the browser will do the rest.

The check, and the habit

Test with DevTools on a phone viewport, and read the Network tab: the hero image should arrive at a width close to the display width times the device pixel ratio, not at 2000 pixels. Then test on desktop, where the image should arrive larger, because the display is larger. The same srcset serves both, and the browser picks correctly in each case, which is the point of the attribute. A fix that only helps mobile is a fix that was tested on mobile only.

Run PageSpeed Insights before and after, three times each, and watch the LCP, not the score. The score moves for many reasons. The LCP is the number the fix touches, and a hero that drops from 2,000 pixels to 800 should cut LCP by half a second or more on mobile. If it does not, the image was not the bottleneck, and the next place to look is the scripts that block the paint, not a smaller image.

Make the fix once, in the template, and every future upload inherits it. That is the difference between a fix and a chore: a fix in the template applies to every image the merchant uploads from now on, and a fix applied to one image has to be repeated for the next one. The template is where image sizing lives, and the merchant should never have to think about widths again. If the fix has to be repeated per image, it was made in the wrong place.

Related reading

Related reading on this site: Render-Blocking JavaScript on Shopify: The Two Fixes That Matter, How to Read a PageSpeed Insights Report for Your Store.

Frequently asked questions

What is srcset and why does it matter for LCP?

Srcset lists the widths an image is available in, and the browser picks the smallest one that fits the screen. Without it, a phone that needs a 400-pixel image downloads a 2,000-pixel one, five times the bytes, and that oversized hero is usually the LCP element.

What widths should I put in a hero srcset?

400, 800, 1200, 1600, and 2000 pixels covers phones through large desktops, with a sizes attribute of 100vw for a full-width hero. The browser picks the smallest width that covers the display size at the device pixel ratio.

Should I lazy-load my hero image?

No, never. The hero is usually the LCP element, and lazy loading it delays the paint by definition. Mark it fetchpriority high instead, and reserve lazy loading for images below the fold, where it helps.

Why does my sizes attribute matter?

Because it tells the browser how wide the image displays. A sizes value of 100vw on an image that displays at 50vw makes the browser pick a width twice as large as needed. The sizes value has to match the layout at each breakpoint, or the srcset is decorative.