What are the benefits of using next/image?

next/image improves Core Web Vitals with little effort: smaller files through resizing and modern formats, no layout shift thanks to reserved dimensions, lazy loading for offscreen images, responsive srcset generation, and built-in caching. It also adds security controls over which remote images can be optimized.

Performance

  • Right-sized images: generates multiple widths and lets the browser choose with srcset and sizes, instead of shipping a 4000px photo to a phone.
  • Modern formats: WebP by default, AVIF when enabled in images.formats, chosen from the browser's Accept header.
  • Lazy loading: offscreen images load only near the viewport (loading="lazy" by default).
  • Preloading the LCP image with preload (or fetchPriority="high").
  • Caching: optimized images are cached on the server or CDN with long TTLs.

Visual stability

Width and height (or fill with a sized parent) reserve space, avoiding Cumulative Layout Shift. Blur placeholders improve perceived speed.

Developer experience

  • Static imports provide dimensions and blur data automatically.
  • One component handles responsive art for different breakpoints.
  • Custom loaders plug into Cloudinary, Imgix or any CDN.

Security

  • images.remotePatterns allowlists remote hosts, so your server cannot be abused to optimize arbitrary URLs.
  • Since Next.js 16: local IP addresses are blocked by default (SSRF protection), redirects are limited to 3, and local images with query strings need localPatterns.

Trade-offs

Optimization uses server CPU on first request, and each width/format combination is a cache entry. Limit deviceSizes, imageSizes and qualities to what you need.

Code example

tsx
1// next.config.ts
2import type { NextConfig } from "next";
3
4const nextConfig: NextConfig = {
5 images: {
6 formats: ["image/avif", "image/webp"], // AVIF first when supported
7 remotePatterns: [new URL("https://cdn.acme.com/uploads/**")],
8 qualities: [60, 75, 90], // only these quality values are allowed
9 minimumCacheTTL: 60 * 60 * 24, // 1 day (Next.js 16 default is 4 hours)
10 },
11};
12
13export default nextConfig;
14
15// Usage: the browser picks the right width from srcset
16// <Image src="https://cdn.acme.com/uploads/cover.jpg" alt="Cover" width={1200} height={630}
17// sizes="(max-width: 640px) 100vw, 640px" quality={60} />

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.

Open in study app