Responsive Images Guide
A practical guide to responsive images on the web, covering srcset, sizes, picture, resolution switching, art direction, image formats and performance.
A responsive image is an image that can adapt to the device, viewport, display density and layout where it is being rendered. Instead of downloading the same large file for every visitor, a website can provide several image variants and let the browser choose an appropriate resource.
Responsive images are important because the image that looks appropriate on a large desktop screen can be unnecessarily expensive on a phone. A 2000 or 3000 pixel image may contain far more data than a mobile layout needs. Conversely, using only a small image can make a large or high-density display look blurry.
Modern responsive image techniques are built primarily around srcset, sizes, picture, appropriate image dimensions and efficient formats such as WebP or AVIF. Together, these features allow the browser to select an image that better matches the actual rendering conditions.
What Are Responsive Images?
Responsive images are images served in different sizes or sometimes different formats depending on the conditions in which they are displayed. The goal is not simply to make an image shrink with CSS. The important part is avoiding unnecessary downloads while preserving sufficient visual quality.
For example, suppose a product image is displayed at approximately 360 CSS pixels on a phone, 700 CSS pixels on a tablet and 1000 CSS pixels on a desktop. Sending a 2000-pixel source to every device may waste bandwidth. A responsive image setup can provide several versions, such as 400, 800, 1200 and 2000 pixels, and allow the browser to select an appropriate candidate.
Responsive images solve a different problem from responsive CSS. CSS controls how an image is laid out. Responsive image techniques influence which underlying file the browser downloads.
| Technique | Main purpose | Typical use |
|---|---|---|
| CSS width and height | Controls rendered layout | Making images fit a responsive container |
| srcset with width descriptors | Provides multiple image resolutions | Serving different file sizes for different layouts |
| sizes | Describes the expected rendered width | Helping the browser choose from srcset candidates |
| picture | Provides alternative sources | Art direction or format switching |
| width and height attributes | Reserves layout space | Reducing layout shifts |
Why Responsive Images Matter
Images are often among the largest resources on a web page. A page can contain relatively little JavaScript and CSS while still transferring several megabytes of image data. Serving unnecessarily large images therefore has a direct effect on bandwidth and loading performance.
The problem becomes more obvious when the same page is accessed from different devices. A desktop monitor may display a large hero image, while a phone may show a much smaller version. Sending one universal high-resolution asset ignores that difference.
Responsive images can reduce transferred bytes, improve loading behavior on slower connections and prevent unnecessary work on devices that cannot visually benefit from extremely large source files. They can also improve the experience of users on high-density displays by providing sufficiently detailed resources when they are actually needed.
Responsive Layout vs Responsive Image Delivery
A common misunderstanding is that setting width: 100% makes an image responsive in every sense. It makes the rendered element adapt to its container, but it does not automatically make the downloaded resource appropriate for that container.
<img
src="/images/photo-2000.jpg"
alt="Mountain landscape"
style="width: 100%; height: auto;"
>The example above can display correctly on a phone, but the browser may still download photo-2000.jpg even when the image is rendered at only 360 CSS pixels. CSS changes the presentation; it does not create smaller versions of the source image.
A responsive delivery setup instead gives the browser several candidates to choose from.
The srcset Attribute
The srcset attribute lets an image specify multiple resource candidates. There are two main descriptor types: width descriptors using w and pixel-density descriptors using x.
Width Descriptors
Width descriptors tell the browser the intrinsic width of each candidate in pixels. The browser uses these values together with the expected rendered size from sizes to determine which resource is appropriate.
<img
src="/images/photo-800.jpg"
srcset="
/images/photo-400.jpg 400w,
/images/photo-800.jpg 800w,
/images/photo-1200.jpg 1200w,
/images/photo-2000.jpg 2000w
"
alt="Mountain landscape"
>The 400w, 800w, 1200w and 2000w values do not mean that the browser must use those files at exactly those CSS widths. They describe the intrinsic widths of the available resources. The browser combines this information with the image's expected display size, device pixel ratio and other loading conditions.
Pixel-Density Descriptors
The x descriptor is useful when the image has a known rendered size and different files are intended for different device pixel densities.
<img
src="/images/avatar-1x.jpg"
srcset="
/images/avatar-1x.jpg 1x,
/images/avatar-2x.jpg 2x
"
width="200"
height="200"
alt="User avatar"
>In this example, the image is intended to occupy approximately the same CSS dimensions, but a high-density display can use the 2x candidate for additional detail.
For fluid layouts where the displayed width changes significantly across viewport sizes, width descriptors are generally more useful because they allow the browser to choose from candidates according to the actual layout size.
What Does sizes Do?
When srcset uses width descriptors, sizes tells the browser how wide the image is expected to be displayed under different viewport conditions. This information is important because the browser may need to choose a candidate before the page has finished applying all layout calculations.
<img
src="/images/article-800.jpg"
srcset="
/images/article-400.jpg 400w,
/images/article-800.jpg 800w,
/images/article-1200.jpg 1200w,
/images/article-1600.jpg 1600w
"
sizes="
(max-width: 600px) 100vw,
(max-width: 1000px) 80vw,
800px
"
alt="Article illustration"
>The sizes value above says that on viewports up to 600 pixels the image is expected to occupy the full viewport width. Between 601 and 1000 pixels, it is expected to occupy approximately 80% of the viewport width. At larger widths, it is expected to be around 800 CSS pixels wide.
How srcset and sizes Work Together
srcset provides the available candidates. sizes describes the expected display width. The browser uses both pieces of information to select an appropriate resource, taking device pixel ratio and other browser decisions into account.
Consider an image that occupies 50vw on a desktop but nearly the entire viewport on a phone. Without sizes, the browser does not have the same information about the intended layout. With an accurate sizes declaration, it can make a more informed choice from the srcset candidates.
Choosing Image Widths
Responsive image variants should be based on the actual sizes at which the image is likely to be displayed. There is no universal set of widths that works for every website.
A practical set might contain widths such as 320, 480, 640, 768, 1024, 1280 and 1600 pixels, but the exact breakpoints should come from the site's layouts and content. If an image never appears wider than 700 pixels, generating a 3000-pixel version for every asset may provide little benefit.
At the same time, using too few candidates can force the browser to download a file that is significantly larger than the rendered image. The goal is to provide enough variants to avoid large jumps in file dimensions without generating an unnecessary number of files.
An image dimension or responsive image calculator can help estimate suitable source dimensions from the target layout, aspect ratio and device requirements.
Device Pixel Ratio and Retina Displays
CSS pixels are not always the same as physical pixels on a display. A device pixel ratio of 2 means that an element rendered at 300 CSS pixels can use approximately 600 physical pixels in each dimension for a sharper representation.
This is one reason why serving an image exactly at its CSS width is not always sufficient. A 300 CSS-pixel image may need a larger source on a high-density display, depending on the desired quality and the browser's resource selection.
Responsive images allow the browser to balance these requirements. The browser does not simply choose the largest file whenever a high-density display is detected; it considers the available candidates and the expected rendered dimensions.
The picture Element
The picture element is useful when responsive image delivery requires more than choosing between different resolutions of the same image. It allows different sources to be supplied based on media conditions, supported formats or other source-selection rules.
<picture>
<source
media="(max-width: 700px)"
srcset="/images/product-mobile.jpg"
>
<source
media="(min-width: 701px)"
srcset="/images/product-desktop.jpg"
>
<img
src="/images/product-desktop.jpg"
alt="Product displayed on a table"
>
</picture>The img element remains important because it provides the fallback image and is the actual replaced element rendered by the browser. The source elements provide additional candidates or conditions for selecting the resource.
Art Direction vs Resolution Switching
Two different responsive image problems are often confused. Resolution switching means that the same image is available at different dimensions. Art direction means that the composition itself changes for different contexts.
For resolution switching, srcset and sizes are usually sufficient. The same photograph can have 400, 800, 1200 and 1600 pixel versions while retaining the same composition.
For art direction, a mobile version might use a different crop from the desktop version. The subject can be repositioned or unnecessary background areas can be removed. The picture element is designed for this type of source selection.
<picture>
<source
media="(max-width: 600px)"
srcset="/images/hero-mobile.jpg"
>
<img
src="/images/hero-desktop.jpg"
alt="Person working at a desk"
>
</picture>The mobile and desktop files can have different aspect ratios and compositions while still representing the same content.
Responsive Image Formats
Responsive image delivery can also be combined with format selection. A website may provide AVIF or WebP to browsers that support them while retaining a more widely supported fallback.
<picture>
<source
type="image/avif"
srcset="/images/photo.avif"
>
<source
type="image/webp"
srcset="/images/photo.webp"
>
<img
src="/images/photo.jpg"
alt="Mountain landscape"
>
</picture>The same pattern can be combined with multiple resolutions. For a production image pipeline, each format can have several generated widths rather than only one file per format.
Responsive Images and Modern Formats
Choosing an efficient format and choosing an appropriate image dimension are separate optimization decisions. A highly compressed AVIF image can still be unnecessarily large if a 2000-pixel source is downloaded for an image that is displayed at 400 pixels.
Likewise, a perfectly sized JPEG can still be larger than necessary when another format provides similar visual quality at a smaller transfer size. Responsive image systems work best when format selection, dimensions and compression are optimized together.
Width and Height Attributes
Responsive images should still have explicit width and height attributes whenever the intrinsic dimensions are known. These attributes do not force the image to remain at those rendered dimensions. They provide the browser with the intrinsic aspect ratio and help reserve the correct amount of layout space before the image loads.
<img
src="/images/photo-800.jpg"
srcset="
/images/photo-400.jpg 400w,
/images/photo-800.jpg 800w,
/images/photo-1200.jpg 1200w
"
sizes="(max-width: 800px) 100vw, 800px"
width="800"
height="533"
alt="Mountain landscape"
>The width-to-height ratio establishes the image's aspect ratio. CSS can then control the final rendered size while the browser can preserve the correct geometry during loading.
Using CSS with Responsive Images
Responsive image attributes and CSS have complementary roles. HTML describes the available image resources and their expected dimensions, while CSS controls how the selected image is presented in the layout.
.responsive-image {
display: block;
width: 100%;
height: auto;
max-width: 100%;
}For fixed-ratio containers, CSS aspect-ratio can be useful when the design requires a predictable box. object-fit can then control how the image fills that box.
.card-image {
width: 100%;
aspect-ratio: 16 / 9;
object-fit: cover;
display: block;
}This is particularly useful for card grids where source images may have different intrinsic dimensions but the UI requires consistent visual proportions.
Responsive Images in CSS Backgrounds
Background images can also respond to viewport conditions through CSS media queries, but CSS backgrounds do not use img srcset and sizes in the same way as HTML images. When an image is meaningful content, an img or picture element is generally more appropriate because it provides semantics and browser image-loading behavior.
.hero {
background-image: url("/images/hero-desktop.jpg");
}
@media (max-width: 700px) {
.hero {
background-image: url("/images/hero-mobile.jpg");
}
}Background images are appropriate when the image is decorative or is part of the visual presentation rather than meaningful page content. CSS can then be used to select different background assets for different conditions.
Lazy Loading and Responsive Images
Responsive image selection and lazy loading solve different problems. Responsive image attributes determine which resource is appropriate. Lazy loading determines when a resource should be requested.
<img
src="/images/article-800.jpg"
srcset="
/images/article-400.jpg 400w,
/images/article-800.jpg 800w,
/images/article-1200.jpg 1200w
"
sizes="(max-width: 800px) 100vw, 800px"
width="800"
height="533"
loading="lazy"
alt="Article illustration"
>Below-the-fold images are common candidates for lazy loading. Important above-the-fold images, particularly a prominent hero or likely LCP image, should not automatically be lazy-loaded. Delaying a critical image can make the page slower instead of faster.
Responsive Images and LCP
The largest contentful paint image deserves special attention. If the main visual element is loaded from an unnecessarily large resource, the browser may spend additional time downloading and decoding it. If the resource is too small, visual quality can suffer.
For a critical hero image, use an accurate srcset and sizes configuration, generate appropriately sized files and avoid lazy loading when the image is needed immediately. Frameworks such as Next.js can also automate parts of responsive image generation and resource selection when their image components are configured correctly.
Responsive Images in Next.js
Next.js provides the Image component for common responsive image workflows. It can generate or request appropriately sized images and can use responsive sizing information to help determine which resource should be delivered.
import Image from "next/image";
export function ArticleImage() {
return (
<Image
src="/images/mountain.jpg"
alt="Mountain landscape"
width={1600}
height={1067}
sizes="(max-width: 768px) 100vw, 800px"
/>
);
}The sizes property is especially important when an image has a fluid layout. It tells the image system how much horizontal space the image is expected to occupy at different viewport sizes.
For a full-width mobile image that becomes a narrower article image on larger screens, a sizes value might describe 100vw on smaller screens and a fixed or constrained width on larger screens. The exact value should match the actual CSS layout.
Responsive Images in React
React does not change the underlying responsive image model. Standard HTML attributes such as srcSet and sizes can be used directly on an img element, while picture and source can be represented with JSX.
export function ResponsiveImage() {
return (
<picture>
<source
media="(max-width: 700px)"
srcSet="/images/hero-mobile.jpg"
/>
<img
src="/images/hero-desktop.jpg"
alt="Person working at a desk"
width={1600}
height={900}
/>
</picture>
);
}For repeated content such as article cards, product grids or galleries, it is often better to build a reusable image component that standardizes dimensions, alt text, sizes and loading behavior instead of duplicating inconsistent markup throughout the application.
Generating Responsive Image Variants
A production image pipeline normally starts with an original asset and generates several derivatives. These derivatives can differ in width, format and sometimes crop.
For example, an uploaded 4000-pixel photograph might be converted into a collection of smaller WebP and AVIF files. The application can then expose the generated variants through srcset or a framework image component.
This approach is preferable to asking the browser to download a huge original and rely on CSS to shrink it. The browser cannot recover bandwidth that has already been spent downloading pixels that were never needed.
Choosing Image Dimensions
The correct source dimensions depend on the maximum rendered size, device pixel ratio, crop requirements and image type. A useful starting point is to inspect the actual layout rather than choosing arbitrary widths.
If an article image never exceeds 760 CSS pixels, a source around 760 pixels may be sufficient for a standard-density display, while a larger candidate can cover high-density displays. If the same image becomes a full-width hero on large screens, its maximum required source width will be much larger.
An image resize calculator or dimension checker can help verify source dimensions and prevent accidentally generating assets that are either too small or excessively large.
Aspect Ratio Matters
Responsive variants should normally preserve the original aspect ratio when they represent the same composition. If a 1600 × 900 image becomes 800 × 450, the ratio remains 16:9.
If the layout requires a different composition rather than simple scaling, use a separate crop. This is an art-direction problem rather than ordinary resolution switching.
Original: 1600 × 900
Responsive variant: 800 × 450
Aspect ratio: 16:9Keeping predictable aspect ratios helps prevent unexpected distortion and makes responsive layouts easier to reason about. An aspect ratio calculator can be useful when generating or checking image variants.
Image Cropping for Responsive Layouts
Some designs intentionally crop images differently at different breakpoints. A desktop hero might show a wide scene, while a mobile hero might focus on the main subject. Simply resizing the desktop image may leave the subject too small or poorly positioned on a narrow screen.
The picture element is a good fit when different crops are separate image assets. CSS object-fit and object-position are useful when the same source can satisfy the design through client-side cropping.
.responsive-crop {
width: 100%;
aspect-ratio: 4 / 3;
object-fit: cover;
object-position: center;
}A crop calculator can help determine the resulting dimensions and proportions when preparing different variants.
Common Responsive Image Mistakes
One common mistake is assuming that width: 100% automatically reduces the downloaded file. It does not. The browser can still request a large source image and scale it down during rendering.
Another mistake is using srcset with width descriptors but omitting sizes for a layout where the image width is not effectively the full viewport width. This can make resource selection less accurate.
Generating dozens of image widths for every asset can also be counterproductive. More variants increase storage, processing and cache complexity. Image widths should reflect real layout requirements.
A further mistake is using picture when srcset would be sufficient. If the image composition does not change and only the resolution changes, srcset and sizes are usually simpler.
The opposite mistake also occurs: trying to solve art direction with a single source and CSS cropping when the mobile and desktop compositions really require different image assets.
How to Build a Responsive Image Strategy
Start by identifying the actual image roles in the interface. Article images, product cards, avatars, hero images, thumbnails and decorative backgrounds often have very different requirements.
Next, determine the rendered width at the important layout breakpoints. Do not start with arbitrary source dimensions. Measure the actual component or derive its dimensions from the design system.
Then generate a reasonable set of image variants around those dimensions. Select an efficient format, preserve the required aspect ratio and create alternative crops only where the composition genuinely needs to change.
Finally, describe the resources correctly in HTML or through the framework's image system. Verify srcset, sizes, width, height, loading behavior and the final network requests in browser developer tools.
Testing Responsive Images
Responsive image implementations should be tested at several viewport widths and device pixel ratios. Resizing the browser window is useful, but it is also important to inspect the actual network requests to confirm that the expected image candidate is being downloaded.
Browser developer tools can show the requested image URL, transferred size and resource timing. This makes it possible to detect cases where a small mobile image unexpectedly downloads a large desktop asset.
It is also worth testing slow network conditions. An image that appears acceptable on a fast desktop connection may become a major bottleneck on a slower mobile connection.
| Check | What to verify |
|---|---|
| Rendered width | The image occupies the expected amount of layout space |
| srcset | Available image candidates cover the important sizes |
| sizes | The declared sizes match the actual layout |
| Format | An efficient format is used where appropriate |
| Aspect ratio | The image does not unexpectedly distort or shift |
| Network request | The browser downloads an appropriately sized candidate |
| Loading | Critical images are not unnecessarily lazy-loaded |
Responsive Images and SEO
Responsive images can contribute to better page performance, which is important for user experience and can affect search performance through Google's page experience and Core Web Vitals systems. The SEO benefit is therefore usually indirect: efficient image delivery can help create a faster, more stable page.
Image SEO also depends on meaningful alt text, appropriate file formats, correct dimensions, accessible markup and useful surrounding content. Responsive delivery should be considered part of the overall image optimization strategy rather than a replacement for these practices.
Responsive Images Checklist
- Use srcset when multiple resolutions of the same image are available.
- Use sizes when srcset contains width descriptors and the rendered width depends on the layout.
- Use picture when you need art direction or format-specific sources.
- Provide width and height attributes when the intrinsic dimensions are known.
- Generate image variants based on actual layout requirements.
- Preserve the aspect ratio unless a different crop is intentional.
- Use modern image formats where they provide a practical benefit.
- Avoid lazy-loading critical above-the-fold images.
- Inspect network requests to verify which image candidates are actually downloaded.
- Do not generate unnecessary numbers of image variants.
Frequently Asked Questions
What is a responsive image?
A responsive image is an image delivered or rendered in a way that adapts to the device, viewport, display density and layout. The browser can select an appropriate image resource instead of downloading the same large file for every device.
What is the difference between srcset and sizes?
srcset defines the available image candidates, while sizes describes how wide the image is expected to be displayed under different viewport conditions. When width descriptors are used, the browser uses both pieces of information to select an appropriate resource.
Do I need sizes with srcset?
If srcset uses width descriptors such as 400w and 800w, sizes is generally important for accurately describing the image's rendered width. Without accurate sizes information, resource selection may be less efficient.
When should I use picture instead of srcset?
Use srcset and sizes when you are serving different resolutions of the same composition. Use picture when you need different crops, different compositions or format-specific source selection.
Does width: 100% make an image responsive?
It makes the rendered image adapt to its container, but it does not necessarily make the downloaded resource responsive. The browser may still download a large source and scale it down. srcset and sizes can reduce unnecessary downloads.
How many responsive image sizes should I generate?
There is no universal number. Generate variants that cover the real rendered widths used by your layouts and provide enough candidates to avoid large jumps between sizes. Excessive variants increase storage and processing complexity without necessarily improving performance.
Should responsive images use WebP or AVIF?
They can. WebP and AVIF can reduce transfer size compared with many older formats, but format choice and image dimensions are separate concerns. A modern format is still inefficient if the browser downloads an unnecessarily large image.
Helpful Image Tools
When preparing responsive image variants, a Responsive Image Size Calculator can help estimate suitable source dimensions for different display conditions. An Image Aspect Ratio Calculator is useful for preserving consistent proportions, while an Image Resize Calculator can determine target dimensions for generated variants. For art-directed layouts, an Image Crop Calculator can help calculate crop dimensions, and an Image Dimension Checker can verify the final width and height of an image before it is published.
Conclusion
Responsive images are about delivering the right image resource for the actual rendering conditions rather than simply shrinking a large image with CSS. The core tools are srcset for providing candidates, sizes for describing the expected rendered width and picture for cases where different sources or compositions are required.
A good implementation starts with the real layout. Determine how large an image can become, generate sensible variants, preserve the required aspect ratio, choose an efficient format and describe the resources accurately. Then verify the result in browser developer tools to make sure the browser is actually downloading appropriately sized files.
When responsive image delivery is combined with proper compression, modern formats, correct dimensions, sensible loading behavior and stable layout geometry, images can remain visually sharp without becoming an unnecessary performance bottleneck.