Web Development

Next.js Image Optimization: A Practical Guide

Next.js image optimization made practical: next/image props, sizes, preload in Next.js 16, AVIF, quality settings, remote images and fixes for slow LCP.

SJ SinanSJ Sinan9 min read
In this article

Your Next.js site looks great, but PageSpeed Insights flags a slow Largest Contentful Paint, and the culprit is almost always an image. A hero photo that’s too big, a gallery that loads everything at once, or a layout that jumps when pictures appear.

Next.js has strong tools for this, but they only help when you use them correctly. This guide covers Next.js image optimization in the App Router, including the changes in Next.js 16 and what to do when your host can’t run the built-in optimizer.

Quick answer: For Next.js image optimization, use the next/image component with width and height (or fill with sizes), set a correct sizes value for responsive images, mark only the main hero image with preload or fetchPriority="high", let other images lazy load, enable AVIF and WebP formats, and compress source images before upload.

Why Images Matter So Much

Images are usually the largest files on a page, and the hero image is often the Largest Contentful Paint element. Google’s Core Web Vitals guidance sets a “good” LCP at 2.5 seconds or less. Images without fixed dimensions also cause layout shift, which hurts Cumulative Layout Shift.

Get images right, and you fix two of the three Core Web Vitals at once.

What next/image Does for You

The Next.js Image component extends the normal img tag. Out of the box, it:

  • Resizes images on demand and serves the right size for each screen
  • Converts images to modern formats the browser supports
  • Lazy loads images by default, so off-screen images don’t slow the first load
  • Reserves space using width and height, which prevents layout shift
  • Caches optimized images on the server

You still have to give it the right information. Most problems come from missing or wrong props.

The Props That Matter Most

PropWhat it doesWhen to use it
width and heightSet the image’s aspect ratio and reserve spaceEvery image with a known size
fillMakes the image fill its parent boxImages whose size depends on the layout
sizesTells the browser how wide the image will displayEvery responsive or fill image
preloadAdds a preload link in the page headOnly the single LCP hero image
loadingLazy (default) or eagerEager for above-the-fold images
qualityCompression level from 1 to 100Only if the default looks wrong
placeholderShows a blurred preview while loadingLarge photos where it helps the experience

Next.js Image Optimization: 7 Rules That Work

1. Always Set sizes on Responsive Images

This is the most common mistake. The docs explain that without sizes, an image with a width gets only a limited 1x and 2x srcset, and a fill image is treated as if it spans the full viewport. Phones then download images far bigger than needed.

For a card that is full width on mobile and one third of the page on desktop, a value like (max-width: 768px) 100vw, 33vw lets the browser pick a sensible file.

2. Prioritize Only the Hero Image

In Next.js 16, the old priority prop is deprecated in favor of preload. Use preload on the single image that is your LCP element, usually the hero. The docs also note that in most cases loading="eager" or fetchPriority="high" is the better choice, and that preload shouldn’t be combined with those.

Never lazy load the hero image. That delays your LCP and is one of the easiest speed wins to fix.

3. Let Everything Else Lazy Load

Below-the-fold images should keep the default lazy loading. Don’t set every image to eager “just in case.” You’ll slow the first load for nothing.

4. Turn On AVIF

By default, Next.js serves WebP. You can add AVIF in next.config.js with images.formats set to AVIF and WebP. According to the docs, AVIF usually compresses about 20% smaller than WebP but takes around 50% longer to encode, so the first request is slower and cached requests are faster. For photo-heavy sites, it’s usually worth it.

5. Check Your Quality Settings

Next.js 16 changed the default allowed qualities to just 75. If you set quality={90} on an image without adding 90 to images.qualities in your config, it won’t be used. In most cases, 75 looks fine. Raise it only for images where detail truly matters, like product close-ups.

6. Allow Remote Images Safely

Images from a CMS or CDN need to be allowed in images.remotePatterns. Be specific with the hostname and path, rather than allowing everything, so nobody can use your server to optimize their images.

7. Start With Good Source Files

The optimizer can resize and convert, but it can’t fix a blurry or badly cropped photo. Upload images at about twice their largest display size, crop them to the right aspect ratio, and give them descriptive file names and alt text for image search.

