Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To configure Next.js image sizes, use width and height for the image’s intrinsic dimensions, CSS for its rendered dimensions, and sizes to tell the browser how wide a responsive image will appear. In next.config.js, adjust deviceSizes and imageSizes only when their candidate widths do not fit your site’s layouts. The key is to make sizes describe the image’s actual CSS width—not simply its source file dimensions.

What Next.js image sizes control

The Next.js Image component extends the HTML <img> element for automatic image optimization. (Next.js Image Component documentation.) Its size-related settings work at different stages, so changing a configuration array is not the first fix for every oversized download.

  • width and height describe intrinsic source dimensions and let the browser reserve the correct aspect-ratio space. They do not dictate the final CSS-rendered width.
  • sizes describes the image’s expected rendered width at different viewport widths. The browser uses that hint to select a candidate from the generated srcset.
  • deviceSizes and imageSizes define width candidates available to the Next.js image optimizer.
  • CSS controls the image’s actual display size and, for responsive layouts, should agree with sizes.

These controls are related but not interchangeable. A correct sizes value cannot fix a layout whose CSS is wrong, and changing deviceSizes does not accurately describe how wide a particular image appears on the page.

Choose the right Image component pattern

Known intrinsic dimensions

For a file with known dimensions, pass its intrinsic pixel width and height. Use CSS to set its display size while preserving its aspect ratio. For example, an image that is 1200 by 800 pixels can be rendered narrower without changing the source dimensions:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import Image from 'next/image'

export default function ProductPhoto() {
  return (
    <Image
      src="/product.jpg"
      alt="A product on a table"
      width={1200}
      height={800}
      style={{ width: '100%', height: 'auto' }}
    />
  )
}

The dimensions let the browser determine the aspect ratio before the image loads, helping reserve layout space and reduce layout shift. The CSS declaration controls the rendered width.

Static imports

When you statically import an image file, Next.js can derive its width and height from the imported asset. This is useful for local images with known dimensions. CSS still determines the rendered size. For example:

import Image from 'next/image'
import productPhoto from './product.jpg'

export default function ProductPhoto() {
  return (
    <Image
      src={productPhoto}
      alt="A product on a table"
      style={{ width: '100%', height: 'auto' }}
    />
  )
}

Remote or dynamic URLs

For a remote image URL or a path selected at runtime, provide width and height so Next.js can calculate its aspect ratio. The dimensions describe the source image, not necessarily the display width. Follow the Next.js Image documentation for any additional source configuration required by your version and image-host setup.

Parent-controlled image boxes with fill

Use fill when the parent controls the image box or the intrinsic aspect ratio is not available. The parent must establish the containing box and be positioned. Supply sizes when the image is responsive:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import Image from 'next/image'

export default function Hero() {
  return (
    <div style={{ position: 'relative', width: '100%', height: 420 }}>
      <Image
        src="/hero.jpg"
        alt="A landscape at sunset"
        fill
        sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
        style={{ objectFit: 'cover' }}
      />
    </div>
  )
}

The example says the image is full viewport width up to 768 pixels, half the viewport width up to 1200 pixels, and one third of the viewport width above that. Those values are only correct if they match the actual layout. If the hero is full width at every size, use an expression that says so.

Responsive CSS-width images

If CSS changes an image’s width at breakpoints, add a sizes expression that mirrors those breakpoints and width rules. Keep its height automatic to preserve the aspect ratio. For example, if cards occupy the full viewport below 640 pixels, half the viewport from 640 through 999 pixels, and one third above 1000 pixels, a matching hint could be:

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
sizes="(max-width: 639px) 100vw, (max-width: 999px) 50vw, 33vw"

Use the width the image actually occupies, accounting for the layout’s columns and any relevant page gutters. Do not copy this sample expression unless those proportions describe your CSS.

Write a sizes value that matches the layout

The sizes prop is a browser hint, written as a comma-separated list of media conditions and expected slot widths, followed by a fallback width. It is not a CSS declaration and does not set the image’s width. CSS sets the width; sizes tells the browser what width to expect at each viewport range.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Find the image’s rendered width in your page layout at each relevant breakpoint.
  2. Express those widths as viewport-based values or fixed lengths, in the same order as the corresponding media conditions.
  3. End with the width that applies when none of the earlier conditions match.
  4. Compare the hint with the CSS and adjust it whenever the layout changes.

For a two-column layout that switches to one column on narrow screens, for example, a reasonable starting expression might be (max-width: 768px) 100vw, 50vw. If the content has substantial side padding or a maximum-width container, the image may be narrower than those proportions; reflect that in the hint rather than treating viewport width as content width.

If sizes is omitted, the browser assumes 100vw. For an image that actually occupies only a fraction of the viewport, that assumption can lead the browser to download a larger candidate than necessary. With sizes, Next.js generates a fuller width-based srcset; without it, width generation is limited and is better suited to fixed-size images. (See the Next.js Image documentation.)

Configure deviceSizes and imageSizes

Most projects can begin with the documented defaults. Change the arrays in next.config.js when your audience’s viewport widths or your layouts require candidate widths that are not covered well by those defaults. The lists below are the defaults documented by Next.js in 2026; check the documentation for the Next.js version used by your project before relying on them.

