You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-`loading` - The loading behavior. When `lazy`, defer loading the image until it reaches a calculated distance from the viewport. When `eager`, load the image immediately. Default `lazy`. [More info](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-loading)
49
54
-`priority` - When true, the image will be considered high priority and [preload](https://web.dev/preload-responsive-images/).
50
55
-`unoptimized` - When true, the source image will be served as-is instead of resizing and changing quality.
51
-
-`unsized` - When true, the `width` and `height` requirement can by bypassed. Should _not_ be used with `priority` or above-the-fold images.
56
+
-`unsized` - When true, the `width` and `height` requirement can by bypassed. Should _not_ be used with above-the-fold images. Should _not_ be used with `priority`.
52
57
53
-
Another other properties on the `<Image>` component be passed to the underlying `<img>` element.
58
+
All other properties on the `<Image>` component will be passed to the underlying `<img>` element.
Copy file name to clipboardExpand all lines: docs/basic-features/image-optimization.md
+28-21Lines changed: 28 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
description: Next.js supports built-in image optimization, as well as third party loaders for Imgix, Cloudinary, and more! Learn more here.
3
3
---
4
4
5
-
# Image Optimization
5
+
# Image Component and Image Optimization
6
6
7
7
<detailsopen>
8
8
<summary><b>Examples</b></summary>
@@ -19,7 +19,7 @@ The Automatic Image Optimization allows for resizing, optimizing, and serving im
19
19
20
20
## Image Component
21
21
22
-
To add an image to your application, import the `next/image` component:
22
+
To add an image to your application, import the [`next/image`](/docs/api-reference/next/image.md) component:
23
23
24
24
```jsx
25
25
importImagefrom'next/image'
@@ -31,8 +31,8 @@ function Home() {
31
31
<Image
32
32
src="/me.png"
33
33
alt="Picture of the author"
34
-
width={200}
35
-
height={200}
34
+
width={500}
35
+
height={500}
36
36
/>
37
37
<p>Welcome to my homepage!</p>
38
38
</>
@@ -44,19 +44,32 @@ export default Home
44
44
45
45
-`width` and `height` are required to prevent [Cumulative Layout Shift](https://web.dev/cls/), a [Core Web Vital](https://web.dev/vitals/) that Google is going to [use in their search ranking](https://webmasters.googleblog.com/2020/05/evaluating-page-experience.html)
46
46
-`width` and `height` are automatically responsive, unlike the HTML `<img>` element
47
+
- See [`next/image`](/docs/api-reference/next/image.md) for list of available props.
47
48
48
49
## Configuration
49
50
50
51
You can configure Image Optimization by using the `images` property in `next.config.js`.
51
52
52
-
### Sizes
53
+
### Device Sizes
53
54
54
-
You can specify a list of image widths to allow using the `sizes` property. Since images maintain their aspect ratio using the `width` and `height` attributes of the source image, there is no need to specify height in `next.config.js` – only the width. You can think of these as breakpoints.
55
+
You can specify a list of device width breakpoints using the `deviceSizes` property. Since images maintain their aspect ratio using the `width` and `height` attributes of the source image, there is no need to specify height in `next.config.js` – only the width. These values will be used by the browser to determine which size image should load.
55
56
56
57
```js
57
58
module.exports= {
58
59
images: {
59
-
sizes: [320, 420, 768, 1024, 1200],
60
+
deviceSizes: [320, 420, 768, 1024, 1200],
61
+
},
62
+
}
63
+
```
64
+
65
+
### Icon Sizes
66
+
67
+
You can specify a list of icon image widths using the `iconSizes` property. These widths should be smaller than the smallest value in `deviceSizes`. The purpose is for images that don't scale with the browser window, such as icons or badges. If `iconSizes` is not defined, then `deviceSizes` will be used.
68
+
69
+
```js
70
+
module.exports= {
71
+
images: {
72
+
iconSizes: [16, 32, 64],
60
73
},
61
74
}
62
75
```
@@ -89,25 +102,19 @@ module.exports = {
89
102
90
103
The following Image Optimization cloud providers are supported:
91
104
92
-
- Imgix: `loader: 'imgix'`
93
-
- Cloudinary: `loader: 'cloudinary'`
94
-
- Akamai: `loader: 'akamai'`
95
-
- Vercel: No configuration necessary
105
+
- When using `next start` or a custom server image optimization works automatically.
106
+
-[Vercel](https://vercel.com): Works automatically when you deploy on Vercel
0 commit comments