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

Use Next.js’s built-in Image component from next/image for most images. For a file in public, pass its root-relative path; for a remote file, allowlist its source in images.remotePatterns. Set dimensions to preserve the image’s aspect ratio, then use CSS and an accurate sizes value to control responsive rendering. The exact loading props depend on your installed Next.js version: the current reference says priority is deprecated starting in Next.js 16.

Use the built-in Image component

The Next.js Image component extends the HTML img element with image optimization behavior. Import it from next/image, provide alternative text, and set dimensions for a basic image.

import Image from 'next/image'

export default function Page() {
  return (
    <main>
      <Image
        src="/photo.jpg"
        alt="A mountain lake at sunrise"
        width={800}
        height={600}
      />
    </main>
  )
}

Put photo.jpg in the project’s public directory. Public assets are addressed from the site root, so the path is /photo.jpg, not /public/photo.jpg. The Next.js Image Component reference covers the current API; the Getting Started: Images guide introduces image use in the Pages Router.

Alternative: import a local image file

Static imports are also supported. They are useful when the asset belongs to the component or page rather than being addressed as a public URL.

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

export default function Page() {
  return <Image src={photo} alt="A mountain lake at sunrise" />
}

For supported static JPG, PNG, WebP, or AVIF imports, Next.js can provide blur data automatically when you use a blur placeholder. Follow the installed version’s reference for the exact import and placeholder behavior.

Choose dimensions or fill based on the layout

The width and height props communicate an image’s intrinsic aspect ratio; they do not, by themselves, dictate its final CSS-rendered size. Providing that ratio lets the browser reserve space and helps prevent layout shift while the image loads. Use the source image’s proportions, then set the rendered dimensions through CSS when the design requires a different display size.

Fixed dimensions

Use width and height when the component should occupy a predictable, intrinsic-ratio box. For example, a 1200-by-800 image has a 3:2 ratio even if CSS renders it smaller.

<Image
  src="/photo.jpg"
  alt="A mountain lake at sunrise"
  width={1200}
  height={800}
  style={{ width: '100%', height: 'auto' }}
/>

Fill a positioned parent

Use fill when the image should cover or fit a container whose size comes from the surrounding layout. The parent must establish a positioned containing block, commonly with position: relative; give the container a meaningful size or aspect ratio as well.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<div style={{ position: 'relative', aspectRatio: '3 / 2' }}>
  <Image
    src="/photo.jpg"
    alt="A mountain lake at sunrise"
    fill
    style={{ objectFit: 'cover' }}
    sizes="(max-width: 768px) 100vw, 50vw"
  />
</div>

objectFit determines how the source fits its box: cover fills the box and may crop; contain shows the whole image and may leave unused space. Choose based on whether the crop is acceptable.

Tell the browser the responsive width

When using fill or CSS that makes an image responsive, provide sizes to describe its expected rendered width at different viewport sizes. Without it, the browser assumes 100vw, which can lead to downloading an unnecessarily large image. This is particularly important for a multi-column layout where a card image occupies only part of the viewport.

<Image
  src="/photo.jpg"
  alt="A mountain lake at sunrise"
  width={1200}
  height={800}
  sizes="(max-width: 768px) 100vw, 50vw"
  style={{ width: '100%', height: 'auto' }}
/>

Make the media conditions and width fractions match the actual CSS layout. If an image is full width on small screens but half-width on larger screens, the example above describes that intent; change it if the page’s columns or breakpoints differ. See the Pages Router Image reference for responsive image guidance.

Configure remote image sources narrowly

For a remote image, pass its absolute URL and allow the intended source through images.remotePatterns in next.config.js. Specify the protocol, hostname, path, and query-string policy that your app needs. Avoid broad patterns: omitted matching fields imply broad wildcards and may allow more URLs than intended. The older domains setting is deprecated in favor of remotePatterns.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
/** @type {import('next').NextConfig} */
const nextConfig = {
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 'images.example.com',
        port: '',
        pathname: '/photos/**',
        search: '',
      },
    ],
  },
}

module.exports = nextConfig

This example permits HTTPS images under /photos/ on images.example.com, with no query string. Adjust the path and query policy deliberately if the image provider uses a different URL shape. After changing Next.js configuration, restart the development server so it reads the updated configuration.

Remote files are not available to Next.js at build time, so provide dimensions yourself. Add blurDataURL too if you want a blur placeholder for a remote or dynamic image.

<Image
  src="https://images.example.com/photos/lake.jpg"
  alt="A mountain lake at sunrise"
  width={1200}
  height={800}
  sizes="(max-width: 768px) 100vw, 50vw"
/>

When optimization is not suitable

