Prompt
I'm building a website and need automatic image resizing for different breakpoints
Latest observation
Nov 2, 2026
OpenAI APIWeb search: off
A good way to handle this is to generate responsive image variants and serve the right one at each breakpoint using srcset and sizes.
Basic approach
- Upload one large original image
- Generate resized versions for common widths, for example:
- 320px
- 640px
- 960px
- 1280px
- 1920px
- Use responsive HTML so the browser picks the best file automatically.
Example
<img
src="image-640.jpg"
srcset="
image-320.jpg 320w,
image-640.jpg 640w,
image-960.jpg 960w,
image-1280.jpg 1280w
"
sizes="(max-width: 600px) 100vw,
(max-width: 1200px) 50vw,
33vw"
alt="Example image">
How it works
srcsettells the browser which image widths are available.sizestells the browser how large the image will appear at different screen widths.- The browser chooses the most appropriate file based on device width and pixel density.
If you want automatic resizing on the server/CDN
Use an image service or CDN that can resize on demand:
- Cloudinary
- Imgix
- ImageKit
- Fastly Image Optimizer
- Cloudflare Images
These can generate URLs like:
https://example.com/image.jpg?width=640
Best practices
- Keep images in modern formats like WebP or AVIF
- Serve appropriately compressed files
- Use
loading="lazy"for below-the-fold images - Preserve aspect ratio to avoid layout shifts
Example with <picture> for format fallbacks
<picture>
<source
type="image/avif"
srcset="image-320.avif 320w, image-640.avif 640w, image-960.avif 960w"
sizes="(max-width: 600px) 100vw, 50vw">
<source
type="image/webp"
srcset="image-320.webp 320w, image-640.webp 640w, image-960.webp 960w"
sizes="(max-width: 600px) 100vw, 50vw">
<img
src="image-640.jpg"
srcset="image-320.jpg 320w, image-640.jpg 640w, image-960.jpg 960w"
sizes="(max-width: 600px) 100vw, 50vw"
alt="Example image">
</picture>
If you tell me what stack you’re using, I can show the exact setup:
- plain HTML/CSS
- React / Next.js
- Vue / Nuxt
- WordPress
- server-side image processing with Node/Python/PHP