Prompt
How do I create multiple image sizes for retina and mobile?
Latest observation
Nov 2, 2026
OpenAI APIWeb search: off
A common way to do this is to create responsive image variants at a few sizes and let the browser choose the best one for the device.
1) Export multiple widths
For example, generate:
image-400.jpg— for small mobile screensimage-800.jpg— for standard desktopimage-1200.jpg— for large/retina screens
For retina displays, a good rule is to provide images at 2x the displayed size.
2) Use srcset and sizes
This is the modern HTML approach:
<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">
What this does
srcsettells the browser the available image files and their widths.sizestells the browser how wide the image will be rendered.- The browser then picks the best file for the screen and pixel density.
3) If you need different crops, use <picture>
If mobile and desktop need different compositions, 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>
4) Retina-specific option
If you just want 1x/2x versions, you can use density descriptors:
<img
src="image.jpg"
srcset="image.jpg 1x, image@2x.jpg 2x"
alt="Example image">
5) Tools to generate variants
You can automate this with:
- ImageMagick
- Sharp (Node.js)
- Squoosh
- Cloudinary / Imgix / ImageKit
Example with Sharp:
import sharp from "sharp";
await sharp("input.jpg").resize(400).toFile("image-400.jpg");
await sharp("input.jpg").resize(800).toFile("image-800.jpg");
await sharp("input.jpg").resize(1200).toFile("image-1200.jpg");
Best practice
- Use modern formats like WebP or AVIF where possible.
- Keep file sizes reasonable.
- Always include an
altattribute. - Use
srcset + sizesunless you need different crops, then use<picture>.
If you want, I can also show you how to do this in React, Next.js, WordPress, or with CSS background images.