# Image

A picture in a box that keeps its shape while it loads, with a fallback when it cannot load.

- Family: display
- Import: `import { Image } from "@senvenli/react/display";`
- Page: https://design.senvenli.com/docs/components/image
- JSON: https://design.senvenli.com/docs/components/image.json

## Example: A fixed shape

`ratio` keeps the box while the picture loads, so the page never jumps.

```tsx
import { Image } from "@senvenli/react/display";
import { Grid } from "@senvenli/react/layout";

export default function Example() {
  return (
    <Grid columns={3} space="space-150">
      <Image src="/avatars/03.webp" alt="Marco smiling, in a blue shirt" ratio="1/1" />
      <Image src="/avatars/05.webp" alt="Sofia in a white blazer" ratio="4/3" radius="large" />
      <Image src="/avatars/07.webp" alt="Claire with long brown hair" ratio="16/9" radius="none" />
    </Grid>
  );
}
```

## Examples

### When it cannot load

A neutral tile with an icon, still named by the alt text.

```tsx
import { Image } from "@senvenli/react/display";

export default function Example() {
  return (
    <div className="w-48">
      <Image src="/missing-picture.webp" alt="The product photo" ratio="4/3" />
    </div>
  );
}
```

## Guidelines

### When to use it

- A product photo, a cover, a thumbnail in a card.

### Use something else when

- [avatar](https://design.senvenli.com/docs/components/avatar.md): The picture is of a person or a company.
- [carousel](https://design.senvenli.com/docs/components/carousel.md): Several pictures to page through.
- [image-viewer](https://design.senvenli.com/docs/components/image-viewer.md): A picture to open full screen.

### Do and avoid

- Give `ratio` so the page does not jump while the picture loads.

## Accessibility

Built in:

- Loads lazily by default.
- The fallback keeps the alt text as its name.

You provide:

- An alt text that says what the picture shows, or "" for decoration.

## API reference

### Image

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| src | `string` |  | yes |  |
| alt | `string` |  | yes | What the picture shows ("A red bicycle against a white wall"); `""` for a purely decorative one. |
| ratio | `string \| number` |  | no | Width to height ("16/9", "4/3", "1/1", or a number like 1.5): the box keeps it before the picture loads, so the page never jumps. Left out, the picture's own shape. |
| fit | `"cover" \| "contain"` | `"cover"` | no | `cover` (default) fills the box and crops; `contain` shows all of it, with space around. |
| radius | `ComponentRadius` |  | no |  |
| fallback | `React.ReactNode` |  | no | Shown when the picture cannot load; a neutral tile with an image icon by default. |
| loading | `"lazy" \| "eager"` | `"lazy"` | no | `lazy` (default) loads it when it nears the screen; `eager` for the picture above the fold. |
| width | `number` |  | no |  |
| height | `number` |  | no |  |

### Tokens it reads

`--ds-background-neutral`, `--ds-icon`, `--ds-icon-brand`, `--ds-icon-danger`, `--ds-icon-information`, `--ds-icon-subtle`, `--ds-icon-success`, `--ds-icon-warning`, `--ds-radius-medium`, `--ds-size-icon`, `--ds-size-icon-large`, `--ds-size-icon-small`

## Related

- [avatar](https://design.senvenli.com/docs/components/avatar.md)
- [card](https://design.senvenli.com/docs/components/card.md)
- [carousel](https://design.senvenli.com/docs/components/carousel.md)
