October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk8 min

How to Use the Next.js Image Component for Optimized Images

Set up next/image with the right layout, responsive sizing, loading behavior, and safe source configuration for your Next.js version.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Import Image from next/image, provide dimensions or use fill, and describe the image with alt text. For responsive layouts, set sizes to match the rendered width. Keep ordinary offscreen images lazy-loaded, and reserve high priority or preloading for the image most likely to be the page’s Largest Contentful Paint (LCP) element. The examples below follow the Next.js Image Component reference updated March 16, 2026; check your installed Next.js version before using version-sensitive props.

Start with the right image layout

The Next.js Image component extends the HTML <img> element with automatic image optimization. Import it from next/image. Use explicit width and height when the image has known dimensions; use fill when it should size itself to a parent container.

As an Amazon Associate I earn from qualifying purchases.

Known dimensions

For a local image with a defined intrinsic size, provide its source, dimensions, and meaningful alternative text:

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="/images/product.jpg"
      width={1200}
      height={800}
      alt="Blue ceramic mug on a wooden table"
    />
  )
}

Choose dimensions that reflect the image’s intrinsic aspect ratio. The values provide layout information; use CSS to control its displayed size where needed. Write alt text that conveys the image’s relevant content or function. If an image is decorative, use an empty alt value rather than describing irrelevant details.

Fill a parent container

Use fill when the image should cover a container whose dimensions come from the layout. The parent must establish positioning, such as relative, fixed, or absolute. Choose an object-fit rule according to whether cropping is acceptable:

<div className="relative aspect-[16/9]">
  <Image
    src="/images/landscape.jpg"
    alt="Mountain valley beneath a cloudy sky"
    fill
    sizes="100vw"
    style={{ objectFit: 'cover' }}
  />
</div>

cover fills the box and may crop the image; contain preserves the full image and may leave unused space. Give the container a real size, for example with an aspect ratio or explicit height, so the fill image has an area to occupy.

Make responsive image selection match the layout

When an image’s rendered width varies with the viewport, set sizes to describe its expected CSS width. The browser uses that information to choose among the generated srcset candidates. A value that overstates or understates the real layout can lead to an unnecessarily large or too-small candidate.

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

Example: full-width on small screens, one-third width otherwise

<Image
  src="/images/story.jpg"
  alt="A field of sunflowers at sunset"
  width={1600}
  height={1067}
  sizes="(max-width: 768px) 100vw, 33vw"
/>

This expression follows the documented example pattern. Adapt the breakpoint and percentages to the actual CSS layout: a three-column grid, a fixed-width sidebar, and a full-bleed hero do not have the same rendered width. If the image uses fill, include sizes as well when its display width is responsive.

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

Allow only the image sources the app needs

For a remote image, configure an allowlist in next.config.js before rendering it. Restrict the protocol, hostname, pathname and, where relevant, query string to the source URLs your app expects.

/** @type {import('next').NextConfig} */
const nextConfig = {
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 'images.example.com',
        port: '',
        pathname: '/products/**',
        search: '',
      },
    ],
  },
}

module.exports = nextConfig

Replace the example host and path with your real image source. Restart or redeploy the app after changing configuration. A remote URL that does not match the pattern is rejected with a 400 response. Avoid omitting pattern fields casually: omitted fields can act as wildcards and permit a broader set of URLs than intended.

Restrict local paths when useful

You can also use localPatterns to limit which local paths may be optimized. A local source outside the configured pattern receives a 400 response. This is useful when an application has local image routes that should not all be accepted by the optimizer.

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

Use current configuration instead of deprecated options

The domains configuration has been deprecated since Next.js 14 in favor of remotePatterns. Unlike a narrowly defined pattern, domains cannot limit protocol, port, or pathname. Check the API reference for the configuration syntax supported by your installed version.

Choose lazy loading, eager loading, or preload deliberately

Images are lazy-loaded by default. That suits many images below the fold because the browser can defer fetching them until they are near the viewport. For an image that must load promptly, consider eager loading or fetchPriority="high". These are selective controls, not defaults to apply to every image.

Preload only the likely LCP image

If a single above-the-fold image is likely to be the page’s LCP element, preloading it may be appropriate. Do not preload several competing images, or combine preload with loading or fetchPriority on the same image. In Next.js 16, priority is deprecated in favor of preload; for example:

<Image
  src="/images/home-hero.jpg"
  alt="A family walking along a beach"
  width={1800}
  height={1000}
  sizes="100vw"
  preload
/>

