Next.jsEasy
What is the Next.js Image component?
next/image exports an <Image> component that extends <img> with automatic optimization: it resizes images on demand, serves modern formats such as WebP or AVIF, lazy-loads by default, reserves space to prevent layout shift, and generates a responsive srcset.
Required and key props
src: a static import (import hero from "./hero.jpg"), a path inpublic/, or a remote URL allowed byimages.remotePatterns.alt: required for accessibility; use""for decorative images.width/height: required for remote andpublic/images (not for static imports), unless you usefill.fill: stretch to the parent, which must be positioned; combine withsizesandobject-fit.sizes: tells the browser how wide the image will display, so it downloads the right size.preload: preload a critical image (the LCP image). Replaces thepriorityprop, deprecated in Next.js 16.placeholder="blur": automatic for static imports; remote images needblurDataURL.quality: must be listed inimages.qualities(default only[75]since Next.js 16).loading,fetchPriority,unoptimized,loader.
How optimization works
The browser requests /_next/image?url=...&w=828&q=75. The server resizes and encodes the image (using sharp), caches it, and serves it with caching headers. minimumCacheTTL defaults to 4 hours since Next.js 16.
Without the default optimizer
With output: 'export' or a CDN-based pipeline, set a custom loader (Cloudinary, Imgix, your CDN) or unoptimized: true.
Code example
tsx
1// app/page.tsx2import Image from "next/image";3import hero from "./hero.jpg"; // static import: width, height and blur known at build45export default function Home() {6 return (7 <main>8 {/* LCP image: preload it */}9 <Image src={hero} alt="Team at work" placeholder="blur" preload sizes="100vw" />1011 {/* Remote image: needs width/height and remotePatterns */}12 <Image13 src="https://images.example.com/products/42.jpg"14 alt="Blue running shoe"15 width={600}16 height={400}17 sizes="(max-width: 768px) 100vw, 50vw"18 />1920 {/* Fill a sized container */}21 <div className="relative aspect-video">22 <Image src="/banner.webp" alt="" fill className="object-cover" sizes="100vw" />23 </div>24 </main>25 );26}
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.