Prompt
How do I prepare images for lazy loading and responsive breakpoints?
Latest observation
To prepare images for lazy loading and responsive breakpoints, you want to create multiple optimized versions of each image and serve the right one based on screen size and device capabilities.
1) Create several image sizes
Export each image at a few widths, for example:
- 320px
- 640px
- 960px
- 1280px
- 1600px
Keep the same aspect ratio across sizes.
2) Use modern formats
Prefer:
- AVIF: best compression, great quality
- WebP: widely supported, smaller than JPEG/PNG
- JPEG/PNG: fallback if needed
If the image is photographic, use AVIF/WebP.
If it needs transparency, use WebP or PNG.
3) Compress appropriately
- Use a quality setting around 70–85 for photos
- Remove unnecessary metadata if you don’t need it
- Avoid serving huge original images to small screens
4) Set correct dimensions
Always include width and height in HTML or CSS to prevent layout shift.
5) Use srcset and sizes
This lets the browser choose the best file for the viewport.
Example:
<img
src="image-960.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, 600px"
alt="Description"
loading="lazy"
width="960"
height="640"
/>
srcset= available image widthssizes= how wide the image will display at different breakpointsloading="lazy"= defers loading until near the viewport
6) Use <picture> for art direction or format fallback
If you need different crops or formats:
<picture>
<source
type="image/avif"
srcset="image-320.avif 320w, image-640.avif 640w, image-960.avif 960w"
sizes="(max-width: 600px) 100vw, 600px"
/>
<source
type="image/webp"
srcset="image-320.webp 320w, image-640.webp 640w, image-960.webp 960w"
sizes="(max-width: 600px) 100vw, 600px"
/>
<img
src="image-960.jpg"
alt="Description"
loading="lazy"
width="960"
height="640"
/>
</picture>
7) Lazy load only non-critical images
Use lazy loading for:
- below-the-fold images
- gallery thumbnails
- secondary content
Do not lazy-load the main hero image or images immediately visible on page load.
8) Consider an image CDN or build pipeline
Tools like:
- Cloudinary
- Imgix
- ImageKit
- Next.js image optimization
- sharp / Squoosh in your build process
can generate the right breakpoints automatically.
9) Test the results
Check:
- image file sizes
- whether the right breakpoint is chosen
- page performance in Lighthouse / DevTools
- whether layout shifts are gone
If you want, I can also give you:
- a recommended breakpoint set,
- a ready-to-use HTML/CSS template, or
- a WordPress/React/Next.js version.