---
title: "Image"
description: "A picture that keeps its box before it loads, shows a placeholder, fades in, and shows a fallback on an error. Lazy by default, with a srcset from a loader."
url: https://gelatinui.com/components/image
markdown_url: https://gelatinui.com/components/image.md
access: free
install: "npx shadcn@latest add @gelatin-ui/image"
registry_item: https://gelatinui.com/r/image.json
version: "2026-11-08"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Image

> A picture that keeps its box before it loads, shows a placeholder, fades in, and shows a fallback on an error. Lazy by default, with a srcset from a loader.

Page: https://gelatinui.com/components/image

## When to use it

Best for: A content picture that keeps its box before it loads, with a placeholder and a fallback.

- Use it for the pictures in your content: a card photo, a hero, a gallery tile.
- Give it a box: `width` and `height`, an aspect class, or `fill` in a positioned parent. The box keeps its size before the file loads, so the page does not shift.
- Set `preload` on a picture above the fold, such as a hero. Other pictures load lazily.
- Use `loader` or `transformer` for an image CDN, so the browser picks the right width from the srcset.
- Put `ImageLoaderProvider` around the app to set one loader for every Image, as Next.js `images.loader` does. A loader that returns `undefined` leaves that file as it is.
- Put an `ImageFallback` in the Image for your own error text.

## When not to use it

- For pictures that people move through one at a time, use a [Carousel](https://gelatinui.com/components/carousel.md).

## Notes for agents

- Always give it a box (`width` and `height`, an aspect class, or `fill`), so the page does not shift.
- It loads lazily by default; set `preload` only on a picture above the fold.

## Anatomy

```text
Image
└─ ImageFallback (0..n)
```

## API reference

### Image

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `alt` | `string` |  | Required: say what the picture shows. `""` for a picture that only decorates. |
| `fit` | `"contain" \| "cover"` |  |  |
| `rounded` | `"default" \| "full"` |  |  |
| `src` | `string \| Blob` |  | The file: an address, or a `Blob` (a `File` a person dropped, shown through an object URL that is freed with the file). With no `src`, the box shows the fallback at once and loads nothing. |
| `srcSet` | `string` |  | A ready `srcset` for `src` ("a-640.jpg 640w, a-1280.jpg 1280w"), with `sizes`: for files that a server already made at each width. It wins over `loader` and `transformer`. Change it together with `src`: the old picture keeps only its `src` while the new one loads. |
| `width` | `number` |  | The width of the box in px. With `height`, it sets the box ratio before the file loads. |
| `height` | `number` |  |  |
| `fill` | `boolean` | false | Fill the positioned parent (`absolute inset-0`). Give the parent a size. |
| `sizes` | `string` |  | The `sizes` of the srcset: how wide the box is per screen ("(max-width: 640px) 100vw, 33vw"). |
| `loader` | `ImageLoader` |  | Makes the URL of each srcset width, Next.js style. Default: the loader of the nearest `ImageLoaderProvider` (none outside one). |
| `transformer` | `ImageTransformer` |  | An Unpic provider transformer, an alternative to `loader`. |
| `quality` | `number` |  | The quality that `loader` and `transformer` get (1–100). |
| `preload` | `boolean` | false | A picture above the fold (a hero): loads at once with a high fetch priority, and React preloads it (`<link rel="preload">` with the srcset). Default `false`: lazy. |
| `placeholder` | `ImagePlaceholderKind \| ReactElement` | "muted" | What shows while the file loads: `muted` (default, the muted box), `skeleton` (the box with a shimmer band), `blur` (`blurDataURL`, blurred), `color` (`placeholderColor`), `none` (no fill, also on an error: the parent shows), or an element: your own layer under the file until its fade ends (a sharp thumbnail of the same picture). |
| `blurDataURL` | `string` |  | A tiny copy of the picture (10px or less, a data URL) for `placeholder="blur"`. |
| `placeholderColor` | `string` |  | The main color of the picture for `placeholder="color"` (a data color). |
| `position` | `string` |  | The CSS `object-position` of the picture in the box ("top", "30% 60%"). |
| `fade` | `boolean` | true | Fade the file in when it loads. Default `true`. A file the page already loaded, or a server file, shows at once. |
| `onLoadingStatusChange` | `function` |  | Called with the new status: `idle`, `loading`, `loaded`, `error`. |
| `onLoad` | `function` |  |  |
| `onError` | `function` |  |  |
| `className` | `string` |  | The classes of the box (size, corners, ratio). |
| `imgClassName` | `string` |  | The classes of the `<img>`. |
| `style` | `CSSProperties` |  |  |
| `children` | `ReactNode` |  | An `ImageFallback` for the error and the no-`src` box. Default: an icon (none for `alt=""`). With a child, the root is not `role="img"`: the fallback speaks for itself, and an img role would hide its words and controls (a retry button) from screen readers. |

### ImageFallback

No props of its own: `className`, `children`, and every other prop go to the element it renders.

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| Image | `image` | `data-pending` |  |  |
| ImageFallback | `image-fallback` |  |  |  |

## Usage

Give every Image an `alt` and a box. With no `src`, or when the file fails, the box shows the fallback, never the broken picture of the browser.

```tsx title="stay-card.tsx"
import { Image, ImageFallback } from "@/components/ui/image";

export function StayCard({ title, photo }: { title: string; photo?: string }) {
  return (
    <article className="overflow-clip rounded-xl border">
      <Image src={photo} alt={title} className="aspect-3/2 w-full rounded-none">
        <ImageFallback>Photo not available</ImageFallback>
      </Image>
      <p className="p-3 text-sm font-medium">{title}</p>
    </article>
  );
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui/image
```

It adds 14 registry items: 13 files, 2161 lines, and the npm packages `@mantine/hooks`, `@phosphor-icons/react`, `@unpic/core`, `@xstate/react`, `clsx`, `tailwind-merge`, `tailwind-variants`, `xstate`.

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Carousel](https://gelatinui.com/components/carousel.md)
- [Skeleton](https://gelatinui.com/components/skeleton.md)
- [Avatar](https://gelatinui.com/components/avatar.md)

## Accessibility

The `alt` prop is required. Say what the picture shows, or pass `alt=""` for a picture that only decorates.

On an error or with no `src`, the box keeps its size and shows an icon. The box then has `role="img"`, and `alt` names it. A decorative picture (`alt=""`) shows the empty box only.

With an `ImageFallback` child, the box has no img role: the fallback text and controls speak for themselves, so a screen reader reads them.

Image is not a control. It has no hover, press, or focus look. To make a picture a control, put it in a link or a button.

## Motion

| Part | Motion |
| --- | --- |
| Fade in | fade · 150ms · ease-out (0, 0, 0.2, 1) · the file fades from 0 to 1 over the placeholder or the old picture |
| Skeleton | shimmer · 2s · linear · repeats · a band of light moves across the box while the file loads |
| Cached file | none · a file the page already loaded, or a server file, shows at once |
