Image Components
Astro provides two built-in components for optimized images:<Image />- Optimizes a single image and transforms dimensions, file type, and quality<Picture />- Generates multiple formats and sizes for responsive images
Where to Store Images
src/ (recommended): Store local images here for automatic optimization and bundling.
public/: For images you want served as-is without processing. Accessible via public URL paths.
Remote: Store in a CMS or CDN and reference via full URL.
Using the Image Component
Import and use the<Image /> component for optimized images:
Image Paths
- Local images in
src/: Import from relative path - Public images: Use URL path relative to
public/ - Remote images: Use full URL
Generated Output
The<Image /> component generates optimized HTML:
Using the Picture Component
Generate multiple formats with<Picture />:
Responsive Images
Make images responsive with layout properties:Generated Responsive Output
Configure Global Responsive Images
Set default behavior inastro.config.mjs:
Images in Markdown
Use standard Markdown syntax:Images in MDX
MDX supports both components and Markdown syntax:SVG Components
Import SVG files as Astro components:SVG Type Safety
Unprocessed Images with <img>
Use the HTML <img> tag for complete control without optimization:
Local Images
Public Images
Remote Images
Images from CMS or CDN
Use full URLs with Astro image components:CldImage component).
Authorizing Remote Images
Protect your site by configuring allowed image sources:Images in Content Collections
Declare images in frontmatter:image() helper:
Generating Images with getImage()
For advanced use cases, usegetImage() to generate images programmatically:
Default Image Service
Astro uses Sharp for image optimization by default. You may need to install it manually with strict package managers:No-op Passthrough Service
For adapters that don’t support optimization:Image Caching
Processed images are cached in./node_modules/.astro/ (configurable via cacheDir).
Remote images respect HTTP caching headers and support revalidation using Last-Modified and ETag headers.
Alt Text
Always provide descriptive alt text for accessibility:alt attribute is required for <Image /> and <Picture /> components.