网页
综合
更新时间 2026-04-01 00:00:00
Image Optimization
自动蜘蛛
nextjs.org
正文约 2088 字
The Next.js <Image> component extends the HTML <img> element to provide:
To start using <Image>, import it from next/image and render it within your component.
The src property can be a local or remote image.
Learn more about how to use next/image → YouTube (9 minutes).
You can store static files, like images and fonts, under a folder called public in the root directory. Files inside public can then be referenced by your code starting from the base URL (/).
If the image is statically imported, Next.js will automatically determine the intrinsic width and height. These values are used to determine the image ratio and prevent Cumulative Layout Shift while your image is loading.
If you can't use a static import for your images, you can use a dynamic import() in a Server Component to still get automatic width, height, and blurDataURL:
If you have a path alias configured (e.g. @/), you can use it instead of a relative path:
The path must include a static prefix (like ../content/blog/images/). Be as specific as possible, since all files matching that prefix are bundled. Only files in your specified directory are included, so external input cannot reach outside of it.
To use a remote image, you can provide a URL string for the src property.
Since Next.js does not have access to remote files during the build process, you'll need to provide the width, height and optional blurDataURL props manually. The width and height are used to infer the correct aspect ratio of image and avoid layout shift from the image loading in. Alternatively, you can use the fill property to make the image fill the size of the parent element.
To safely allow images from remote servers, you need to define a list of supported URL patterns in next.config.js. Be as specific as possible to prevent malicious usage. For example, the following configuration will only allow images from a specific AWS S3 bucket:
See the API Reference for the full feature set of Next.js Image.
Last updated April 1, 2026
Subscribe to our newsletter
Stay updated on new releases and features, guides, and case studies.
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。