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.

Mountain landscape
constrained
---
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.

Mountain range
full-width
---
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.

Portrait
fixed
---
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.

Landscape
responsive
---
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.

Portrait orientation
contained
---
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.

Wide landscape
cover
---
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.

Forced 16:9 ratio
aspect-ratio
---
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.

Hero image
eager
---
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

PropTypeDefaultDescription
srcstring | ImageMetadata | null—Image source — a local ImageMetadata import or a remote/relative URL string; resolved via findImage before rendering
widthstring | number | null—Rendered image width in pixels; numeric strings are parsed with parseInt before use
heightstring | number | null—Rendered image height in pixels; numeric strings are parsed with parseInt before use
altstring | 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
stylestring—Extra inline CSS appended after the layout-generated styles
srcsetstring | null—Explicit srcset value; overrides the automatically generated responsive srcset when provided
sizesstring | 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
layoutLayout—Responsive layout mode used to compute wrapper alignment classes and generated sizing styles
widthsnumber[] | null—Custom breakpoint widths (in px) used to build the responsive srcset
aspectRatiostring | number | null—Forces an aspect ratio (e.g. '16:9' or a number) used to derive a missing width or height
objectPositionstring—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)
formatstring—Target output image format (e.g. 'webp') requested from the image optimizer