GitHub

uiImage

Responsive image component. Supports aspect-ratio cropping with object-fit: cover, optional caption, and rounded corners. Always uses loading="lazy" and decoding="async".

With aspect ratio

Set ratio to constrain the image to a fixed aspect ratio. The image fills the crop area with object-fit: cover.

Mountain landscape at dusk
uiImage({ src: '/img/photo.jpg', alt: 'Mountain landscape at dusk', ratio: '16/9' })

Square and rounded

Profile photo
uiImage({ src: '/img/avatar.jpg', alt: 'Profile photo', ratio: '1/1', rounded: true })

With caption

Aerial view of a coastal town
Aerial view of Porto, Portugal. Photo by João Silva.
uiImage({
  src:     '/img/photo.jpg',
  alt:     'Aerial view of a coastal town',
  ratio:   '4/3',
  caption: 'Aerial view of Porto, Portugal. Photo by João Silva.',
})
PropTypeDefault
srcstringImage source URL
altstringAlt text — required for accessibility
captionstringRenders a <figcaption> below the image
ratiostringCSS aspect-ratio string e.g. '16/9', '4/3', '1/1'. When set, the image fills the crop area with object-fit: cover.
roundedbooleanfalseApplies full border-radius to the image wrap
widthnumberSets the width attribute on the <img>
heightnumberSets the height attribute on the <img>
classstring