Next.js Image Component: Sizes, Preload and Remote Images

Import Image from next/image and give it src, alt, and either width and height or fill. Add a sizes string whenever the rendered width changes with the screen, so the browser downloads a smaller file. For the hero image that is your LCP, set preload (it replaced priority in Next.js 16). Allow external hosts with images.remotePatterns.

The props that decide speed
PropDefaultUse it when
width / heightnoneThe image has a fixed size, or you want the aspect ratio reserved
fillfalseThe parent box decides the size (cards, heroes, covers)
sizesbrowser assumes 100vwThe image is responsive or uses fill
preloadfalseThe image is the above-the-fold LCP element
loadinglazySet eager only for images that must load straight away
quality75Only values listed in images.qualities are served

Updated

Two image mistakes are easy to make in Next.js: a fill image with no sizes, so phones download desktop files, and a hero that waits for lazy loading. This page explains each prop in plain words, gives you a calculator that writes the sizes string for your layout, and lists the config defaults Next.js uses today.

Sizes calculator

Choose a layout and breakpoints to generate the sizes attribute, then see which default srcset width a given screen is likely to download.

Default candidate widths: 32, 48, 64, 96, 128, 256, 384, 640, 750, 828, 1080, 1200, 1920, 2048, 3840. Browsers may choose differently, for example when a larger file is already cached.

Every prop you are likely to use

next/image props (Next.js 16 reference)
PropTypeWhat it does
srcstring or static importLocal path in public, imported file, or an external URL allowed by remotePatterns
altstringRequired text alternative; use an empty string only for decorative images
width, heightinteger (px)Intrinsic size used for the aspect ratio; not needed for static imports or fill
fillbooleanStretch to the positioned parent instead of using width and height
sizesstringMedia conditions and slot widths that drive srcset selection
qualityinteger 1 to 100Output quality, default 75, snapped to the images.qualities list
preloadbooleanAdds a preload link in the head for the LCP image
loadinglazy or eagerDefaults to lazy
placeholderempty, blur or data URLWhat shows while loading; blur needs blurDataURL unless the image is a static import
unoptimizedbooleanServe the source file as is, without resizing or format changes
prioritybooleanDeprecated in Next.js 16; use preload instead

Image config defaults

images settings in next.config and their defaults
SettingDefaultNotes
deviceSizes640, 750, 828, 1080, 1200, 1920, 2048, 3840Widths for full-width and fill images
imageSizes32, 48, 64, 96, 128, 256, 384Extra small widths, only used when the image has a sizes prop
qualities75Required allowlist from Next.js 16
minimumCacheTTL14400 (4 hours)The larger of this and the upstream Cache-Control wins
remotePatternsnoneEach external host must be listed

Copyable examples

Hero image from a static import

The import gives Next.js the real dimensions and a blur placeholder. preload starts the download from the head.

import Image from "next/image";
import hero from "./hero.jpg";

export default function Hero() {
  return (
    <Image
      src={hero}
      alt="Bakery counter with fresh loaves"
      placeholder="blur"
      preload
      sizes="100vw"
      style={{ width: "100%", height: "auto" }}
    />
  );
}

Card grid with fill and sizes

Each card is a third of the page on desktop, half on tablets and full width on phones, and the sizes value says exactly that.

<div style={{ position: "relative", aspectRatio: "4 / 3" }}>
  <Image
    src={product.photoUrl}
    alt={product.name}
    fill
    sizes="(max-width: 640px) 100vw, (max-width: 1024px) 50vw, 33vw"
    style={{ objectFit: "cover" }}
  />
</div>

next.config.ts for a remote image host

Only HTTPS files under /uploads/ on one host are allowed. Two quality values are permitted.

import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  images: {
    remotePatterns: [
      { protocol: "https", hostname: "cdn.example.com", pathname: "/uploads/**" },
    ],
    qualities: [60, 75],
    formats: ["image/avif", "image/webp"],
  },
};

export default nextConfig;

Why the component exists

A plain img tag sends one file to every device. next/image resizes the source on request, converts it to a modern format the browser accepts, lazy loads it by default and reserves the space so the layout does not jump while it arrives.

The catch is that it can only pick a sensible file when it knows how wide the image will be. That is the job of width, height and sizes, and it is where most real-world mistakes happen.

Getting LCP right

Largest Contentful Paint is often a hero photo. Lazy loading that photo delays the metric, so mark it with preload, or with loading="eager" plus fetchPriority="high", and leave every image below the fold on the lazy default.

Pair that with an honest sizes value. A hero that spans the full width on phones but only half the page on desktop should say so, otherwise large screens and small screens both get the wrong file.

Config you will touch

remotePatterns lists the outside hosts you trust. qualities is an allowlist of quality values and is required from Next.js 16, and the docs default it to 75. formats lets you add AVIF ahead of WebP, at the cost of storing both versions in the cache.

deviceSizes and imageSizes together make up the candidate widths in every srcset. You rarely need to change them, but knowing the defaults helps you read what the browser downloaded in the network panel.

How it works

  1. Pick the layout your image sits in, such as full width, a two column split or a three card grid.
  2. Set the breakpoints your CSS uses. The calculator writes the matching sizes value.
  3. Choose a phone width and pixel density to see which default srcset width the browser would most likely fetch.
  4. Copy the finished Image element and paste it into your component.

Tips

Frequently asked questions

Is the priority prop deprecated?

Yes. From Next.js 16 the docs mark priority as deprecated in favour of preload, which inserts a preload link in the head. The docs also say that in most cases loading="eager" or fetchPriority="high" is the better choice, and preload should not be combined with either of those props.

Why does next/image say the hostname is not configured?

External images must match an entry in images.remotePatterns in next.config. Add an object with protocol, hostname and a pathname such as /photos/**, then restart the dev server. Requests that match no pattern get a 400 response from the image optimizer.

What does the sizes prop actually change?

It tells the browser how wide the image will be at each breakpoint before CSS loads. With sizes, Next.js also emits a full width-based srcset (640w, 750w and so on) instead of only 1x and 2x, so a phone can pick a far smaller file.

Do I need width and height with fill?

No. fill and width/height are alternatives. With fill the image stretches to its positioned parent, and you control cropping with object-fit through the style or className prop.

How long are optimized images cached?

The default minimumCacheTTL is 14400 seconds, which is four hours. The real max age is whichever is larger: that value or the Cache-Control header sent by the original image. Statically imported images get long-lived immutable caching because their file names are hashed.

Related: Website image sizes guide, Optimize images for the web, HTML images, srcset and sizes, Image compressor, Next.js proxy (middleware) examples.

Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.

More in Guides

We.Inc is an AI-powered website builder you can resell under your own brand. Launch a branded client dashboard, bill on Stripe Connect, and deliver AI-generated websites in minutes. White-label plans start at $99 a month for 25 client sites, with a 7-day free trial and no per-site fees.

Product

Who It's For

Features

Resources

Company

View Sitemap