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.
Press Enter or Space to zoom. Click, press Escape, or scroll to close.
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.