Primitives
Image
An optimized image with sizing, ratio, and fit controls.
Demonstrating responsive image optimization with srcset, lazy loading, and multiple layout modes.
Constrained layout (default)
Image scales down to fit container but never exceeds its natural size. Perfect for content images.
---
import ImageBlock from '@alfadormx/blocks/primitives/Image.astro';
---
<ImageBlock
src="https://images.unsplash.com/photo-1506905925346-21bda4d32df4"
alt="Mountain landscape"
width={800}
height={600}
layout="constrained"
/>Full width layout
Image always spans 100% of container width. Ideal for hero images and banners.
---
import ImageBlock from '@alfadormx/blocks/primitives/Image.astro';
---
<ImageBlock
src="https://images.unsplash.com/photo-1506905925346-21bda4d32df4"
alt="Mountain range"
width={1200}
height={400}
layout="fullWidth"
/>Fixed layout
Image maintains exact dimensions regardless of screen size. Good for thumbnails and avatars.
---
import ImageBlock from '@alfadormx/blocks/primitives/Image.astro';
---
<ImageBlock
src="https://images.unsplash.com/photo-1506905925346-21bda4d32df4"
alt="Portrait"
width={200}
height={200}
layout="fixed"
/>Responsive layout
Width is 100%, height scales automatically. Maintains aspect ratio perfectly.
---
import ImageBlock from '@alfadormx/blocks/primitives/Image.astro';
---
<div class="max-w-2xl">
<ImageBlock
src="https://images.unsplash.com/photo-1506905925346-21bda4d32df4"
alt="Landscape"
width={1000}
height={667}
layout="responsive"
/>
</div>Contained layout
Image fits within container using object-fit: contain. No cropping, maintains full visibility.
---
import ImageBlock from '@alfadormx/blocks/primitives/Image.astro';
---
<div class="h-96 bg-surface">
<ImageBlock
src="https://images.unsplash.com/photo-1506905925346-21bda4d32df4"
alt="Portrait orientation"
width={600}
height={900}
layout="contained"
/>
</div>Cover layout
Image covers container completely using object-fit: cover. May crop to fit.
---
import ImageBlock from '@alfadormx/blocks/primitives/Image.astro';
---
<div class="h-96 bg-surface">
<ImageBlock
src="https://images.unsplash.com/photo-1506905925346-21bda4d32df4"
alt="Wide landscape"
width={1200}
height={800}
layout="cover"
/>
</div>Custom aspect ratio
Force specific aspect ratio (16:9) regardless of source image dimensions.
---
import ImageBlock from '@alfadormx/blocks/primitives/Image.astro';
---
<div class="max-w-4xl">
<ImageBlock
src="https://images.unsplash.com/photo-1506905925346-21bda4d32df4"
alt="Forced 16:9 ratio"
width={1200}
aspectRatio="16:9"
layout="responsive"
/>
</div>Eager loading (above fold)
Load immediately without lazy loading. Use for hero images and LCP elements.
---
import ImageBlock from '@alfadormx/blocks/primitives/Image.astro';
---
<ImageBlock
src="https://images.unsplash.com/photo-1506905925346-21bda4d32df4"
alt="Hero image"
width={1200}
height={600}
layout="fullWidth"
loading="eager"
fetchpriority="high"
/>API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
| src | string | ImageMetadata | null | — | Image source — a local ImageMetadata import or a remote/relative URL string; resolved via findImage before rendering |
| width | string | number | null | — | Rendered image width in pixels; numeric strings are parsed with parseInt before use |
| height | string | number | null | — | Rendered image height in pixels; numeric strings are parsed with parseInt before use |
| alt | string | null | — | Accessible alternative text; required at runtime — the component throws if it is undefined or null |
| loading | 'eager' | 'lazy' | null | — | Native img loading strategy; falls back to 'lazy' when not set |
| decoding | 'sync' | 'async' | 'auto' | null | — | Native img decoding hint; falls back to 'async' when not set |
| style | string | — | Extra inline CSS appended after the layout-generated styles |
| srcset | string | null | — | Explicit srcset value; overrides the automatically generated responsive srcset when provided |
| sizes | string | null | — | Explicit sizes attribute; auto-computed from width and layout when left unset |
| fetchpriority | 'high' | 'low' | 'auto' | null | — | Native fetchpriority hint forwarded to the rendered img element |
| layout | Layout | — | Responsive layout mode used to compute wrapper alignment classes and generated sizing styles |
| widths | number[] | null | — | Custom breakpoint widths (in px) used to build the responsive srcset |
| aspectRatio | string | number | null | — | Forces an aspect ratio (e.g. '16:9' or a number) used to derive a missing width or height |
| objectPosition | string | — | CSS object-position value applied to the generated image styles |
| align | 'left' | 'center' | 'right' | — | Horizontal alignment of the image within its wrapper (left, center, or right) |
| format | string | — | Target output image format (e.g. 'webp') requested from the image optimizer |