# Nuxt Image Reference
**Last Updated:** 2025-11
**Check:** `@nuxt/image` in package.json
Nuxt Image is an image optimization module that provides automatic image optimization, lazy loading, responsive images, and support for multiple image providers.
## Installation & Setup
```bash
pnpm add @nuxt/image
```
**nuxt.config.ts:**
```typescript
export default defineNuxtConfig({
modules: ["@nuxt/image"],
image: {
// Optional configuration
quality: 80,
formats: ["webp", "avif"],
// Image providers
providers: {
cloudinary: {
baseURL: "https://res.cloudinary.com/{your-cloud-name}/image/upload/",
},
},
},
})
```
## Core Components
### NuxtImg
Basic optimized image component:
```vue
```
**Common Props:**
- `src` - Image source (path or URL)
- `alt` - Alt text for accessibility
- `width` / `height` - Dimensions
- `loading` - `"lazy"` (default) or `"eager"`
- `fit` - `"cover"`, `"contain"`, `"fill"`, `"inside"`, `"outside"`
- `format` - `"webp"`, `"avif"`, `"jpg"`, `"png"`
- `quality` - Image quality (0-100)
- `provider` - Image provider to use
### NuxtPicture
Responsive image with multiple formats:
```vue
```
**Benefits:**
- Automatically generates multiple formats (WebP, AVIF)
- Creates responsive srcset for different screen sizes
- Better browser compatibility with fallbacks
## Common Patterns
### Responsive Images
```vue
```
### Image with Loading States
```vue
```
### Background Images
```vue
Content
```
### Image with Different Formats
```vue
```
### Fit Options
```vue
```
## Image Providers
### Local Provider (Default)
For images in `public/` directory:
```vue
```
### External URLs
```vue
```
### Cloudinary
```typescript
// nuxt.config.ts
export default defineNuxtConfig({
image: {
cloudinary: {
baseURL: "https://res.cloudinary.com/{your-cloud-name}/image/upload/",
},
},
})
```
```vue
```
### Vercel / Netlify
Automatically detected and configured when deployed:
```typescript
// nuxt.config.ts
export default defineNuxtConfig({
image: {
provider: "vercel", // or 'netlify'
},
})
```
### Custom Provider
```typescript
// nuxt.config.ts
export default defineNuxtConfig({
image: {
providers: {
custom: {
provider: "~/providers/custom-provider.ts",
options: {
baseURL: "https://cdn.example.com",
},
},
},
},
})
```
```typescript
// providers/custom-provider.ts
import { joinURL } from "ufo"
import type { ProviderGetImage } from "@nuxt/image"
export const getImage: ProviderGetImage = (src, { modifiers, baseURL }) => {
const { width, height, format, quality } = modifiers
const url = joinURL(baseURL, src)
return {
url: `${url}?w=${width}&h=${height}&fm=${format}&q=${quality}`,
}
}
```
## Composables
### $img Helper
Generate image URLs programmatically:
```vue
Content
```
## Performance Optimization
### Lazy Loading (Default)
Images are lazy-loaded by default:
```vue
```
### Preload Critical Images
```vue
```
### Placeholder / Blur
```vue
```
### Image Sizes
Specify responsive sizes for optimal loading:
```vue
```
## Advanced Usage
### Modifiers Object
Pass multiple modifiers:
```vue
```
### Dynamic Sources
```vue
```
### Image Gallery
```vue
```
### Art Direction
Different images for different screen sizes:
```vue
```
## Configuration Reference
### Global Configuration
```typescript
// nuxt.config.ts
export default defineNuxtConfig({
image: {
// Default quality
quality: 80,
// Default formats
formats: ["webp", "avif", "jpg"],
// Image sizes for responsive images
screens: {
xs: 320,
sm: 640,
md: 768,
lg: 1024,
xl: 1280,
xxl: 1536,
"2xl": 1536,
},
// Provider configuration
provider: "cloudinary",
providers: {
cloudinary: {
baseURL: "https://res.cloudinary.com/{cloud-name}/image/upload/",
},
},
// IPX options (local provider)
ipx: {
maxAge: 60 * 60 * 24 * 365, // 1 year cache
},
// Presets
presets: {
avatar: {
modifiers: {
format: "webp",
width: 100,
height: 100,
fit: "cover",
},
},
thumbnail: {
modifiers: {
format: "webp",
width: 300,
height: 200,
fit: "cover",
},
},
},
},
})
```
### Using Presets
```vue
```
## Best Practices
1. **Always include alt text** - Essential for accessibility
2. **Use NuxtPicture for hero images** - Better format support and responsiveness
3. **Specify dimensions** - Prevents layout shift
4. **Lazy load by default** - Except above-the-fold images
5. **Use appropriate fit** - `cover` for thumbnails, `contain` for products
6. **Optimize quality** - 80-85 is usually sufficient
7. **Leverage providers** - Use CDN providers for external images
8. **Use presets** - Define common image styles once
9. **Test on slow networks** - Verify lazy loading and placeholders work
10. **Prefer WebP/AVIF** - Modern formats for better compression
## Troubleshooting
### Images Not Optimizing
Check:
1. `@nuxt/image` is in `nuxt.config.ts` modules
2. Images are in `public/` directory for local provider
3. Provider is correctly configured
4. Development server was restarted after config changes
### Images Not Loading
1. Verify src path is correct
2. Check provider baseURL configuration
3. Ensure CORS is configured for external images
4. Check network tab for 404/403 errors
### Poor Performance
1. Enable lazy loading (default)
2. Use appropriate image sizes
3. Implement placeholders
4. Use WebP/AVIF formats
5. Configure CDN caching
### Layout Shift
Always specify width and height:
```vue
```
## Official Resources
- **Documentation:** https://image.nuxt.com
- **Providers:** https://image.nuxt.com/providers
- **API Reference:** https://image.nuxt.com/api
- **GitHub:** https://github.com/nuxt/image
---
**Note:** Always verify provider-specific features with official documentation. Image optimization strategies may vary by provider.