Image zoom
An image that opens large when it is pressed, growing out of its thumbnail and shrinking back into it. Use it for screenshots, photos and plans that need a closer look. For any other content in a window, use a dialog.
Install
npx shadcn@latest add @thrum-pro/image-zoomThis is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.
Automatically installs icons x and zoom-in from the icon set.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
src | string | Required | The image. |
alt | string | Required | The text alternative. The large image has the same one, and it names the window. |
zoomSrc | string | – | A larger file for the zoomed view. Without it the thumbnail's src is shown large. |
caption | ReactNode | – | A line under the large image. It is the window's description, read after its name. |
open | boolean | – | Whether it is open, when the parent holds the state. Use it with onOpenChange. |
defaultOpen | boolean | Default false | Whether it starts open, when it holds its own state. |
onOpenChange | (open: boolean) => void | – | Called when it opens or closes, whatever caused it. |
closeLabel | string | Default "Close" | The close button's accessible name. |
sound | boolean | Default true | Play a soft sound when it opens and when it closes, if the visitor has sound on. |
className | string | – | Classes for the thumbnail image: its width, its corners. |
triggerClassName | string | – | Classes for the button around the thumbnail, which carries the focus ring. |
...props | ComponentProps<"img"> | – | Every other img attribute goes to the thumbnail: loading, width, height, srcSet. |
Motion and sound
Motion
- Opening, the window grows from the thumbnail's place and size to the middle of the screen over 200 ms, and the veil fades in.
- Closing plays it backwards into the thumbnail, wherever it is now.
- Reduced motion: the window fades in and out where it stands, without growing.
Sound
- A soft rising tone when it opens.
- A soft falling tone when it closes, whichever way it was closed.
Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works
Accessibility
- The thumbnail is a button named by the image's alt text and ", open larger", so a screen reader says what it opens.
- The large view follows the WAI-ARIA dialog pattern: a modal named by the alt text and described by the caption. The page behind cannot be reached while it is open.
- The large image has the same alt text as the thumbnail.
- The close button is 32 pixels square, sits 12 pixels inside the window, and is named Close.
- The large image is sized to fit the screen, leaving 24 pixels on each side, before it loads, so nothing jumps.
- Under a glass material the frame around the image is translucent; the image itself is never see-through.
| Keys | Action |
|---|---|
| Enter / Space | On the thumbnail: open the large image. Focus moves to the close button. |
| Tab / Shift Tab | Stay on the close button: focus cannot leave the window. |
| Esc | Close it. Focus returns to the thumbnail. |
Source
The source comes with Pro
TypeScript source · Copy-paste ready · MIT-compatible for client projects · Includes all dependencies
Files and dependencies
- Adds
components/ui/image-zoom.tsx- Packages
@base-ui/react@1.9.0- Brings along
- Dialog
- Icons
xzoom-in
Changelog
- 1.0.0 · 2026-12-03First release.