Our design team once taped a screenshot above my monitor with "why is this hero still blurry?" written in red marker. The culprit wasn't one bug. It was a half-configured image pipeline: the wrong sizes, a missing remote pattern, and a cache that expired every minute.
Next.js ships with great image defaults, but only if the config, the component props and your CMS all agree. Here's the setup I now use on every project, updated for Next.js 16.
How next/image actually works
When you render <Image>, Next.js doesn't send your original file. It generates a srcset of URLs like /_next/image?url=…&w=1080&q=75. The browser picks one based on the screen and the sizes attribute, and the Next.js server resizes, re-encodes and caches that variant on first request.
So three things decide what the user sees:
-
Which widths exist —
deviceSizesandimageSizesin config. -
Which width the browser picks — the
sizesprop. -
How long variants stay cached —
minimumCacheTTLplus the upstream image's cache headers.
Get any one wrong and you either ship blurry images or huge ones.
The config
// next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
images: {
formats: ['image/avif', 'image/webp'],
remotePatterns: [
new URL('https://media.example.com/**'),
{ protocol: 'https', hostname: '*.public.blob.vercel-storage.com' },
],
qualities: [60, 75, 90],
minimumCacheTTL: 60 * 60 * 24 * 30, // 30 days
},
}
export default nextConfig
What each line buys you:
-
formats— AVIF is typically around 20% smaller than WebP at the same quality. Next.js serves the first format the browser accepts, falling back to WebP. AVIF is slower to encode, so the first request for each variant takes a little longer. -
remotePatterns— images from hosts that aren't listed are rejected with an error. Be specific;hostname: '**'turns your server into a free image proxy for anyone. -
qualities— in Next.js 16 this list is an allow-list. Aqualityprop that isn't in it is coerced to the closest allowed value, which stops anyone from generating endless variants by tweaking the URL. -
minimumCacheTTL— the default is 4 hours. If your CMS gives every upload a unique URL (Payload and most CMSs do), there's no reason to re-optimise every few hours. A low value here quietly increases your image-optimisation bill.
The sizes prop is the whole game
Most blurry or bloated images come from a missing or wrong sizes. Without it, a responsive image assumes it's as wide as the viewport, so a 400px card on a 4K monitor downloads a 3840px file.
sizes tells the browser how wide the image will be at each breakpoint, before CSS has loaded:
import Image from 'next/image'
export function PostCard({ post }: { post: { title: string; image: { url: string; alt: string } } }) {
return (
<div className="relative aspect-[16/9]">
<Image
src={post.image.url}
alt={post.image.alt}
fill
sizes="(min-width: 1280px) 400px, (min-width: 768px) 50vw, 100vw"
className="object-cover"
/>
</div>
)
}
Read it as: on large screens the card is 400px wide; on tablets it's half the viewport; on phones it's the full width. Write the values from your actual grid. The rule I give the team: every fill image must have sizes .
Preload the LCP image (priority is deprecated)
The hero image is usually the page's Largest Contentful Paint element. By default next/image lazy-loads, which delays it. In Next.js 16 the priority prop is deprecated — use preload for the one image above the fold:
<Image
src={hero.url}
alt={hero.alt}
width={1600}
height={900}
sizes="100vw"
preload
quality={90}
/>
Use it on one image per page. Preloading everything competes for bandwidth and makes LCP worse.
No layout shift: dimensions or fill
Cumulative Layout Shift happens when the browser doesn't know an image's size until it downloads. next/image forces you to pick one of:
-
width+height— for images with a known aspect ratio. These set the ratio, not the display size; CSS can still make the image responsive. -
fill— the image fills a parent that hasposition: relativeand a size. Pair it with anaspect-*class so the box is reserved before the image arrives.
For CMS images, store width and height on upload. Payload's upload collections do this automatically, so you can pass media.width and media.height straight through.
Placeholders that feel fast
A blank box that suddenly fills in feels slower than a blurred preview that sharpens. For static imports, placeholder="blur" works out of the box. For CMS images you need a tiny blurDataURL — generate a 10px-wide base64 version on upload and store it next to the image:
<Image src={media.url} alt={media.alt} width={media.width} height={media.height}
placeholder="blur" blurDataURL={media.blurDataURL} />
Ban raw img tags
All of this is wasted if someone pastes <img src="…"> into a component. Next.js's ESLint plugin already has a rule for it — make it an error, not a warning:
// eslint.config.mjs (excerpt)
export default [
{
rules: {
'@next/next/no-img-element': 'error',
},
},
]
That one rule has caught more regressions for us than any code review.
Don't optimise twice
If your images already come from a CDN that resizes on the fly (Cloudinary, Imgix, Vercel Blob with a resizer), either point Next.js at it with a custom loader or pass unoptimized for those images. Re-optimising an already-optimised image adds latency and cost with no visual gain. SVGs should usually be unoptimized too — they're already resolution-independent.
How I verify it
- Open DevTools → Network → filter by Img. Check the downloaded width is close to the displayed width × device pixel ratio.
- Run Lighthouse and look at "Properly size images" and "Largest Contentful Paint element".
- In production, watch LCP and CLS in your real-user monitoring (Vercel Speed Insights or the Chrome UX Report), not just lab scores.
Checklist
- Remote hosts listed precisely in
remotePatterns. - AVIF and WebP in
formats; a shortqualitiesallow-list. -
minimumCacheTTLmeasured in days, not seconds, for immutable CMS URLs. - Every
fillimage has a realisticsizes. - Exactly one
preloadimage per page — the LCP element. - Width/height or an aspect-ratio box on every image.
-
@next/next/no-img-elementset to error.
Designers noticed the difference the week we shipped this, and Core Web Vitals agreed. The red-marker screenshot is still on my wall — as a reminder, not a complaint.
Originally published at www.tayloramitverma.com.
Top comments (0)