mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 21:55:11 +00:00
f26a801775
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Roe <daniel@roe.dev>
44 lines
1.1 KiB
Markdown
44 lines
1.1 KiB
Markdown
---
|
|
title: "<NuxtImg>"
|
|
description: "Nuxt provides a <NuxtImg> component to handle automatic image optimization."
|
|
links:
|
|
- label: Source
|
|
icon: i-simple-icons-github
|
|
to: https://github.com/nuxt/image/blob/main/src/runtime/components/nuxt-img.ts
|
|
size: xs
|
|
---
|
|
|
|
`<NuxtImg>` is a drop-in replacement for the native `<img>` tag.
|
|
|
|
- Uses built-in provider to optimize local and remote images
|
|
- Converts `src` to provider-optimized URLs
|
|
- Automatically resizes images based on `width` and `height`
|
|
- Generates responsive sizes when providing `sizes` option
|
|
- Supports native lazy loading as well as other `<img>` attributes
|
|
|
|
## Setup
|
|
|
|
In order to use `<NuxtImg>` you should install and enable the Nuxt Image module:
|
|
|
|
```bash [Terminal]
|
|
npx nuxi@latest module add image
|
|
```
|
|
|
|
## Usage
|
|
|
|
`<NuxtImg>` outputs a native `img` tag directly (without any wrapper around it). Use it like you would use the `<img>` tag:
|
|
|
|
```html
|
|
<NuxtImg src="/nuxt-icon.png" />
|
|
```
|
|
|
|
Will result in:
|
|
|
|
```html
|
|
<img src="/nuxt-icon.png" />
|
|
```
|
|
|
|
::read-more{to="https://image.nuxt.com/usage/nuxt-img" target="_blank"}
|
|
Read more about the `<NuxtImg>` component.
|
|
::
|