# <Image> (Local)

> Optimizing static images and preventing layout shift.

Subject: Next.js | Lesson 47 of 65 | 4 min read
Interactive lesson: https://codewithanimation.in/nextjs/image-local
Previous: [NextRequest & NextResponse](https://codewithanimation.in/nextjs/web-request-response.md) | Next: [<Image> (Remote)](https://codewithanimation.in/nextjs/image-remote.md)

## The <Image> Component

The Next.js `<Image>` component is an extension of the standard HTML `<img>` tag.

It automatically optimizes images by converting them to modern formats (like WebP or AVIF), resizing them for different devices, and preventing Cumulative Layout Shift (CLS).

## Cumulative Layout Shift (CLS)

When a standard `<img>` loads, the browser doesn't know its dimensions until the file finishes downloading. This causes the text below the image to suddenly jump down the page.

This jump is called Cumulative Layout Shift, and it heavily penalizes your Google Lighthouse SEO score.

`<Image>` fixes this by reserving the exact layout space before the image even loads.

## Local Imports

To use a local image, you statically import it: `import profilePic from './me.png';`

Then pass the imported object to the component: `<Image src={profilePic} alt="Me" />`.

Next.js automatically determines the `width` and `height` from the imported file, so you don't have to specify them manually.

## Common mistake: The Blur Placeholder

For local images, you can instantly improve perceived performance by adding `placeholder="blur"`.

Because Next.js analyzes the local file at build time, it automatically generates a tiny, low-resolution blurred version of the image and embeds it directly into the HTML to show while the full image loads.

## Try it: The CLS Simulator

Compare a standard HTML `<img>` against a Next.js `<Image>`. Trigger a slow network load to see how the standard image causes text to jump, while Next.js reserves the space and provides a blur placeholder.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/nextjs/image-local

## Check yourself

### Question 1

Why don't you need to provide `width` and `height` props when using a statically imported local image?

- A. Because CSS automatically handles it.
- B. Because Next.js inspects the local file at build time and extracts the dimensions.
- C. Because `<Image>` defaults to 100x100.
- D. Because the browser calculates it.

Correct answer: B

When you `import` an image, Next.js reads the actual file during the build process to determine its exact width, height, and generate a blur placeholder.

- Why not A: CSS can scale it, but Next.js needs raw dimensions to reserve space.
- Why not C: It extracts the true dimensions.
- Why not D: If we waited for the browser, we would get Layout Shift.

## Remember this

- `<Image>` prevents Cumulative Layout Shift (CLS).
- It automatically converts images to smaller formats like WebP.
- Statically importing local images automatically sets `width` and `height`.
- Use `placeholder="blur"` for automatic blurred loading states.
