React quickstart
Add the React component and render a zoomable image with <ImageZoom>.
Install the component
In a project configured for shadcn/ui, run:
npx shadcn@latest add @medium-zoom/image-zoom
pnpm dlx shadcn@latest add @medium-zoom/image-zoom
yarn dlx shadcn@latest add @medium-zoom/image-zoom
bunx shadcn@latest add @medium-zoom/image-zoom
The registry copies the component and stylesheet into your project and installs medium-zoom. You can edit those files to match your application.
Display an image
Import <ImageZoom> from your configured components directory. With the usual shadcn/ui alias:
Press Enter or Space to zoom. Click, press Escape, or scroll to close.
photo.tsx
import { ImageZoom } from '@/components/ui/image-zoom'
export function Photo() {
return (
<ImageZoom
src="/assets/images/ocean-sunset.jpg"
alt="Ocean sunset"
width={1_920}
height={1_280}
/>
)
}Replace the image URL with your own. alt describes the image and labels the button. Width and height reserve space while the image loads.
Enter or Space on the button opens the image. Press Esc, click the enlarged image or its background, or scroll to close the zoom.
Browser support
The React component follows the browser requirements of your React application and its build tooling.