Get StartedComponentsStylingThemingMath & Science
MCP

Basics

Image

Displays an image. Renders a native img, defaults to object-fit: cover, and accepts every style prop.

Nothing extra happens by default. Lazy loading, a loading placeholder and an error placeholder are all opt-in.

Markdown

Import

tsx
import { Image } from "@indoku/ui"

Examples

Basic

Mountain landscape

Height

Use the height prop to change the height of the image.

Sunset landscape

Circular

Combine boxSize and borderRadius="full" for a round image.

Round avatar

Aspect ratio

Use the aspectRatio prop to change the aspect ratio of the image.

Landscape in 4:3

Fit

By default the image applies object-fit: cover. Use fit to change it.

fit cover

cover

fit contain

contain

fit fill

fill

Align

Use align to set object-position when the image is cropped.

align top

top

align center

center

align bottom

bottom

HTML width and height

htmlWidth and htmlHeight set the native width and height attributes, while width and height are style props.

Square with native size

As child

Use asChild to apply the image styles to a single child, such as a framework image component.

Rendered through asChild

Lazy loading

Not lazy by default. Add the native loading="lazy" so the browser downloads the image only when it is near the viewport.

Loaded only when near the viewport

Loading placeholder

fallback is shown until the image has loaded. Give the image a size (w/h, boxSize or aspectRatio) so the placeholder has room. This demo delays the source to simulate a slow network.

Slow image

Error placeholder

When the image fails to load (404, bad URL, blocked), a built-in icon placeholder is shown. Replace it with errorFallback. Using errorFallback alone adds no loading placeholder.

Missing image

default error icon

Missing image

custom errorFallback

Responsive sources

Native srcSet and sizes let the browser pick the smallest file that fits the layout.

Responsive image

Props

Image

PropTypeDefaultDescription
fitCSSProperties['objectFit']'cover'Maps to object-fit.
alignCSSProperties['objectPosition']–Maps to object-position.
htmlWidthstring | number–Native width attribute. Use width for the CSS property.
htmlHeightstring | number–Native height attribute. Use height for the CSS property.
asChildbooleanfalseRender the single child element with the image props and styles instead of an img. fallback and errorFallback are ignored.
fallbackReactNode–Shown until the image has loaded. Setting it wraps the image in a frame.
errorFallbackReactNode–Replaces the built-in error icon. Setting it (or fallback) enables the error placeholder.

* required. Style props and HTML attributes are accepted as well.

Accessibility

  • Always set alt. Use alt="" for purely decorative images.
  • The loading placeholder is hidden from assistive tech. The error placeholder is exposed as an image labelled with alt.
  • Set htmlWidth and htmlHeight (or aspectRatio) to reserve space and avoid layout shift while loading.

Notes

  • All native img attributes are forwarded, including loading, decoding, srcSet, sizes, onLoad and onError.
  • With fallback or errorFallback, size and style props apply to a wrapping span frame, and fit, ref and native attributes stay on the img. Without them there is no wrapper.
  • Image optimization (smaller files in WebP or AVIF) happens at build time or on a CDN, not in this component. Use srcSet and sizes for responsive files, and wrap with <picture> and <source type="image/webp"> to offer modern formats with a fallback.
  • The Provider preflight already sets display: block, max-width: 100% and height: auto on images.

Created by @indokudev