Optimizing images
next/image extends the HTML <img> element with automatic optimization:
correctly sized images per device, modern formats like WebP, lazy loading, and
protection against layout shift.
Import Image from next/image and render it:
import Image from 'next/image';
export default function Page() {
return <Image src="/profile.png" alt="Picture of the author" width={500} height={500} />;
}
A local image lives under public/ and is referenced by a path. If you
import it statically, Next.js infers width, height, and a blur placeholder
for you. A remote image needs width and height — to reserve the right
aspect ratio — or the fill prop, and its host must be allowed in
next.config.ts under images.remotePatterns.
For responsive images, pass sizes so the browser downloads the smallest image
that fits, for example sizes="(max-width: 768px) 100vw, 33vw". fill makes the
image stretch to its positioned parent.
In short: use next/image for local and remote images, supply dimensions or
fill, and set sizes to avoid oversized downloads.
You are about to answer a short quiz on next/image.