The Next.js Image component helps you show pictures on your website faster and clearer. It automatically makes images smaller and loads them smartly so your site feels quick and smooth.
Image component and optimization in NextJS
import Image from 'next/image'; <Image src="/path/to/image.jpg" alt="Description of image" width={widthInPixels} height={heightInPixels} priority={trueOrFalse} placeholder="blur" blurDataURL="data:image..." />
The src can be a local file path or an external URL if configured.
You must provide width and height to help Next.js optimize the image size.
import Image from 'next/image'; <Image src="/logo.png" alt="Company Logo" width={200} height={100} />
next.config.js).import Image from 'next/image'; <Image src="https://example.com/photo.jpg" alt="Sample Photo" width={600} height={400} />
import Image from 'next/image'; <Image src="/portrait.jpg" alt="Portrait" width={300} height={400} placeholder="blur" blurDataURL="data:image/jpeg;base64,..." />
import Image from 'next/image'; <Image src="/hero.jpg" alt="Hero Image" width={1200} height={600} priority={true} />
This component shows a heading and an optimized image with a blur placeholder. The image is sized to 600x400 pixels and loads smoothly.
import Image from 'next/image'; export default function HomePage() { return ( <main style={{ maxWidth: '600px', margin: 'auto', padding: '1rem' }}> <h1>Welcome to Our Site</h1> <Image src="/nature.jpg" alt="Beautiful nature scene" width={600} height={400} placeholder="blur" blurDataURL="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD..." /> <p>This image loads with a nice blur effect and is optimized for fast loading.</p> </main> ); }
Always add meaningful alt text for accessibility so screen readers can describe the image.
Next.js automatically serves images in modern formats like WebP when supported by the browser.
Use the priority prop sparingly for images that must load immediately, like logos or hero images.
The Next.js Image component makes images load faster and look better automatically.
Provide src, alt, width, and height for best results.
Use features like blur placeholders and priority loading to improve user experience.