Impact: HIGH (40-80% image size reduction and elimination of Cumulative Layout Shift)
Images are typically the largest assets on a web page. Raw <img> tags force the browser to download full-size images regardless of viewport, cause layout shift (CLS) when they load, and serve unoptimized formats. The next/image component provides:
Automatic format conversion — serves WebP/AVIF when the browser supports it
Responsive sizing — generates multiple sizes and uses srcset for the right one
Lazy loading by default — only loads images when they enter the viewport
Layout shift prevention — reserves space based on dimensions, preventing CLS
Blur placeholders — shows a blurred preview while the full image loads
Incorrect (raw img tags):
// ❌ Full-size image downloaded on every device, causes layout shiftexport default function ProductCard({ product }) { return ( <div> <img src={product.imageUrl} alt={product.name} /> <h3>{product.name}</h3> </div> )}// ❌ CSS background images skip all optimization<div style={{ backgroundImage: `url(${hero.url})` }} />// ❌ Eager loading large images in below-the-fold content<img src="/huge-banner.jpg" alt="Banner" loading="eager" />
Correct (next/image with proper configuration):
import Image from 'next/image'// ✅ Local images — dimensions inferred automaticallyexport default function ProductCard({ product }) { return ( <div> <Image src={product.imageUrl} alt={product.name} width={400} height={300} sizes="(max-width: 768px) 100vw, 400px" /> <h3>{product.name}</h3> </div> )}// ✅ Hero/LCP images — set priority to preload<Image src="/hero.jpg" alt="Welcome to our store" width={1200} height={600} priority // Preloads the image, disables lazy loading sizes="100vw" placeholder="blur" // Shows blurred version while loading blurDataURL={blurHash} // Base64 blur placeholder/>// ✅ Fill mode for unknown dimensions (e.g., user uploads)<div className="relative aspect-video"> <Image src={user.avatarUrl} alt={user.name} fill className="object-cover" sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw" /></div>