srcset is an HTML attribute on an image that lists several versions of the same picture, at different widths or pixel densities, so the browser can download the one that best fits the screen. A phone gets a small file, a large high-density screen gets a sharp one, and nobody downloads more bytes than they need.
What is srcset? #
A normal image tag has one file in its src attribute. Every visitor gets that file, whatever their screen. srcset adds a list of candidates. MDN’s reference for the img element describes it as a comma-separated list of “possible image sources” for the browser to choose from.
web.dev’s lesson on responsive images puts the key point plainly: srcset “complements the src attribute instead of replacing it”. You still keep a src.
How does it work? #
Each entry in the list is a file address followed by a descriptor. There are 2 kinds of descriptor, and you must pick one kind per list.
Width descriptors (w) #
A number followed by w gives the real pixel width of that file. MDN says it “must match the intrinsic width of the referenced image”. You pair it with a sizes attribute that tells the browser how wide the picture will show on the page.
<img src="chair-800.jpg"
srcset="chair-400.jpg 400w, chair-800.jpg 800w, chair-1600.jpg 1600w"
sizes="(width <= 600px) 100vw, 50vw"
width="800" height="600"
alt="Oak dining chair with a woven seat">
Here the picture fills the screen on narrow phones and half the screen elsewhere. The browser does the sum: display width times pixel density, then the nearest file that is big enough.
Density descriptors (x) #
A number followed by x says which screen density the file is for. It suits images that are always shown at one fixed size, such as a logo.
<img src="logo.png" srcset="logo-2x.png 2x" width="120" height="40" alt="Shop logo">
MDN notes that with x descriptors, the src file counts as the 1x choice. With w descriptors, src is not one of the candidates and sizes is used instead.
Who makes the final choice? #
The browser. MDN says it “selects any of the available sources at its discretion”, for example to save data on a slow connection. You give options; you do not force one.
Why does it matter for search? #
It matters in 2 ways.
- Speed. Smaller files on small screens help page speed and Largest Contentful Paint, one of the Core Web Vitals. web.dev’s guide to optimising LCP wants the main image’s
srcorsrcsetpresent in the first HTML, so the browser finds it early. - Image search. Google’s image SEO best practices say Google finds images through the
srcofimgelements. Because “some browsers and crawlers don’t understand these attributes”, Google asks you to always give a fallbacksrc. Google also says it does not index CSS background images.
More on this in our image SEO guide.
Why does it matter for AI answers? #
AI crawlers and live fetchers read your HTML as text. Many never run your layout, so they see only the attributes. A clear src and an honest alt text tell a large language model what the picture shows. A page full of tiny placeholder files with the real image hidden in script gives them nothing. Keep the real file address in plain HTML. This links to the wider work of answer engine optimisation.
srcset or the picture element? #
| Need | Use |
|---|---|
| Same picture, different sizes | srcset with w and sizes |
| Same picture, fixed size, sharp on retina screens | srcset with x |
| Different crop for phones (art direction) | <picture> with <source media> |
| Newer formats with a fallback | <picture> with <source type>, see WebP and AVIF |
Google’s image guide says that with <picture> you should still include an img element with a src as the fallback.
Common mistakes #
- Leaving out sizes. MDN says that without it,
sizesdefaults to100vw, the full screen width. A small thumbnail then pulls the largest file. - Mixing w and x. MDN calls this incorrect. web.dev agrees: one or the other, “but not both together”.
- Wrong w numbers. If the 800w file is really 1600 pixels wide, the browser picks badly.
- No width and height. web.dev says these let the browser keep space, so other content does not jump when the image loads. That jump is layout shift.
- Lazy loading the hero image. web.dev’s LCP guide says “Never lazy-load your LCP image”. Keep lazy loading for pictures further down.
- Percentages in sizes. MDN says percentage values are not allowed there. Use
vwor pixels.
A worked example #
A product page shows a 1600 pixel photo in a column 400 pixels wide on phones. Every phone downloads the full file. The fix:
- Export 3 widths: 400, 800 and 1600 pixels. Our image resizer and image compressor run in your browser.
- Write
srcset="photo-400.jpg 400w, photo-800.jpg 800w, photo-1600.jpg 1600w". - Add
sizes="(width <= 600px) 100vw, 400px"to match the real layout. - Keep
src="photo-800.jpg", plus width, height and alt. - Because this is the main image, add
fetchpriority="high". web.dev warns that setting high priority on more than 1 or 2 images makes it unhelpful.
A phone with a 2x screen now asks for about 800 pixels, not 1600, so it downloads a quarter of the pixels.
How to check it #
- Open the browser’s developer tools, inspect the image and read its “current source”. Resize the window and watch it change.
- To see LCP for a real page, try the Core Web Vitals checker or the page speed checker once they launch (coming soon).
- Use our image SEO checker to list images with no
src, alt or size. - Run the broken link checker to catch missing image files in a list.
- Our Core Web Vitals calculator explains the thresholds.
Questions #
Does srcset replace src? #
No. Keep src as the fallback. Google and web.dev both say so.
Does WordPress add srcset for me? #
Most themes that use the built-in image functions print it. Check the page source to be sure. See WordPress SEO.
Is srcset a ranking factor? #
Not by itself. It helps speed and user experience, which feed into how good a page is to use. See user experience and technical SEO.
Related words #
Sources #
- MDN: the img element (srcset and sizes), checked 24 November 2026
- web.dev: Responsive images, checked 24 November 2026
- web.dev: Optimise Largest Contentful Paint, checked 24 November 2026
- Google Search Central: Image SEO best practices, checked 24 November 2026
Updated 24 November 2026 by URSY.
Cite this page: srcset. URSY. Updated 24 November 2026. https://ursy.com/wiki/srcset/ · Section links
Tools for this
- LiveAI Readiness Checkeris your site ready for ChatGPT, Gemini, Claude? Score + fixesRun the check →
- LiveAI Bot Checkerwhich AI bots your robots.txt lets inRun the check →
- LiveRobots.txt Checker + Generatortest any address against your rules, or write new onesRun the check →
- LiveSchema Markup CheckerRun the check →