Next.js image optimisation: a practical guide
Use next/image with the right sizes value, load the hero image eagerly, allow only your image hosts, and compress originals. Next.js 16 examples.
By Sohail Hussain20 November 20265 min read
To optimise images in Next.js, use the next/image component for every content image, give it its dimensions, set a sizes value that matches how wide it is on screen, and mark the one image that is the Largest Contentful Paint element to load eagerly with high priority. Next.js then serves each visitor a resized WebP at the right width, lazy-loads everything below the fold, and reserves space so nothing jumps. Most of the gains people miss come from sizes and the hero image, not from the format.
The examples below are for the App Router in Next.js 16, current as of October 2026. Version 16 changed several image defaults, which are covered at the end.
What does next/image do for you?
The component wraps a normal <img> and adds four things:
- Resizing. It generates a
srcsetof widths from your config, and the browser downloads the smallest one that fits. - Modern formats. It converts to WebP by default, based on what the browser says it accepts. AVIF is one config line away.
- Lazy loading. Images load only when they approach the viewport, using the browser's native
loading="lazy". - No layout shift. The
widthandheightset the aspect ratio, so the browser reserves the space before the file arrives.
Images are a common reason pages fail Core Web Vitals, which is why we treat them as part of technical SEO and performance rather than a design detail. Optimised images are also one of the reasons we give in why we build company websites with Next.js.
How do you set width, height and sizes correctly?
There are three ways to give Next.js the dimensions.
Static import. Next.js reads the width and height from the file and generates a blur placeholder you can switch on with placeholder="blur". Use this for images that live in the repository.
Explicit width and height. For CMS or remote images, pass the original dimensions, which most CMS APIs return. They set the aspect ratio, not the rendered size; CSS controls that.
fill. The image fills its parent, which must have position: relative and a size. Use it when the aspect ratio is set by the layout, such as a card with a fixed-ratio frame.
Then set sizes whenever the image is not a fixed pixel width. It tells the browser how wide the image will be at each breakpoint, so it can pick the right file from the srcset. For a three-column card grid:
<Image
src={project.image.url}
alt={project.image.alt}
width={project.image.width}
height={project.image.height}
sizes="(min-width: 1024px) 33vw, (min-width: 640px) 50vw, 100vw"
/>
Without sizes, a fill image is treated as full viewport width, so a phone with a high-density screen downloads a file several times larger than the card needs. On a fixed-width image without sizes, Next.js generates only 1x and 2x versions, which is right for logos and avatars and wrong for anything responsive. Our srcset generator shows the markup that a given sizes value produces, which helps when you are working out breakpoints.
How should the hero image be loaded?
Every next/image is lazy by default. That is correct for most images and wrong for the hero, which is usually the page's Largest Contentful Paint element. Lazy-loading it delays the moment the main content appears.
Load it eagerly and ask for high priority:
import Image from "next/image";
import hero from "./hero.jpg";
export function Hero() {
return (
<Image
src={hero}
alt="Engineers inspecting a pump assembly on the factory floor"
sizes="100vw"
loading="eager"
fetchPriority="high"
style={{ width: "100%", height: "auto" }}
/>
);
}
In Next.js 16 the old priority prop is deprecated. Its replacement, preload, inserts a <link rel="preload"> in the head, but the Image component docs say that in most cases loading="eager" or fetchPriority="high" is the better choice. Use preload only when the image is discovered late in the page and you are sure it is the LCP element on every screen size.
Mark one image per page this way, two at most. If everything is high priority, nothing is. How to fix a poor LCP score covers the other causes of a slow hero.
What should go in next.config.ts?
Three settings matter for most sites:
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
images: {
formats: ["image/avif", "image/webp"],
qualities: [60, 75],
remotePatterns: [new URL("https://images.example-cms.com/your-project/**")],
},
};
export default nextConfig;
remotePatterns lists the hosts Next.js may fetch and optimise. Anything else gets a 400 error. Make the pattern as narrow as your CMS allows, down to a project path, so nobody can use your optimiser for their own images.
qualities is an allowlist, and in Next.js 16 it defaults to [75]. A quality={60} prop on an image is coerced to the nearest allowed value unless 60 is in the list.
formats controls the output. WebP is the default. Adding AVIF first means browsers that accept it get AVIF, at the cost of slower first encodes and two cached copies of every size. We enable it on image-heavy pages and leave it off elsewhere.
Which mistakes undo the optimisation?
Huge originals. Next.js resizes on request, but it still downloads the original from the source, and the first visitor waits for that. Upload images at no more than twice their largest display width and compress them first. Our image compressor does this in the browser without uploading anything.
CSS background images. A hero set with background-image bypasses next/image entirely: no resizing, no modern format, and the browser finds it late. Use an <Image fill> with object-fit: cover behind the content instead.
Optimising SVGs and icons. SVGs are vectors and gain nothing from resizing. Next.js serves .svg sources unoptimised automatically. For tiny PNG icons, unoptimized avoids a pointless round trip through the optimiser.
Forgetting alt text. The alt prop is required. Describe what the image shows for someone who cannot see it, or use alt="" for decorative images. Image SEO covers alt text and file naming for search.
What changed for images in Next.js 16?
If you are upgrading an older site, check these:
| Change in Next.js 16 | What to do |
|---|---|
priority deprecated | Use loading="eager" with fetchPriority="high", or preload |
qualities defaults to [75] | Add any other quality values you use |
minimumCacheTTL default raised from 60 seconds to 4 hours | Lower it only if source images change in place often |
16 removed from default imageSizes | Add it back only if you serve 16-pixel images |
Local images with query strings need localPatterns | Add a pattern with the exact search value |
| Remote redirects limited to 3 by default | Point src at the final URL |
On Vercel, image optimisation is metered, so a site with thousands of product images can see it on the bill. If your images already come from a CDN that resizes through URL parameters, a custom loaderFile that builds those URLs avoids paying twice. For a small company site, the defaults are fine and cost little or nothing.
Was this guide useful?