{"id":86,"date":"2026-10-18T17:53:17","date_gmt":"2026-10-18T17:53:17","guid":{"rendered":"https:\/\/refracttools.com\/blog\/?p=86"},"modified":"2026-10-18T17:53:17","modified_gmt":"2026-10-18T17:53:17","slug":"srcset-sizes-explained","status":"publish","type":"post","link":"https:\/\/refracttools.com\/blog\/performance\/srcset-sizes-explained\/","title":{"rendered":"Responsive images with srcset and sizes, explained"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><code>srcset<\/code> lists several versions of an image with their real widths, and <code>sizes<\/code> tells the browser how wide the image will be displayed. The browser combines the two with the screen&#8217;s pixel density and downloads the smallest file that still looks sharp. Get <code>sizes<\/code> wrong, or leave it out, and the browser assumes the image fills the whole screen, which usually means downloading a much bigger file than needed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This guide explains both attributes with worked examples for the three most common layouts, when to use <code>&lt;picture&gt;<\/code> instead, and how the newer <code>sizes=\"auto\"<\/code> fits in.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Last checked: October 2026.<\/em><\/p>\n\n\n\n<div class=\"wp-block-group is-style-refract-takeaways is-layout-constrained wp-block-group-is-layout-constrained\">\n<h3 class=\"wp-block-heading\">Key takeaways<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use width descriptors (<code>800w<\/code>) in <code>srcset<\/code> for images that change size with the layout.<\/li>\n\n\n<li>Write <code>sizes<\/code> to match your CSS: how wide the image is at each breakpoint.<\/li>\n\n\n<li>Use density descriptors (<code>2x<\/code>) only for images shown at a fixed size, such as logos.<\/li>\n\n\n<li>Keep <code>width<\/code> and <code>height<\/code>, and don&#8217;t lazy-load the main image at the top of the page.<\/li>\n\n\n<li><code>sizes=\"auto\"<\/code> works for lazy-loaded images in Chrome, Edge and Firefox, with a fallback list for other browsers.<\/li>\n<\/ul>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">How srcset and sizes work together<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;img\n  src=\"\/img\/hero-1200.webp\"\n  srcset=\"\/img\/hero-480.webp 480w,\n          \/img\/hero-800.webp 800w,\n          \/img\/hero-1200.webp 1200w,\n          \/img\/hero-1600.webp 1600w,\n          \/img\/hero-2400.webp 2400w\"\n  sizes=\"(max-width: 800px) 100vw, 800px\"\n  width=\"2400\" height=\"1350\"\n  alt=\"Describe the image\"&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>srcset<\/strong> lists each file and its actual width in pixels, written with a <code>w<\/code>.<\/li>\n\n\n<li><strong>sizes<\/strong> says how wide the image will be shown: the full viewport width on screens up to 800px wide, and 800px on anything wider.<\/li>\n\n\n<li><strong>src<\/strong> is the fallback for very old browsers.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The browser multiplies the display width by the screen&#8217;s pixel density and usually picks the smallest file at or above that number. On a 390px-wide phone at 3\u00d7 density, the image is shown at 390px, so it needs about 1,170 pixels and the browser downloads the 1,200px file. On a desktop with a 2\u00d7 screen, the image is 800px wide and needs 1,600 pixels.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The final choice is up to the browser. It may use a larger file it already has in its cache, or a smaller one on a slow connection, which is why <code>srcset<\/code> is a list of options rather than a set of rules. If you need to force a particular image under particular conditions, that is a job for <code>&lt;picture&gt;<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Writing sizes for common layouts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>sizes<\/code> should describe your CSS, not your images. Read it as &#8220;under this condition, the image is this wide&#8221;, checked from left to right; the last value has no condition and applies otherwise.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><div class=\"table-scroll\" tabindex=\"0\" role=\"region\" aria-label=\"Scrollable table\"><table><thead><tr><th>Layout<\/th><th>sizes value<\/th><\/tr><\/thead><tbody><tr><td>Full-width hero<\/td><td><code>100vw<\/code><\/td><\/tr><tr><td>Article column, max 760px wide<\/td><td><code>(max-width: 800px) 100vw, 760px<\/code><\/td><\/tr><tr><td>Three-column grid that stacks on phones<\/td><td><code>(max-width: 600px) 100vw, (max-width: 1000px) 50vw, 33vw<\/code><\/td><\/tr><tr><td>Sidebar image, always 300px<\/td><td><code>300px<\/code><\/td><\/tr><\/tbody><\/table><\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Allow for padding where it matters. If an article column has 20px of padding on each side on phones, <code>calc(100vw - 40px)<\/code> is more accurate than <code>100vw<\/code>, though the difference is rarely worth extra complexity.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Width descriptors or density descriptors?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For an image shown at a fixed size, such as a 200px logo, you don&#8217;t need <code>sizes<\/code> at all. List versions by screen density instead:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;img src=\"\/img\/logo-200.png\"\n     srcset=\"\/img\/logo-200.png 1x, \/img\/logo-400.png 2x\"\n     width=\"200\" height=\"60\" alt=\"Company name\"&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For anything that resizes with the layout, use width descriptors and <code>sizes<\/code>. Mixing the two in one <code>srcset<\/code> isn&#8217;t allowed.<\/p>\n\n\n<aside class=\"tool-card tool-card--inline\"><span class=\"swatch\" style=\"background:linear-gradient(90deg,#f59e0b 0 25%,#ea580c 25% 55%,#9a3412 55%)\" aria-hidden=\"true\"><\/span><div class=\"tool-card__body\"><p class=\"tool-card__eyebrow\">Free tool<\/p><p class=\"tool-card__name\">Responsive image (srcset) generator<\/p><p class=\"tool-card__blurb\">Every image width as a ZIP, plus the srcset and sizes HTML to match.<\/p><\/div><a class=\"btn primary\" href=\"https:\/\/refracttools.com\/srcset-generator\/\">Try it free <span aria-hidden=\"true\">\u2192<\/span><\/a><\/aside>\n\n\n\n<h2 class=\"wp-block-heading\">srcset or the picture element?<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><div class=\"table-scroll\" tabindex=\"0\" role=\"region\" aria-label=\"Scrollable table\"><table><thead><tr><th>Use<\/th><th>When<\/th><\/tr><\/thead><tbody><tr><td><code>&lt;img srcset sizes&gt;<\/code><\/td><td>Same image, different sizes. The browser chooses.<\/td><\/tr><tr><td><code>&lt;picture&gt;<\/code> with <code>type<\/code><\/td><td>Different formats, such as AVIF with a WebP or JPEG fallback.<\/td><\/tr><tr><td><code>&lt;picture&gt;<\/code> with <code>media<\/code><\/td><td>A different crop on small screens (art direction). You choose.<\/td><\/tr><\/tbody><\/table><\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">You can combine them: each <code>&lt;source&gt;<\/code> inside <code>&lt;picture&gt;<\/code> takes its own <code>srcset<\/code> and <code>sizes<\/code>. The <a href=\"https:\/\/refracttools.com\/blog\/image-optimisation\/webp-vs-avif-vs-jpeg\/\">WebP vs AVIF vs JPEG guide<\/a> shows the format version.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">sizes=&#8221;auto&#8221; for lazy-loaded images<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Images with <code>loading=\"lazy\"<\/code> don&#8217;t load until the layout is known, so the browser can measure them itself. <code>sizes=\"auto\"<\/code> tells it to do that:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;img loading=\"lazy\"\n     srcset=\"card-400.webp 400w, card-800.webp 800w, card-1200.webp 1200w\"\n     sizes=\"auto, (max-width: 600px) 100vw, 33vw\"\n     width=\"1200\" height=\"800\" alt=\"\u2026\"&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It&#8217;s supported in Chrome and Edge from version 126 and Firefox from version 150, with only partial support in Safari so far. Browsers that don&#8217;t understand <code>auto<\/code> use the list after it, so always include one. WordPress has added <code>auto<\/code> to lazy-loaded images automatically since version 6.7. It only works with <code>loading=\"lazy\"<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Mistakes that waste data<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Leaving out sizes<\/strong> with width descriptors. The browser assumes <code>100vw<\/code> and downloads a full-screen image for a small card.<\/li>\n\n\n<li><strong>Lazy-loading the hero image.<\/strong> It delays your Largest Contentful Paint. Load it normally, and consider <code>fetchpriority=\"high\"<\/code> on it.<\/li>\n\n\n<li><strong>Missing width and height<\/strong>, which lets the page jump as images load.<\/li>\n\n\n<li><strong>Too many or too few widths.<\/strong> Five or six between about 480px and 1,920px covers most layouts; add 2,400px or 2,560px for full-width images on large high-density screens.<\/li>\n\n\n<li><strong>Upscaled files.<\/strong> A 2,400w entry made from an 1,800px original adds bytes and no detail.<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-group is-style-refract-callout is-layout-constrained wp-block-group-is-layout-constrained\">\n<p class=\"wp-block-paragraph\"><strong>Tip:<\/strong> Not sure what widths you need? Measure the image at your widest and narrowest layouts, multiply by 2 for high-density screens, and fill the gaps in between. The <a href=\"https:\/\/refracttools.com\/blog\/image-optimisation\/image-size-for-website\/\">guide to image sizes<\/a> has typical numbers for heroes, articles and thumbnails.<\/p>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Generate the files and the HTML<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <a href=\"https:\/\/refracttools.com\/srcset-generator\/\">srcset generator<\/a> does the tedious part. Drop in your largest image, tick the widths, describe the layout (full width, content column or grid), and it creates every file as WebP, AVIF or JPEG and writes the <code>srcset<\/code>, <code>sizes<\/code> or <code>&lt;picture&gt;<\/code> markup. Everything happens in your browser. For a placeholder to show while those images load, see the <a href=\"https:\/\/refracttools.com\/blur-placeholder-generator\/\">blur placeholder generator<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Sources: <a href=\"https:\/\/caniuse.com\/mdn-html_elements_img_sizes_auto\" rel=\"noopener\" target=\"_blank\">Can I use: sizes=&#8221;auto&#8221;<\/a>, <a href=\"https:\/\/make.wordpress.org\/core\/2024\/10\/18\/auto-sizes-for-lazy-loaded-images-in-wordpress-6-7\/\" rel=\"noopener\" target=\"_blank\">WordPress 6.7: auto sizes for lazy-loaded images<\/a>.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>srcset lists your image files, sizes says how wide the image is shown, and the browser picks the smallest sharp file. Worked examples, common layouts and the new sizes=&#8221;auto&#8221;.<\/p>\n","protected":false},"author":1,"featured_media":85,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_refract_tool":"srcset-generator","footnotes":""},"categories":[36],"tags":[5,17,42],"class_list":["post-86","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-performance","tag-image-tools","tag-performance","tag-responsive-images"],"_links":{"self":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts\/86","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/comments?post=86"}],"version-history":[{"count":1,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts\/86\/revisions"}],"predecessor-version":[{"id":118,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts\/86\/revisions\/118"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/media\/85"}],"wp:attachment":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/media?parent=86"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/categories?post=86"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/tags?post=86"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}