Option What it provides Documented default
deviceSizes Width candidates for images sized relative to the viewport, including responsive or full-width layouts. [640, 750, 828, 1080, 1200, 1920, 2048, 3840]
imageSizes Smaller width candidates for images that provide a sizes prop. [32, 48, 64, 96, 128, 256, 384]

Every imageSizes value should be smaller than the smallest deviceSizes value. These arrays describe the optimizer’s available candidate widths; they are not a list of rendered widths for each component.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Example configuration

In a CommonJS-style next.config.js, the arrays can be set under images:

/** @type {import('next').NextConfig} */
const nextConfig = {
  images: {
    deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
    imageSizes: [32, 48, 64, 96, 128, 256, 384],
  },
}

module.exports = nextConfig

This example explicitly repeats the documented defaults, so it does not alter the default behavior. To customize it, replace values based on the widths your site actually serves. If your configuration file uses another supported module format, preserve that format rather than pasting CommonJS syntax into it.

When to change the arrays

  • Consider adjusting deviceSizes when your site’s common viewport-driven image widths fall between candidates or the default range does not reflect the viewports you target.
  • Consider adjusting imageSizes for smaller card, thumbnail, or other sub-viewport image widths when those images use sizes.
  • Keep all imageSizes entries below the smallest deviceSizes entry.
  • Do not add many arbitrary values in the hope of fixing a component-specific hint. First check the component’s CSS and sizes.

Changing candidates affects what widths can be generated; it does not tell the browser which width the image occupies. That remains the job of a correct sizes value.

Diagnose an image download that is too large

When a page downloads an image larger than expected, inspect the component and its layout before changing global configuration. A practical diagnostic order is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Check the image’s actual rendered width at the viewport where the problem occurs.
  2. Check whether CSS makes that width responsive, including through a parent container or grid.
  3. If it is responsive, verify that sizes describes that width at the same breakpoints.
  4. If the image has no sizes, remember the browser assumes 100vw; add a hint that matches its layout.
  5. Inspect the generated srcset and the candidate selected by the browser. A candidate can be wider than the rendered slot because the browser selects from available widths.
  6. Only then review deviceSizes and imageSizes to see whether their candidate ranges suit the site.

For example, a card image that occupies one third of a desktop viewport but omits sizes may be treated as viewport-wide for candidate selection. Adding an accurate expression such as (max-width: 700px) 100vw, 33vw can communicate the card’s changing slot width. The exact breakpoints and fractions must come from your layout.

Performance, reliability, and cost considerations

Correct size hints help the browser request a candidate better matched to the rendered slot, but there is no universal download reduction percentage: the result depends on the layout, viewport, candidate widths, and browser selection. The cited Next.js documentation does not establish a named performance benchmark. Avoid treating the largest configured width as a recommended output size for every image.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

For layout stability, supply intrinsic dimensions where required or use fill with a properly defined parent box. For selection accuracy, match sizes to responsive CSS. For optimizer coverage, ensure the configured arrays include useful widths for the layouts you serve. These solve distinct problems and should be checked separately.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common problems and fixes

The browser downloads a width close to the whole viewport

Likely cause: A responsive image has no sizes, so the browser assumes 100vw, or its hint overstates the slot width.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Fix: Add or correct sizes using the image’s true layout width at each breakpoint.

The image is stretched or has the wrong proportions

Likely cause: The rendered CSS width and height do not preserve the source aspect ratio, or the parent box used with fill is not the intended shape.

Fix: For dimension-based images, use a responsive width with height: auto. For fill, size the parent intentionally and use an appropriate fit rule such as objectFit where needed.

The image causes layout movement while loading

Likely cause: The browser was not given the image’s aspect ratio in advance.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Fix: Provide intrinsic width and height, use dimensions derived by a static import, or define a stable parent box when using fill.

A configured candidate width is not being selected

Likely cause: The browser’s expected slot width, device pixel ratio, available generated candidates, and configured arrays do not line up with the expectation. The browser chooses from candidates; it is not required to request a width identical to the CSS width.

Fix: Inspect the rendered width, sizes, and generated srcset. Adjust the arrays only if the candidate range itself is unsuitable.

A small image has no useful small candidate

Likely cause: A sub-viewport image needs smaller candidates and does not have a suitable sizes hint, or the relevant widths are absent from imageSizes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Fix: Add an accurate sizes prop for the responsive image and review imageSizes, keeping every entry below the smallest deviceSizes entry.

Or skip the browser setup

If your task is to capture a page as an image or PDF rather than configure Next.js’s own image optimizer, ScreenshotNeo provides a website screenshot API and MCP server. A single GET request can return a PNG, JPEG, WebP, or PDF. See the ScreenshotNeo API documentation for request options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses include X-Page-Verdict and X-Billed headers. Its MCP server includes take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for ScreenshotNeo’s free plan.

FAQ

Do deviceSizes and imageSizes control the CSS width?

No. CSS controls the rendered width. The arrays define optimizer candidate widths, while sizes describes the expected slot width to help the browser choose among candidates.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Should every Next.js Image use sizes?

Use sizes when CSS or fill makes the image responsive. It is especially important when the image occupies less than the full viewport.

Should I change the default width arrays?

Not automatically. Start with the documented defaults and customize them only when your layouts’ candidate-width needs are not well covered.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.