For versions before Next.js 16, consult the documentation for the supported prop rather than copying a newer example unchanged. Decide based on the page’s actual content and framework version, not simply because an image appears near the top.

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

Add a blur placeholder only when you have suitable data

To show a blur-up placeholder, set placeholder="blur" and provide blurDataURL. Supported static JPG, PNG, WebP, or AVIF imports can provide blur data automatically unless the image is animated. Remote and dynamically sourced images need a manually supplied blur data URL.

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
<Image
  src="https://images.example.com/products/mug.jpg"
  alt="Blue ceramic mug"
  width={900}
  height={900}
  placeholder="blur"
  blurDataURL="data:image/jpeg;base64,..."
/>

Replace the shortened example value with a real, small blur data URL; it is not usable as written. Large embedded blur data can add unnecessary payload. If you do not have appropriate blur data, omit the placeholder rather than inventing one.

Know when the built-in optimizer is not the right delivery path

Authenticated image sources

The built-in optimizer does not forward request headers when fetching an image source. If the origin requires authentication, the optimizer may not be able to retrieve it. The Next.js documentation suggests considering unoptimized for such sources, but assess the delivery architecture before applying that prop broadly: it bypasses the normal optimization path.

SVG sources

SVG is not optimized by default. For a known SVG source, the documentation recommends considering unoptimized. If you enable SVG serving, the docs also recommend attachment disposition and a restrictive content security policy. Review the security implications and your version’s configuration guidance before enabling it.

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

Custom delivery and quality settings

A custom loader or loaderFile can generate URLs for a separate image CDN or transformation service when that delivery architecture fits your app. The official reference describes the integration point but does not establish a particular provider as best. The documented quality range is 1–100, and configured allowlists can constrain permitted values; check current requirements for your Next.js version rather than assuming any value is accepted.

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

Troubleshoot common problems

  • Remote image returns 400: Check that its protocol, hostname, port, pathname and query string match a remotePatterns entry exactly. Add only the scope the app needs.
  • Local image returns 400: If using localPatterns, confirm the requested path matches an allowed pattern.
  • Fill image has no visible size: Give its parent positioning and a definite layout area, such as an aspect ratio or height. Check that the image is not hidden or covered by other layout elements.
  • Responsive image downloads an unexpectedly large candidate: Compare the actual CSS width at each breakpoint with the sizes expression. Correct the expression to describe the rendered slot, not the source file’s dimensions.
  • Authenticated remote image cannot be fetched: The optimizer does not forward source authentication headers. Consider a delivery path that does not rely on forwarded headers, including unoptimized where appropriate.
  • SVG handling differs from raster images: SVG is not optimized by default. Use unoptimized for a known SVG source, or review the documented security controls before enabling SVG serving.
  • Blur placeholder is missing or fails: Confirm that remote or dynamic images have a valid blurDataURL; do not assume they receive one automatically.
  • A prop example fails in your project: Check the installed Next.js version. In particular, Next.js 16 deprecates priority in favor of preload, and older configuration such as domains has been deprecated since Next.js 14.

Performance, reliability, and cost considerations

Use dimensions or a sized fill container to make layout behavior predictable, and give responsive images accurate sizes so the browser can select an appropriate candidate. Avoid preloading multiple images without a clear reason. The API reference documents a default optimization response-body limit of 50 MB; this is a technical limit, not a performance benchmark. Actual delivery behavior depends on the app’s configuration, source images, deployment and browser.

For browser-level checks of a page you control, inspect the rendered result at the viewport sizes relevant to your layout and verify that the chosen source, crop and loading behavior match expectations. ScreenshotNeo is a separate website screenshot API and MCP server, not part of the Next.js Image component; it can capture pages for visual checks.

Or skip the browser setup

For a screenshot of a published page, ScreenshotNeo takes a URL in one request. This returns a WebP screenshot in the example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. ScreenshotNeo accepts cookie and consent banners 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 cost nothing, and responses identify the page verdict and billing status in headers. Its MCP server offers take_screenshot, get_page_info and capture_pdf for AI agents. The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots. See ScreenshotNeo and sign up free.

FAQ

What happens if I leave out sizes?

The browser has less information about the image’s expected rendered width when selecting a responsive candidate. Add a value that describes the layout whenever the displayed width is responsive.

Can I use fill without positioning the parent?

No. The parent needs positioning such as relative, fixed, or absolute, as well as a layout area for the image to fill.

Do blur placeholders work automatically for remote images?

No. Remote and dynamic images need a manually supplied blurDataURL; supported static imports can provide one automatically in the documented cases.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

Official reference

Next.js Image Component API reference (updated March 16, 2026).

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.