This loads the full-size image, no optimization:
Problems: Large file size, blocks rendering, no format optimization
This is automatically optimized:
Benefits: Resized, converted to WebP, lazy loaded, responsive!
src Image source (local import or URL string)
alt Alt text (required for accessibility!)
width & height Dimensions in pixels. Required to prevent layout shift!
quality 0-100. Default is 80. Lower = smaller file, less quality.
loading "lazy" (default) loads when visible. "eager" loads immediately.
format Output format: "webp" (default), "avif", "png", "jpg"
For images you own, put them in your project and import:
---
import { Image } from 'astro:assets';
import myImage from '../assets/photo.jpg';
---
<Image src={myImage} alt="My photo" width={800} height={600} /> Astro optimizes these at build time = super fast!
For external URLs (Unsplash, CDNs, etc.), just use the URL:
<Image
src="https://example.com/image.jpg"
alt="Remote image"
width={800}
height={600}
/> Astro optimizes these on-demand when requested.
<Image> for hero images, portfolio pieces, thumbnails<img> only for:
When you use <Image>:
dist/_astro/