Skip to content
Thrum

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-zoom

This 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

PropTypeDefaultDescription
srcstringRequiredThe image.
altstringRequiredThe text alternative. The large image has the same one, and it names the window.
zoomSrcstring–A larger file for the zoomed view. Without it the thumbnail's src is shown large.
captionReactNode–A line under the large image. It is the window's description, read after its name.
openboolean–Whether it is open, when the parent holds the state. Use it with onOpenChange.
defaultOpenbooleanDefault falseWhether it starts open, when it holds its own state.
onOpenChange(open: boolean) => void–Called when it opens or closes, whatever caused it.
closeLabelstringDefault "Close"The close button's accessible name.
soundbooleanDefault truePlay a soft sound when it opens and when it closes, if the visitor has sound on.
classNamestring–Classes for the thumbnail image: its width, its corners.
triggerClassNamestring–Classes for the button around the thumbnail, which carries the focus ring.
...propsComponentProps<"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.
KeysAction
Enter / SpaceOn the thumbnail: open the large image. Focus moves to the close button.
Tab / Shift TabStay on the close button: focus cannot leave the window.
EscClose it. Focus returns to the thumbnail.

Source

SourcePro

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. 1.0.0 · 2026-12-03First release.

Loading index…

Keyboard shortcuts

/Ctrl KSearch components, docs and actions
?Show this list
AAppearance studio
SSound on or off
MFull or reduced motion
TTheme: auto, light, dark
GSurface: solid or frosted
BBackdrop photograph (under glass)
CCorner radius: square to round
RReplay the demo, on a component page
DDraw new data, on a component page
←→HomeEndMove the cursor in a focused chart
EscClose a dialog, or leave a chart cursor