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.

hd-photo.tsx
Press Enter or Space to zoom. Click, press Escape, or scroll to close.

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.