Master web image optimization for performance and SEO
Images typically account for 50-70% of total page weight. Optimizing images can dramatically improve:
Serve different image formats with automatic fallback:
<picture>
<!-- Modern formats for supported browsers -->
<source srcset="image.avif" type="image/avif">
<source srcset="image.webp" type="image/webp">
<!-- Fallback for older browsers -->
<img src="image.jpg" alt="Description"
loading="lazy"
width="800"
height="600">
</picture>
Serve different image sizes based on screen resolution:
<img srcset="image-320w.jpg 320w,
image-640w.jpg 640w,
image-1280w.jpg 1280w"
sizes="(max-width: 640px) 100vw,
(max-width: 1280px) 50vw,
33vw"
src="image-640w.jpg"
alt="Description"
loading="lazy">
Use tools like TinyPNG, ImageOptim, or Squoosh to reduce file size by 50-80% without visible quality loss.
Never use CSS to resize images. Always serve images at the exact size they'll be displayed.
Use loading="lazy" to defer loading off-screen images until users scroll to them.
Serve images from a CDN for faster delivery worldwide and automatic optimization.
Always specify width and height attributes to prevent layout shifts (CLS).
Write descriptive alt text for accessibility and SEO. Be specific and concise.