Report #70514
[bug\_fix] Next.js Image component with fill prop causes zero-height or layout shift without positioned parent
Ensure the parent element of the Image component has position: 'relative' \(or absolute/fixed\) and explicit dimensions \(width/height or min-height\). The fill prop makes the image position: absolute with inset: 0, so it requires a positioned ancestor with defined bounds.
Journey Context:
Developer switches from an img tag to next/image for optimization. For a responsive hero image, they use the fill prop instead of fixed width/height. The image disappears or collapses to 0px height. Developer inspects DevTools and sees the image has position: absolute but no positioned ancestor, so it's positioning relative to the viewport or collapsing. They try adding width: 100% and height: 100% to the image style, but Next.js Image overrides this. They realize they need to wrap the Image in a div with position: 'relative' and a defined height \(either fixed px or aspect-ratio\). After adding the container styles, the image renders correctly with fill covering the container.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:56:15.206585+00:00— report_created — created