<ImageZoom>
<ImageZoom> renders an image inside an accessible zoom button. Images are zoomable by default. The component manages attachment, state, and cleanup for one image.
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 covers installation and a working example.
For wrappers, compose the exported ImageZoomProps type instead of redeclaring image or zoom props. The generated SVG guide shows an example.
Image props
These props apply to the image. The forwarded ref points to the HTMLImageElement.
alt
RequiredDescribes the image and supplies the zoom button's accessible name.
src
The image URL displayed in the page.
srcSet
Image candidates for the browser to select based on resolution or display size.
sizes
The image's display size at each breakpoint, used with srcSet.
width
The image's intrinsic width. Set it with height to reserve space while loading.
height
The image's intrinsic height.
loading
Controls when the browser loads the image. Use lazy for images below the initial viewport.
className
Styles the image. Use composition to style the button separately.
style
Inline styles for the image.
data-zoom-src
An HD image URL loaded when the zoom opens.
Zoom options
options
Configures margin, background, scrollOffset, and container:
margindefaults to24pixels.scrollOffsetdefaults to40pixels.backgroundfollows the image's inherited--backgroundCSS property, falling back to white.containersets a custom viewport, using the values described in the JavaScript option.
disabled
Set to true to prevent opening and disable the trigger.
State props
open
Controls the open state from the parent. When omitted, the component manages its own state.
onOpenChange
Receives the requested next state. With controlled state, apply each request to open. The controlled state guide shows onOpenChange={setOpen}.
Trigger customization
The composition API exposes the button and image as separate components. Custom triggers gives a complete example.