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
srcsetandsizes, instead of shipping a 4000px photo to a phone. - Modern formats: WebP by default, AVIF when enabled in
images.formats, chosen from the browser'sAcceptheader. - Lazy loading: offscreen images load only near the viewport (
loading="lazy"by default). - Preloading the LCP image with
preload(orfetchPriority="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.remotePatternsallowlists 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
1// next.config.ts2import type { NextConfig } from "next";34const nextConfig: NextConfig = {5 images: {6 formats: ["image/avif", "image/webp"], // AVIF first when supported7 remotePatterns: [new URL("https://cdn.acme.com/uploads/**")],8 qualities: [60, 75, 90], // only these quality values are allowed9 minimumCacheTTL: 60 * 60 * 24, // 1 day (Next.js 16 default is 4 hours)10 },11};1213export default nextConfig;1415// Usage: the browser picks the right width from srcset16// <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.