When the Built-In Optimizer Isn’t an Option

Some hosts and static exports can’t run the Next.js image optimizer, so you need unoptimized. My own site, sjsinan.com, runs that way for hosting compatibility. In that case, you do the optimization before upload:

  • Resize every image to the exact sizes you display, such as 1200 × 630 for blog featured images.
  • Convert to WebP (or AVIF) and compress, for example with a script using the sharp library.
  • Keep fixed aspect ratios in your layout so images never shift the page.
  • Use a CDN like Cloudflare to cache images close to visitors.

It’s more manual, but the result can be just as fast. The featured images I make for this blog are compressed WebP files, usually between 10 and 30 KB.

A Quick Image Audit

Check these on your key pages:

  1. Run PageSpeed Insights and note which element is the LCP.
  2. Confirm the LCP image isn’t lazy loaded.
  3. Look for “Properly size images” and “Serve images in next-gen formats” warnings.
  4. Open the Network tab on a phone-sized screen and check image file sizes.
  5. Scroll the page and watch for layout jumps.

For the bigger picture, my Core Web Vitals optimization guide covers LCP, INP and CLS together, and my Next.js SEO best practices cover the rest of the setup.

Frequently Asked Questions

Does Next.js automatically optimize images?

Only when you use the next/image component and your host supports the built-in optimizer. It then resizes, converts and lazy loads images automatically. A plain img tag gets none of that. You still need to set sizes for responsive images and mark the hero image as a priority, because Next.js can’t guess your layout.

What replaced the priority prop in Next.js 16?

The preload prop replaced priority, which is now deprecated. Use preload only on the single image that is your Largest Contentful Paint element. The Next.js docs also say that in most cases, loading="eager" or fetchPriority="high" is a better choice. Don’t combine preload with either of those properties.

Should I use AVIF or WebP in Next.js?

Enable both. List AVIF first and WebP second in images.formats, and browsers that support AVIF get the smaller file while others get WebP. AVIF files are usually about 20% smaller, but they take longer to create the first time. Once cached, they load faster, which suits most image-heavy sites.

Why are my Next.js images still slow?

The most common causes are a missing sizes value, which makes phones download desktop-sized images, a lazy-loaded hero image, and very large source files. Slow hosting can also delay the first optimization of each image. Check PageSpeed Insights for the LCP element and its file size, then fix the biggest issue first.

Is Next.js image optimization good for SEO?

Yes, indirectly. Faster images improve Core Web Vitals and user experience, which supports rankings. Images also rank in Google Images when they have descriptive file names, alt text and relevant surrounding content. Next.js image optimization handles the speed side, but the alt text and file names are still up to you.

What sizes value should I use with next/image?

The sizes prop tells the browser how wide the image will be shown at different screen sizes, so it can download the right file. For an image that fills the screen on phones and half the width on larger screens, something like “(max-width: 768px) 100vw, 50vw” works. Without sizes, a responsive image may download a much larger file than needed.

Can I use next/image with images from WordPress or another CMS?

Yes. Add the image host, such as your WordPress domain, to remotePatterns in your Next.js config, and next/image will optimize those images like local ones. Keep the pattern as specific as you can, for example limited to your uploads folder, so the optimizer can’t be used for images from any site.

Final Thoughts

Next.js image optimization comes down to a few habits: use next/image, always set sizes, prioritize only the hero, let the rest lazy load, and start with good source files. If your host can’t run the optimizer, do the same work before upload.

If your Next.js site still feels slow, take a look at my website speed optimization service, or send me your URL and I’ll tell you what’s holding it back.

Found this useful? Share it:
SJ Sinan

Written by

SJ Sinan

Web Developer, SEO Specialist & Digital Marketer

I build fast WordPress and Next.js websites, rank them on Google and run Meta and Google Ads for businesses around the world. Everything I write here comes from real client work.

Comments

Be the first to share your thoughts or ask a question.

Leave a comment

Your email will not be published. Comments appear after review.

Free consultation

Want Me to Do This For You?

Tell me about your business and goals. I will suggest the right service and send you a clear, fixed quote.

  • Free 30-minute strategy call
  • Honest advice, even if you need less
  • Fixed quote within 24 hours