Serve responsive images with next/image
next/image emits responsive srcset values, picks modern formats and prevents layout shift when width and height are known. Replace raw img tags on content pages, pass sizes for each layout width, mark the LCP image priority, and keep alt text meaningful. Check the rendered HTML for srcset and intrinsic dimensions rather than trusting the component defaults.
Why this matters
One component handles sizing, formats and lazy loading.
Before you start
- Next.js project and access to the image templates
- Known layout widths for the content column and cards
How to apply it
Inventory the raw images
Find every img tag in pages and components and note the rendered slot width. Start with the hero image and any image above the fold.
Check: grep -rn '<img' app/ components/ lists the tags with their file paths before any change.
Replace tags with next/image
Import Image from next/image, pass width and height or fill with a positioned parent, and move alt text unchanged. Add sizes that match the CSS breakpoints.
Check: The page renders an img with a srcset attribute containing at least two candidate widths.
Prioritise the LCP image
Add priority to the single largest above-the-fold image and remove it from every other image so the preload does not compete with critical CSS.
Check: The rendered HTML contains one image preload link and the hero image tag carries fetchpriority=high.
Confirm dimensions and formats
Check that intrinsic width and height attributes are present and that the optimizer serves WebP or AVIF to a supporting browser, then measure LCP again.
Check: PageSpeed Insights shows the hero image served in a modern format with no layout shift.
Source: seo-mcp playbook · curated entry · report an error
Official references
Framework notes
nextjs-app
Use `next/image` with explicit `width`/`height` or `fill` plus `sizes`; add `priority` to the LCP image and `remotePatterns` in `next.config` for remote hosts.
nextjs-pages
`next/image` works in the Pages Router; import it per component, pass `sizes` for responsive `srcset`, and keep `priority` on the hero only.