Image

A styled-system <img> primitive. Accepts all layout, space, background, and position props from the theme, plus objectFit / objectPosition for common image sizing patterns and borderRadius for rounded corners.

Built-in source priority and error recovery: when a source fails to load the component advances to the next URL automatically. onError fires only when all sources are exhausted.

Source priority

Initial render - props map to <img> attributes as follows:

  • srcsrc attribute.
  • srcSetsrcset attribute (used alongside src, or as the primary source when src is absent).
  • fallbacksrc attribute when both src and srcSet are absent.

Error recovery - when the browser fails to load, the component advances through phases:

src + srcSet  →  src (srcSet dropped)  →  fallback  →  onError
src only      →  fallback              →  onError
srcSet only   →  fallback              →  onError

onError fires only after all sources are exhausted.


Examples

Default

Soroush logo
<Image
  src="/soroush.svg"
  alt="Soroush logo"
  width="200px"
  height="200px"
  objectFit="contain"
/>

Cover

Cover
<Image
  src="/soroush.svg"
  alt="Cover"
  width="300px"
  height="200px"
  objectFit="cover"
/>

With Fallback

With fallback
<Image
  src="broken.jpg"
  alt="With fallback"
  fallback="/soroush.svg"
  width="200px"
  height="200px"
  objectFit="contain"
/>

Object Fit Variants

cover

cover

contain

contain

fill

fill

none

none

scale-down

scale-down

<div style={{ display: 'flex', gap: '16px', flexWrap: 'wrap' }}>
  {objectFitTokens.map((fit) => (
    <div key={fit} style={{ textAlign: 'center' }}>
      <Image src={DEMO_IMG} alt={fit} width="150px" height="120px" objectFit={fit} />
      <p style={{ fontSize: '12px', margin: '4px 0 0' }}>{fit}</p>
    </div>
  ))}
</div>

Image API reference