Descriptive Alt Text
Always provide meaningful alternative text using the alt
attribute. This improves accessibility for screen reader users and helps with SEO.
<img src="landscape.jpg" alt="A panoramic view of the mountains at sunrise">
Lazy Loading
Use the loading="lazy"
attribute to defer loading images until they are nearly in view. This reduces initial load time and conserves bandwidth.
<img src="gallery.jpg" alt="A gallery image" loading="lazy">
Responsive Images
Serve the appropriate image resolution for different devices with srcset
and sizes
. This minimizes unnecessary data usage.
<img src="small.jpg"
srcset="small.jpg 480w, medium.jpg 800w, large.jpg 1200w"
sizes="(max-width: 600px) 480px, (max-width: 1200px) 800px, 1200px"
alt="Responsive example image">
Modern Formats & Fallbacks
Leverage modern formats like WebP for smaller file sizes and high quality. Always provide a fallback (e.g., JPEG) for better browser support.
<picture>
<source srcset="image.webp" type="image/webp">
<img src="image.jpg" alt="Example image with fallback">
</picture>