Skip to content
shadcn.io is not affiliated with official shadcn/ui

Shadcn Image Zoom for React and Tailwind

Click to zoom images, SVG, and diagrams.

A desk by a window

Installation

bunx --bun shadcn@latest add https://kit.dev/r/image-zoom.json

Anatomy

ImageZoom
└── img | svg | [role="img"] | [data-zoom]

shadcn.io Image Zoom is react-medium-image-zoom with shadcn.io overlay tokens (--background). Click the media to FLIP-zoom it; click again or press Escape to close. Zoom buttons are hidden — the media is the control.

The library finds the first img, svg, [role="img"], or [data-zoom] inside the trigger. That is how Anatomy diagrams zoom on docs pages such as Accordion and Action Bar.

Usage

import { ImageZoom } from "@/components/ui/image-zoom";
<ImageZoom alt="A desk by a window" src="/image.jpg" />

Pass children to zoom SVG or a composed figure. Do not pass src in that case unless you want a raster for the zoomed layer.

<ImageZoom>
  <Anatomy title="Accordion anatomy">{/* … */}</Anatomy>
</ImageZoom>

Examples

SVG

Any inline SVG zooms. Theme fills (var(--primary), var(--muted)) stay on the clone when they resolve from the document.

Guides

Image Zoom vs Image Cropper

Image ZoomImage Cropper
ShapeLightbox / FLIP zoomCrop handles and viewport
Use whenInspect a photo or diagramChoose a crop before upload

Docs anatomy

Wrap the figure on a component page (Accordion, Action Bar, above the live preview). Leave Anatomy examples on the Anatomy page unwrapped so the scene stays inspectable.

The zoomed layer is a live SVG clone, not the Open Graph PNG — RTL and --primary follow the page.

Higher-resolution zoom

For photos, pass zoomInProps (or src plus a larger zoomInProps.src) so the lightbox can decode a sharper file than the inline image.

<ImageZoom
  alt="A desk by a window"
  src="/desk-800.jpg"
  zoomInProps={{ src: "/desk-1600.jpg" }}
/>

API Reference

zoomMargin defaults to 20. Remaining zoom behavior is react-medium-image-zoom.

ImageZoom

PropType
Custom trigger. Must contain an img, svg, [role="img"], or [data-zoom].
AttributeDescription
data-rmizRoot from react-medium-image-zoom
data-rmiz-content"found" or "not-found"
data-rmiz-modalNative dialog (top layer)

Accessibility

The zoomed view is a modal dialog. Click the media to open; click it or press Escape to close. Give photos alt. Give SVG an aria-label (Anatomy uses the diagram title).

Keyboard support

KeyDescription
Escape
Close the zoomed view.

Click or tap the media to zoom. Scroll the page (wheel) also closes the zoomed view.