# \<ImageZoom>

> React ImageZoom component reference covering native image props, options, defaults, state, and refs.

Source: <https://medium-zoom.francoischalifour.com/docs/reference/react/image-zoom/>

`<ImageZoom>` renders an image inside an accessible zoom button. Images are zoomable by default. The component manages attachment, state, and cleanup for one image.

```tsx
import { ImageZoom } from '@/components/ui/image-zoom'

export function Photo() {
  return (
    <ImageZoom
      src="/photo.jpg"
      alt="A mountain at sunrise"
      width={1_200}
      height={800}
    />
  )
}
```

The [React quickstart](https://medium-zoom.francoischalifour.com/docs/react/) covers installation and a working example.

For wrappers, compose the exported `ImageZoomProps` type instead of redeclaring image or zoom props. The [generated SVG guide](https://medium-zoom.francoischalifour.com/docs/guides/generated-svg/#react) shows an example.

## Image props

These props apply to the image. The forwarded ref points to the `HTMLImageElement`.

### `alt`

Describes the image and supplies the zoom button's accessible name.

- Type: `string`
- Required

### `src`

The image URL displayed in the page.

- Type: `string`

### `srcSet`

Image candidates for the browser to select based on resolution or display size.

- Type: `string`

### `sizes`

The image's display size at each breakpoint, used with `srcSet`.

- Type: `string`

### `width`

The image's intrinsic width. Set it with `height` to reserve space while loading.

- Type: `number | string`

### `height`

The image's intrinsic height.

- Type: `number | string`

### `loading`

Controls when the browser loads the image. Use `lazy` for images below the initial viewport.

- Type: `'eager' | 'lazy'`

### `className`

Styles the image. Use [composition](https://medium-zoom.francoischalifour.com/docs/reference/react/composition/) to style the button separately.

- Type: `string`

### `style`

Inline styles for the image.

- Type: `CSSProperties`

### `data-zoom-src`

An [HD image URL](https://medium-zoom.francoischalifour.com/docs/guides/hd-images/) loaded when the zoom opens.

- Type: `string`

## Zoom options

### `options`

Configures `margin`, `background`, `scrollOffset`, and `container`:

- `margin` defaults to `24` pixels.
- `scrollOffset` defaults to `40` pixels.
- `background` follows the image's inherited `--background` CSS property, falling back to white.
- `container` sets a custom viewport, using the values described in the [JavaScript option](https://medium-zoom.francoischalifour.com/docs/reference/javascript/options/#container).

* Type: `ZoomOptions`

### `disabled`

Set to `true` to prevent opening and disable the trigger.

- Type: `boolean`
- Default: `false`

## State props

### `open`

Controls the open state from the parent. When omitted, the component manages its own state.

- Type: `boolean`

### `onOpenChange`

Receives the requested next state. With controlled state, apply each request to `open`. The [controlled state guide](https://medium-zoom.francoischalifour.com/docs/guides/controlled-state/) shows `onOpenChange={setOpen}`.

- Type: `(open: boolean) => void`

## Trigger customization

The [composition API](https://medium-zoom.francoischalifour.com/docs/reference/react/composition/) exposes the button and image as separate components. [Custom triggers](https://medium-zoom.francoischalifour.com/docs/guides/custom-react-triggers/) gives a complete example.
