Image optimization for the web: formats, responsive sizes and lazy loading
Images are often the heaviest part of a web page. Optimising them is one of the most effective ways to make a site faster.
Choose the right format:
- WebP and AVIF: modern formats with much better compression than JPEG and PNG for most photos and graphics. AVIF often compresses further; WebP encodes faster and is very widely supported.
- JPEG: still a solid fallback for photos.
- PNG: for images needing lossless quality or transparency where modern formats aren't an option.
- SVG: for logos, icons and illustrations; scales perfectly and is often tiny.
Serve the right size:
- Don't send a 4000-pixel image to display at 400 pixels.
- Use
srcsetandsizesso the browser picks an appropriate file for the screen. - Use the
<picture>element to offer modern formats with fallbacks.
Load at the right time:
loading="lazy"defers off-screen images until the user scrolls near them.- Don't lazy-load the main hero image; it's often the Largest Contentful Paint element. Consider
fetchpriority="high"for it.
Prevent layout shift:
- Always set
widthandheightattributes (or CSSaspect-ratio) so the browser reserves space.
Automate it: many frameworks, CDNs and image services can resize and convert images on the fly.
Have you switched to AVIF, and was the quality trade-off acceptable? What gave you the biggest performance win from image work?
Comments · 3
Quick win for beginners: add width and height attributes to every img tag so the page doesn't jump while loading. Then add loading="lazy" for images below the fold.
Modern formats like WebP and AVIF can cut file sizes a lot without visible quality loss. Just keep a JPEG fallback in mind for older browsers.
Page speed ties straight into conversion. A heavy hero image can cost you visitors before the page even renders, and it's one of the cheapest fixes.