Choose analytics

Essential browser storage remembers your tool settings. Optional analytics helps us understand site use and loads only if you accept it. Image files, filenames and submitted URLs are not sent to analytics.

Read the Cookie Policy
Skip to content
CompressByURL
CompressConvertResizeTarget sizeBy URLWebsite scannerBlog
Start compressing
Homechevron_rightBlogchevron_rightDeveloper guides
Developer guides

Responsive images: get srcset and sizes right for your layout

Responsive images begin with a layout question: how wide will this image actually be? Exporting three files is only half the job. The markup must describe the slot accurately enough for the browser to choose among them.

SV
Saipavan V
Sep 21, 20264 min read

Updated Oct 2, 2026

Responsive images that fit: topic-specific technical illustration
Editorial illustration

The short answer

  • checkWidth descriptors describe files; sizes describes the display slot.
  • checkUse the real column width, not always the viewport.
  • checkCheck currentSrc on fresh loads at each important breakpoint.
On this page
  1. Separate image resolution from image composition
  2. Measure the image slot at the layout breakpoints
  3. Create a small candidate set from a good original
  4. Connect files and slot hints in complete HTML
  5. Verify the selected source and the visual result
  6. Maintain variants as part of the publishing workflow

Separate image resolution from image composition

MDN distinguishes resolution switching from art direction. Resolution switching presents the same composition at different pixel dimensions. Art direction changes the crop for a different layout. Decide which problem you have before preparing files, because making a photograph smaller cannot repair a crop that hides the subject on mobile.

For an article card, width variants of the same crop are often sufficient. For a landscape banner with a person near the edge, a narrower layout might need a deliberately composed alternate crop. Document that distinction in the asset names. Keep alternative text about the content rather than about the crop or file format.

Measure the image slot at the layout breakpoints

In a worked example, a card uses the viewport minus 32 pixels of gutters on narrow screens and occupies a 360-pixel slot on desktop. Its sizes expression should describe those two situations. A value of 100vw would overstate the desktop requirement because the card does not stretch across the screen.

Test the slot in the actual component, including padding, gaps, and max-width. A design sketch is a starting assumption; computed layout is the acceptance evidence. If a sidebar opens or the card appears in another container, the expression may need to describe that layout too. Avoid solving one route while silently overfetching on another.

Create a small candidate set from a good original

Export candidate widths that cover the relevant slots and selected density targets. For the example card, 360, 720, and 1080 pixels can provide useful options. Each w descriptor must correspond to the actual pixel width of its file. Do not name a 720-pixel file as 1080w to force a selection.

Use the same composition and aspect ratio for this resolution-switching set. Work from the original rather than from a succession of compressed derivatives. Compare bytes and quality after resizing. More candidates mean more files to maintain, so add another width because it serves a real gap, not because a template generator offers ten options.

Connect files and slot hints in complete HTML

The following example assumes you have exported three real files at the stated widths and a desktop card with a 360-pixel slot. The source paths are illustrative assets to replace in your own project. The width and height describe a 3:2 ratio; CSS makes the displayed image follow its containing card.

Keep the fallback src useful. Do not assume srcset is a CSS rule that forces one file at a breakpoint. It offers candidates and sizing information to the browser. For a genuinely different mobile crop, use picture with an appropriate media condition rather than mixing inconsistent crops into a single width-descriptor set.

Example for a fluid mobile card and a fixed 360px desktop slot. Export these assets before using the markup.
<img
  src="/images/card-720.webp"
  srcset="/images/card-360.webp 360w,
          /images/card-720.webp 720w,
          /images/card-1080.webp 1080w"
  sizes="(max-width: 600px) calc(100vw - 32px), 360px"
  width="720" height="480"
  loading="lazy" decoding="async"
  alt="Mountain lake below a snow-covered ridge"
  style="display:block;width:100%;height:auto"
>

Verify the selected source and the visual result

Open a fresh load at a narrow viewport and inspect the image’s currentSrc and Network request. Repeat at the desktop layout and a relevant high-density setting. A resized existing session can retain a previously downloaded larger candidate, so it is weaker evidence than a fresh controlled navigation.

Check the actual content as well as the selected filename. An output can have the expected width and still contain artifacts or an incorrect crop. If the browser selects an unexpectedly large candidate, inspect sizes first, then verify the file widths and component geometry. Keep the findings attached to the relevant layout rather than adding another random candidate.

Maintain variants as part of the publishing workflow

Use a predictable naming scheme that distinguishes subject, crop, and width. Keep an untouched original in your source workflow. When the image changes, regenerate the full responsive set together so different widths do not accidentally show different revisions of the photograph.

CompressByURL can prepare static resized variants locally, but it does not write your responsive HTML or change your hosting configuration. Download the approved files, update the component, and verify a public page. The finished result is a working delivery set with readable content, not merely a folder full of small images.

InformationDescribes
720w in srcsetActual width of that candidate file
360px in sizesExpected CSS display slot
width and height attributesIntrinsic aspect ratio for layout
CSS widthDisplayed geometry of the element

Common questions

Should sizes always be 100vw?

Only when the image really occupies the viewport width. Cards, article columns, and sidebar images usually need a more accurate description.

Does srcset automatically crop a mobile image?

No. Width candidates handle resolution selection. Use deliberately prepared crops and picture media conditions when composition needs to change.

Sources and further reading

Technical references for the concepts in this guide. Examples with hypothetical values are illustrations, not measured results.

  • MDN: responsive imagesnorth_east
SV

Saipavan V

Saipavan V writes practical guides for CompressByURL on browser-first image optimization, website image audits, and web performance. His articles connect technical explanations with steps you can verify on your own site.

More about the author

On this page

  1. Separate image resolution from image composition
  2. Measure the image slot at the layout breakpoints
  3. Create a small candidate set from a good original
  4. Connect files and slot hints in complete HTML
  5. Verify the selected source and the visual result
  6. Maintain variants as part of the publishing workflow
  7. Common questions
  8. Sources and further reading

Try it with your images

Local files stay on your device.

Resize an imageCreate a static candidate with dimensions that fit your intended display.arrow_forwardCompare image formatsExport a supported static format and inspect quality and actual bytes.arrow_forward

Explore the topics

Web performancechevron_rightWebsite auditschevron_rightDeveloper guideschevron_rightImage optimizationchevron_right

Keep going.

A few guides for your next useful fix.

View all guides arrow_forward
arrow_outward
Developer guides4 min read

Next.js Image serving files that are too large? Check sizes first

Diagnose oversized Next.js Image downloads by matching sizes to grid columns, inspecting generated srcset, and separating source assets from delivery variants.

Sep 19, 2026
arrow_outward
Web performance4 min read

Fix GTmetrix “Properly size images” without making photos blurry

Find oversized image variants in GTmetrix, calculate a sensible pixel width, and deploy responsive replacements without sacrificing desktop clarity.

Sep 29, 2026
arrow_outward
Developer guides4 min read

Find oversized images with Chrome DevTools and currentSrc

Identify the image a browser actually downloaded, compare its slot and selected source, and capture a useful image audit without guessing from filenames.

Sep 5, 2026
Mascot organizing image cards for optimization

Compress images locally, from a URL, or from a webpage.

Reduce file size, convert formats and prepare web-ready assets in your browser.

Open the free image compressor
CompressByURL

Make images lighter. Keep local files private.

BlogAbout & contactPrivacyTermsCookies