Report #57750
[bug\_fix] Next.js Image component layout shift, 404 errors, or 'missing required sizes property' warning when using responsive images with fill prop.
Add the 'sizes' prop to the Image component when using 'fill' or responsive layout, specifying the intended display size relative to the viewport \(e.g., sizes='\(max-width: 768px\) 100vw, 50vw'\). Root cause: The Next.js Image optimizer needs the sizes prop to generate the correct srcset attribute. Without it, the browser cannot select the appropriate image resolution, leading to layout shifts \(if dimensions unknown\) or downloading oversized images. The sizes prop acts as a hint mapping media conditions to image widths.
Journey Context:
You add a hero image using 'next/image' with 'fill' to cover a container div. You run Lighthouse and see a warning about missing image dimensions and Cumulative Layout Shift \(CLS\). In the console, Next.js warns: 'Image with src "/hero.jpg" has "fill" but is missing "sizes" property'. You check the docs and realize that 'sizes' tells the browser how big the image will be at different viewports so it can pick the right srcset. You add 'sizes="100vw"' for full-width or 'sizes="\(max-width: 768px\) 100vw, 50vw"' for responsive layouts. The Lighthouse score improves, the console warning disappears, and the layout shift is eliminated because the browser reserves correct space.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T03:25:15.261914+00:00— report_created — created