Images play a crucial role in user engagement and SEO. Properly optimized images improve page load times, accessibility, and can drive traffic through image search.
Images often account for most of a page's weight
Drive additional traffic from Google Images
Alt text helps visually impaired users
Images help search engines understand content
Alt text describes an image's content for screen readers and search engines. It appears if the image fails to load.
<img src="coffee-beans.jpg" alt="Fresh organic coffee beans in a wooden bowl">
Always specify width and height attributes to prevent layout shift:
<img src="photo.jpg" alt="..." width="800" height="600">
Next-generation formats provide better compression without quality loss:
| Format | Best For | Support |
|---|---|---|
| WebP | Photos and graphics, 25-35% smaller than JPEG | Excellent |
| AVIF | Photos, 50% smaller than JPEG | Growing |
| SVG | Icons, logos, simple graphics | Excellent |
Lazy loading defers loading of images until they're needed:
<img src="photo.jpg" alt="..." loading="lazy">
Serve different image sizes based on device screen:
<imgsrc="image-800.jpg"srcset="image-400.jpg 400w, image-800.jpg 800w, image-1200.jpg 1200w"sizes="(max-width: 600px) 400px, 800px"alt="...">