Skip to content

Image

Display images with preview and fallback support.

import { Image } from 'asterui'

Basic Image

Simple image display with src and alt props.

Landscape
import { Image } from 'asterui'

function App() {
  return (
      <Image
        src="/valley.png"
        alt="Landscape"
        width={400}
        height={300}
      />
    )
}

export default App

Different Sizes

Images with various dimensions.

Small
Medium
Large
import { Image, Space } from 'asterui'

function App() {
  return (
      <Space direction="horizontal" size="md" align="center">
        <Image
          src="/valley.png"
          alt="Small"
          width={100}
          height={100}
        />
        <Image
          src="/valley.png"
          alt="Medium"
          width={200}
          height={150}
        />
        <Image
          src="/valley.png"
          alt="Large"
          width={300}
          height={200}
        />
      </Space>
    )
}

export default App

Image Preview

Click image to preview in full size.

Landscape with preview
import { Image } from 'asterui'

function App() {
  return (
      <Image
        src="/valley.png"
        alt="Landscape with preview"
        width={400}
        height={300}
        preview
      />
    )
}

export default App

Fallback Image

Display fallback image when source fails to load.

Broken image
import { Image, Space } from 'asterui'

function App() {
  return (
      <Space direction="horizontal" size="md">
        <Image
          src="/does-not-exist.png"
          alt="Broken image"
          width={200}
          height={150}
          fallback="/valley.png"
        />
      </Space>
    )
}

export default App
PropertyDescriptionTypeDefault
srcImage source URLstring-
altAlternative text for the imagestring''
widthImage widthnumber | string-
heightImage heightnumber | string-
previewEnable click to preview image in lightboxbooleantrue
fallbackFallback image URL when source fails to loadstring-
placeholderPlaceholder content shown while loadingReact.ReactNode-
onLoadCallback when image loads successfully() => void-
onErrorCallback when image fails to load() => void-
classNameAdditional CSS classesstring-
styleInline stylesReact.CSSProperties-
  • Always provide meaningful alt text for screen readers
  • Use fallback images to ensure content is always visible
  • Preview is keyboard accessible: press Enter or Space to open, Escape to close
  • Previewable images have role="button" with appropriate aria-label
  • Preview modal has role="dialog" and aria-modal="true"
  • Error state includes aria-label describing the failure