# HD images

> Load a high-resolution image when zooming while displaying a smaller preview in JavaScript or React.

Source: <https://medium-zoom.francoischalifour.com/docs/guides/hd-images/>

Display a smaller preview in the page and load a high-resolution image when the zoom opens. Use the same aspect ratio for both images.

```tsx title="hd-photo.tsx"
import { ImageZoom } from '@/components/ui/image-zoom'

export function HDPhoto() {
  return (
    <ImageZoom
      src="/assets/images/ocean-sunset-preview.webp"
      data-zoom-src="/assets/images/ocean-sunset.jpg"
      alt="Ocean sunset"
      width={1_920}
      height={1_280}
    />
  )
}
```

## JavaScript

Set `data-zoom-src` on the image. Its value is the HD image URL:

```html
<img
  src="/photo-preview.jpg"
  data-zoom-src="/photo-large.jpg"
  alt="A mountain at sunrise"
  width="1200"
  height="800"
  data-zoomable
/>
```

Attach the image after adding it to the document:

```js
import mediumZoom from 'medium-zoom'

mediumZoom('[data-zoomable]')
```

Opening the zoom loads `/photo-large.jpg`.

## React

Pass `data-zoom-src` to `<ImageZoom>` or `<ImageZoom.Image>`:

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

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

Replace both URLs with your preview and HD image.

## Related pages

- [Multiple images](https://medium-zoom.francoischalifour.com/docs/guides/multiple-images/): Attach zoom behavior to several images.
- [\<ImageZoom>](https://medium-zoom.francoischalifour.com/docs/reference/react/image-zoom/): Look up image, zoom, and state props.
