Prompt
How do I deliver different image sizes based on device and screen width?
Latest observation
Nov 21, 2026
OpenAI APIWeb search: off
Use responsive images so the browser picks the best file for the device and viewport width.
1) Use srcset + sizes for width-based switching
This is the most common approach when you have multiple image widths.
<img
src="image-800.jpg"
srcset="
image-400.jpg 400w,
image-800.jpg 800w,
image-1200.jpg 1200w,
image-1600.jpg 1600w
"
sizes="
(max-width: 600px) 100vw,
(max-width: 1200px) 50vw,
800px
"
alt="Example image"
/>
How it works
srcsetlists available image files and their widths.sizestells the browser how wide the image will be in the layout at different breakpoints.- The browser chooses the most appropriate file based on:
- viewport width
- device pixel ratio (e.g. Retina screens)
- layout size
2) Use srcset with pixel-density descriptors for 1x/2x
If the image is displayed at a fixed size, use x descriptors:
<img
src="image.jpg"
srcset="image.jpg 1x, image@2x.jpg 2x"
alt="Example image"
/>
This is good for icons or images with a known display size.
3) Use <picture> for art direction
If you want different crops or different images on mobile vs desktop, use <picture>:
<picture>
<source media="(max-width: 600px)" srcset="mobile-image.jpg">
<source media="(min-width: 601px)" srcset="desktop-image.jpg">
<img src="desktop-image.jpg" alt="Example image">
</picture>
Use this when the composition should change, not just the size.
4) Generate several image sizes
Usually you create multiple variants such as:
- 400px
- 800px
- 1200px
- 1600px
And optionally multiple formats:
- AVIF
- WebP
- JPEG/PNG fallback
Example:
<picture>
<source
type="image/avif"
srcset="image-400.avif 400w, image-800.avif 800w, image-1200.avif 1200w"
sizes="(max-width: 600px) 100vw, 800px"
>
<source
type="image/webp"
srcset="image-400.webp 400w, image-800.webp 800w, image-1200.webp 1200w"
sizes="(max-width: 600px) 100vw, 800px"
>
<img
src="image-800.jpg"
srcset="image-400.jpg 400w, image-800.jpg 800w, image-1200.jpg 1200w"
sizes="(max-width: 600px) 100vw, 800px"
alt="Example image"
>
</picture>
5) Best practices
- Always include a normal
srcfor fallback. - Match
sizesto your real CSS layout. - Don’t send overly large images to mobile.
- Compress and serve modern formats when possible.
- Use
loading="lazy"for below-the-fold images:
<img loading="lazy" ...>
Quick recommendation
- Different sizes only: use
srcset+sizes - Different crops/content: use
<picture> - Retina support for fixed-size images: use
1x/2xdescriptors
If you want, I can give you:
- a plain HTML example,
- a React/Next.js example, or
- a WordPress/CMS setup.
Brands