Prompt
How do I handle different image sizes for breakpoints and retina displays?
Latest observation
Nov 3, 2026
OpenAI APIWeb search: off
A good way to handle this is to separate two concerns:
- Responsive art direction / layout breakpoints: serve different image sizes for different viewport widths.
- High-density displays (retina / DPR): serve sharper images for devices with more device pixels.
Best practice: use srcset + sizes
For most responsive images, this is the simplest and most flexible solution.
<img
src="photo-800.jpg"
srcset="
photo-400.jpg 400w,
photo-800.jpg 800w,
photo-1200.jpg 1200w,
photo-1600.jpg 1600w
"
sizes="
(max-width: 600px) 100vw,
(max-width: 1200px) 50vw,
33vw
"
alt="Example image"
/>
How it works
srcsetlists available image files and their intrinsic widths.sizestells the browser how wide the image will actually be on the page at different breakpoints.- The browser uses those values plus the device pixel ratio to pick the best file.
This automatically handles:
- mobile vs desktop breakpoints
- retina displays
- bandwidth optimization
For retina displays specifically
If you want to provide 1x and 2x versions, you can use pixel density descriptors:
<img
src="photo.jpg"
srcset="photo.jpg 1x, photo@2x.jpg 2x"
alt="Example image"
/>
This is fine for simple cases, but w descriptors with sizes are usually better for responsive layouts.
If you need different crops, use <picture>
When the image itself should change shape or composition at different breakpoints, use <picture>:
<picture>
<source
media="(max-width: 600px)"
srcset="photo-mobile-400.jpg 400w, photo-mobile-800.jpg 800w"
sizes="100vw"
/>
<source
media="(min-width: 601px)"
srcset="photo-desktop-800.jpg 800w, photo-desktop-1600.jpg 1600w"
sizes="50vw"
/>
<img src="photo-desktop-800.jpg" alt="Example image" />
</picture>
Use this when:
- mobile needs a different crop than desktop
- aspect ratio changes
- you want to art-direct the image
Practical recommendations
- Export images at a few sensible widths, such as:
400, 800, 1200, 1600. - Use
srcset+sizesfor responsive sizing. - Use
pictureonly when the image content/crop changes. - Compress images well and prefer modern formats like WebP or AVIF when possible.
Common mistake
Avoid relying only on CSS width: 100% or only on @2x images. That won’t fully solve responsive breakpoints or load the most efficient file for each screen.
If you want, I can also show:
- a real example for CSS/HTML
- how to do this in React/Next.js
- how to generate the image variants automatically