Skip to content

docs: Reference to statically imported images #80048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions docs/01-app/01-getting-started/04-images.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,41 @@ export default function Page() {
<Image
src="/profile.png"
alt="Picture of the author"
width={500}
height={500}
/>
)
}
```

```jsx filename="app/page.js" switcher
import Image from 'next/image'

export default function Page() {
return (
<Image
src="/profile.png"
alt="Picture of the author"
width={500}
height={500}
/>
)
}
```

### Statically imported images

You can also import and use local image files. Next.js will automatically determine the intrinsic [`width`](/docs/app/api-reference/components/image#width-and-height) and [`height`](/docs/app/api-reference/components/image#width-and-height) of your image based on the imported file. These values are used to determine the image ratio and prevent [Cumulative Layout Shift](https://web.dev/articles/cls) while your image is loading.

```tsx filename="app/page.tsx" switcher
import Image from 'next/image'
import ProfileImage from './profile.png'

export default function Page() {
return (
<Image
src={ProfileImage}
alt="Picture of the author"
// width={500} automatically provided
// height={500} automatically provided
// blurDataURL="data:..." automatically provided
Expand All @@ -69,11 +104,12 @@ export default function Page() {

```jsx filename="app/page.js" switcher
import Image from 'next/image'
import ProfileImage from './profile.png'

export default function Page() {
return (
<Image
src="/profile.png"
src={ProfileImage}
alt="Picture of the author"
// width={500} automatically provided
// height={500} automatically provided
Expand All @@ -84,7 +120,7 @@ export default function Page() {
}
```

When using local images, Next.js will automatically determine the intrinsic [`width`](/docs/app/api-reference/components/image#width-and-height) and [`height`](/docs/app/api-reference/components/image#width-and-height) of your image based on the imported file. These values are used to determine the image ratio and prevent [Cumulative Layout Shift](https://web.dev/articles/cls) while your image is loading.
In this case, Next.js expects the `app/profile.png` file to be available.

## Remote images

Expand Down
Loading