astro:assets module.
Importing
Image Component
The<Image /> component optimizes images and generates responsive image markup.
Props
ImageMetadata | string
required
Image source. Can be an imported image or a URL string.
string
required
Alternative text for the image. Required for accessibility.
number | string
Desired width of the image. Sets the
width attribute and resizes the image.number | string
Desired height of the image. Sets the
height attribute and resizes the image if width is not provided.'avif' | 'webp' | 'png' | 'jpg' | 'jpeg' | 'svg' | string
Output format for the image.Default:
'webp''low' | 'mid' | 'high' | 'max' | number
Quality preset or numeric value (0-100) for the output image.
(number | `${number}x`)[]
Pixel densities to generate for the image srcset.
number[]
Widths to generate for the image srcset.
'fill' | 'contain' | 'cover' | 'none' | 'scale-down' | string
How the image should be resized to fit the dimensions.Default:
'cover'string
Position of the image when using
fit. Similar to CSS object-position.string
Background color to use when converting transparent images to non-transparent formats.
boolean
Automatically infer width and height from the source image.Default:
true for local imagesHTML Attributes
All standard HTML<img> attributes are also supported:
Example
Picture Component
The<Picture /> component generates a <picture> element with multiple sources and formats.
Props
ImageOutputFormat[]
Array of image formats to generate. The component will create a
<source> for each format.Default: ['webp']ImageOutputFormat
Format to use for the fallback
<img> element.Default: 'png'HTMLAttributes
Attributes to apply to the
<picture> element.Image component are also supported.
Example
getImage
Programmatically get optimized image data without rendering an<img> tag.
ImageTransform
required
Promise<GetImageResult>
Object containing optimized image data.
string
URL of the optimized image.
object
Record<string, any>
HTML attributes for the image (width, height, etc.).
ImageTransform
Processed transformation options.
Example
ImageMetadata Type
Type for imported images.Example
Remote Images
To use remote images, configureimage.domains or image.remotePatterns in your Astro config: