Skip to main content

Image

Image is an enhanced img element with loading states, error fallback, and object-fit options.

Open in Storybook

Import

import { Image } from "@tosui/react";

Basic Usage

Object Fit

Control how the image fits within its container.

Cover
cover
Contain
contain
Fill
fill

Rounded Variants

None
Small
Medium
Large
Full

Loading State

Image shows a skeleton placeholder while loading.

<Image
src="https://picsum.photos/300/200"
alt="Loading example"
w="300px"
h="200px"
/>

Fallback Image

Provide a fallbackSrc to show if the main image fails to load.

<Image
src="https://broken-url.example/image.jpg"
fallbackSrc="https://via.placeholder.com/300x200"
alt="With fallback"
w="300px"
h="200px"
/>

Error State

If both the main image and fallback fail, a placeholder icon is shown.

<Image
src="https://broken-url.example/image.jpg"
alt="Broken image"
w="300px"
h="200px"
/>

Common Patterns

<Box
position="relative"
cursor="pointer"
overflow="hidden"
rounded="md"
>
<Image
src="/gallery/photo.jpg"
alt="Gallery item"
w="100%"
h="200px"
objectFit="cover"
/>
</Box>

Product Image

<Card>
<Image
src="/product.jpg"
alt="Product"
w="100%"
h="250px"
objectFit="contain"
/>
<CardBody>
<Text fontWeight="medium">Product Name</Text>
<Text color="foreground-muted">$99.99</Text>
</CardBody>
</Card>

Props Reference

PropTypeDefaultDescription
srcstring-Image source URL (required)
altstring-Alt text (required)
wstring-Width (CSS value)
hstring-Height (CSS value)
objectFit"cover" | "contain" | "fill" | "none""cover"Object fit behavior
fallbackSrcstring-Fallback image URL
rounded"none" | "sm" | "md" | "lg" | "full""none"Border radius

Accessibility

  • alt prop is required for accessibility
  • Error placeholder has appropriate styling

TypeScript

import { Image, type ImageObjectFit, type ImageProps } from "@tosui/react";