Responsive images are not a single HTML feature but a set of choices about image width, crop, format, loading priority, and browser selection. This guide provides a repeatable workflow for choosing between srcset, sizes, and picture, generating useful image variants, checking the result in browser developer tools, and revisiting the implementation when a design or delivery workflow changes.
Overview
The goal of responsive images is to give each visitor an appropriate resource for the space available, the device's pixel density, and the formats the browser can use. A large desktop image should not be the default download for a small mobile card, but a small image should not be stretched across a wide hero component either.
Use srcset with width descriptors when the browser may choose among files with different intrinsic widths. Pair it with sizes so the browser can estimate how wide the image will appear before it downloads a candidate. Use picture when you need art direction, such as a different crop at a breakpoint, or format negotiation, such as offering AVIF or WebP before a fallback image.
| Requirement | Preferred technique | Why |
|---|---|---|
| Same image and crop at several rendered widths | img srcset plus sizes | Lets the browser select an appropriately sized candidate. |
| Different crop or composition by viewport | picture with media conditions | Supports art direction without forcing CSS to hide the wrong image. |
| Several image formats with a fallback | picture with MIME-type sources | Allows format selection while retaining a broadly usable fallback. |
| One fixed or nearly fixed display size | Simple img, optionally with a density-based srcset | A complex candidate list may not add value. |
Responsive image markup works best when it follows the component's actual layout. Measure the rendered slot, not just the source file, and treat accessibility as part of the implementation: provide meaningful alternative text, or use an empty alt attribute when the image is purely decorative.
Checklist by scenario
For a responsive card or content image
- Identify the largest likely rendered width of the image, including the relevant layout container and gap rules.
- Generate several candidates around the widths your layout actually uses. Avoid producing dozens of nearly identical files without a reason.
- Write a width-based
srcsetand describe the rendered slot withsizes. - Set
widthandheightattributes from the chosen aspect ratio so the browser can reserve space before the image loads. - Use lazy loading for images that begin below the initial viewport when that behavior matches the page experience.
<img
src="/images/article-800.jpg"
srcset="
/images/article-480.jpg 480w,
/images/article-800.jpg 800w,
/images/article-1200.jpg 1200w
"
sizes="(min-width: 64rem) 33rem, (min-width: 40rem) 50vw, 100vw"
width="1200"
height="800"
alt="A developer reviewing a responsive layout"
loading="lazy"
decoding="async"
>The sizes value should describe the CSS result. If the image occupies the full viewport below 40rem, 100vw is a reasonable description. If it occupies half the viewport on medium screens and a fixed column on wide screens, express those conditions instead of copying a generic value into every component.
For a hero image with a different mobile crop
Use art direction when the subject, focal point, or composition must change. Create separate crops rather than relying on the browser to resize a landscape image into a useful portrait composition.
<picture>
<source
media="(max-width: 39.99rem)"
srcset="/images/product-portrait-640.jpg 640w,
/images/product-portrait-960.jpg 960w"
sizes="100vw"
>
<img
src="/images/product-landscape-1200.jpg"
srcset="/images/product-landscape-800.jpg 800w,
/images/product-landscape-1200.jpg 1200w,
/images/product-landscape-1600.jpg 1600w"
sizes="(min-width: 64rem) 75vw, 100vw"
width="1600"
height="900"
alt="The product dashboard on a laptop"
fetchpriority="high"
decoding="async"
>
</picture>Reserve fetchpriority="high" for an image that is genuinely important to the initial view, such as a primary hero visual. Do not apply it to every image; priority hints are useful only when they reflect the page's loading intent.
For format negotiation
When your image pipeline creates modern formats, put those candidates in source elements and keep a conventional format in the fallback img. The browser selects a supported source, while the fallback remains the semantic image element.
<picture>
<source
type="image/avif"
srcset="/images/team-640.avif 640w, /images/team-1280.avif 1280w"
sizes="(min-width: 48rem) 50vw, 100vw"
>
<source
type="image/webp"
srcset="/images/team-640.webp 640w, /images/team-1280.webp 1280w"
sizes="(min-width: 48rem) 50vw, 100vw"
>
<img
src="/images/team-800.jpg"
width="1280"
height="853"
alt="A team collaborating at a table"
loading="lazy"
decoding="async"
>
</picture>A CDN can generate equivalent variants from a single original using width, quality, and format parameters. Keep the transformation policy in one place, document the allowed widths, and verify that cache keys include every parameter that changes the output. The exact URL syntax depends on the image service, so treat the example above as a markup pattern rather than a provider-specific configuration.
What to double-check
- Source dimensions: The largest candidate should cover the largest expected rendered size at the required density, but it does not need to be an uncompressed original if the component never displays that size.
- Aspect ratio: Make every candidate in a single
srcsetshare the intended ratio unless the markup represents separate art-directed crops. - Sizes accuracy: Compare the declared
sizesvalue with the computed width in the browser at narrow, medium, and wide viewports. - Intrinsic dimensions: Add accurate
widthandheightvalues to reduce layout movement. If a CSS crop usesobject-fit, the intrinsic ratio still needs to be intentional. - Loading behavior: Keep the initial, meaningful image eligible for prompt loading and defer images that are not needed immediately. Test on a slower connection rather than judging only from a warm local cache.
- Accessibility: Write alt text for informative images, use an empty
altfor decorative images, and avoid repeating adjacent visible text. - Format fallback: Confirm that the
imgfallback has a working URL, dimensions, and alt text. A modern-format source should not be the only usable path.
In browser developer tools, inspect the Network panel and filter by image. Check which candidate was requested, its transferred size, response type, cache status, and timing. Resize the viewport and repeat the test. The Chrome DevTools Network Tab Guide on htmlfile.cloud provides a broader request-debugging workflow: diagnose failed requests, slow pages, and caching problems.
Common mistakes
Using srcset without sizes. With width descriptors, the browser needs a description of the rendered slot. Without one, it may make a conservative choice that does not match the component's real width.
Confusing resolution switching with art direction. A list of widths changes file size, not composition. If the mobile design needs a tighter crop, use a media-conditioned source with a separately prepared image.
Serving a huge source and shrinking it with CSS. CSS changes display dimensions but does not undo download cost. Generate candidates close to actual display widths.
Lazy-loading every image. An above-the-fold hero may be delayed unnecessarily when it is marked lazy. Decide based on position and importance, then verify the resulting request order.
Changing format without checking the pipeline. A smaller modern format can still be unsuitable if transformations remove detail, produce unexpected dimensions, or omit metadata required by the design. Compare visual quality at the rendered size.
Testing only one viewport. A correct desktop result does not prove that mobile receives the right crop or candidate. Test the breakpoints that change layout and at least one width between them.
When to revisit
Review responsive-image markup whenever a component's grid, container width, breakpoint, or crop changes. Recheck it before a seasonal landing page or campaign refresh, after moving image processing to a new CDN, and whenever a build pipeline starts generating new formats or width variants. Browser support and image-service capabilities can evolve, so validate format sources and transformation URLs during a regular twice-yearly technical review.
Use this short maintenance checklist:
- Record the component's current rendered widths and aspect ratios.
- Compare those measurements with the candidate widths and
sizesconditions. - Test the smallest, largest, and one intermediate viewport in the Network panel.
- Confirm the initial image has appropriate priority and below-the-fold images are not competing with it.
- Inspect layout stability, visual quality, alt text, and fallback behavior.
- Update the markup, image pipeline documentation, and any performance tests when the inputs change.
For local verification, keep the page easy to test outside a production deployment. If requests behave differently from an application server, the guide on running an HTML file locally without CORS errors can help separate browser-environment problems from image-markup problems. A responsive-image implementation is complete when the right resource, crop, format, and loading behavior can be explained for each scenario—not merely when the page looks correct at one width.