The default optimizer does not forward authentication headers when it fetches a source. If fetching the image requires authentication, the official reference says to consider unoptimized. That option is also available for SVGs and animated images that do not benefit from optimization. Enabling SVG optimization requires security precautions; do not turn it on without understanding the associated risks.

Write useful alternative text

The alt prop is required. Write text that can replace the image without changing the meaning of the page. A useful description depends on the image’s role: describe the information a reader would otherwise miss, rather than mechanically listing every visible detail. For a decorative image, use the project’s appropriate empty-alt convention rather than adding noise to screen-reader output.

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.

Next.js explains that “The alt property is used to describe the image for screen readers and search engines.” Use that as an accessibility requirement, not a reason to stuff keywords into descriptions.

Control placeholders and loading

Use blur only when you have blur data

Set placeholder="blur" with a blurDataURL. Supported static imports of JPG, PNG, WebP, or AVIF can receive blur data automatically. For remote or dynamic images, supply the blur data yourself. Keep it small so a placeholder does not add unnecessary page weight.

<Image
  src="https://images.example.com/photos/lake.jpg"
  alt="A mountain lake at sunrise"
  width={1200}
  height={800}
  placeholder="blur"
  blurDataURL="data:image/jpeg;base64,YOUR_SMALL_BLUR_DATA"
/>

Replace the illustrative data value with actual, small blur data; it is not a working image placeholder as written.

Keep lazy loading as the default

The component defaults to lazy loading. Use eager loading only when an image genuinely needs to appear immediately. For an image likely to be the page’s Largest Contentful Paint (LCP) element, consider early loading selectively rather than applying high priority to every image.

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

Check the API for your installed Next.js version before choosing a loading prop. The current reference says priority is deprecated starting in Next.js 16, in favor of preload. The Pages Router reference notes that loading="eager" or fetchPriority="high" is often preferable to preload. These are version- and placement-dependent choices, not interchangeable defaults for every image.

Screenshot a page while checking its images

If you need to inspect how a page renders in a browser, a screenshot can help you spot unexpected sizing, missing images, or layout changes. For example, you can capture a page after changing an image component and compare the result visually. That is separate from rendering images in Next.js: a screenshot tool does not replace the Image component or its source configuration.

Or skip the browser setup

For a screenshot of a page while checking your layout, ScreenshotNeo provides a one-request API. This does not add or configure images in your app; use the Next.js code above for that. ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture. Bot checks, blank pages, and failed loads are not billed; an MCP server gives AI agents tools for taking screenshots. Its free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000 shots.

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 details. Learn more at ScreenshotNeo, or sign up free for 1,000 screenshots a month with no card.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common image problems

The remote image is rejected

Check the URL’s protocol, hostname, path, and query against remotePatterns. A mismatch means the source has not been allowed. Make the pattern match the actual image URL while keeping it as narrow as possible, then restart the development server after configuration changes.

The image causes layout shift

For a remote source, make sure you supplied its actual width and height, or use fill inside a parent with a defined size or aspect ratio. Those dimensions establish the ratio; CSS still controls the rendered size.

The browser downloads an image that is too large

For responsive CSS sizing or fill, check that sizes describes the width the image actually occupies at each breakpoint. If omitted, the browser assumes 100vw; if the value exaggerates the rendered width, it can still select a larger source than the layout needs.

The image does not fit its container

Confirm the parent’s dimensions and positioning when using fill. Then choose an appropriate objectFit rule: cover may crop the image, while contain preserves the entire image but may leave empty space.

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

A protected image cannot be fetched

The default optimizer does not forward authentication headers to the source. For an image requiring authentication, consider unoptimized as described in the official reference, and verify that serving the image directly is appropriate for your app’s security requirements.

The placeholder does not appear

placeholder="blur" needs blur data. Check whether your static import is a supported image type; for remote or dynamic sources, supply blurDataURL yourself.

The loading prop is rejected or ineffective

Check the documentation for the Next.js version installed in the project. In particular, starting with Next.js 16, priority is deprecated in favor of preload; the Pages Router reference also describes eager loading and fetch priority as alternatives often preferable to preload.

Choose the simplest setup that matches the source

  • Local file in public: use a root-relative path and provide dimensions.
  • Bundled local asset: use a static import; supported imports can supply blur data.
  • Remote file: set a narrow remotePatterns rule and provide dimensions.
  • Responsive or container-filling layout: use CSS or fill with accurate sizes.
  • Image needing authentication, or SVG/animation with no optimization benefit: consider unoptimized, with security considerations for SVG.
  • Likely LCP image: evaluate early loading for that image alone, using props appropriate to the installed version.

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.

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.