A React component for magnifying an image within its original container. The zoom behavior is triggered on click and the image can be moved by dragging on touch devices and by either dragging or hover panning on non-touch devices. The component supports responsive images and optional fullscreen zoom on mobile.
npm install react-inner-image-zoom
yarn add react-inner-image-zoom
I was originally importing the CSS directly into the component but I've recently realized that makes too many assumptions about the wider build process. You can now download the raw CSS file at:
or the minified raw minified version at:
to include however you see fit. Or, if your setup supports it, import the files directory from your
Import and render the component:
import InnerImageZoom from 'react-inner-image-zoom';
<InnerImageZoom src="/path/to/image.jpg" zoomSrc="/path/to/zoom-image.jpg" />
This is the simplest usage. For additional examples, visit the demo page.
|(Required) URL for the original image.
|Default srcset attribute for a responsive original image.
|Default sizes attribute for use with srcset.
|A list of image sources for using the picture tag to serve the appropriate original image (see below for more details).
|URL for the larger zoom image. Falls back to original image src if not defined.
|Multiplied against the natural width and height of the zoomed image. This will generally be a decimal (example, 0.9 for 90%).
|Alternative text for the original image.
drag. The user behavior for moving zoomed images on non-touch devices.
hover. The zoom behavior for images.
|Fade transition time in milliseconds. If zooming in on transparent images, set this to
0 for best results.
|Enables fullscreen zoomed image on touch devices below a specified breakpoint.
|The maximum breakpoint for fullscreen zoom image when fullscreenOnMobile is true.
|Custom classname for styling the component.
|Function to be called after zoom in.
|Function to be called after zoom out.
|if set to true, sets the initial value of isActive to true.
This prop accepts an array of objects which it uses to create a picture tag and source elements. The component looks for the following optional properties and you can find additional details on responsive images here:
|Srcset attribute for source tag.
|Sizes attribute for source tag.
|An attribute containing a media condition for use with the srcset.
|An image MIME type. This is useful for using newer formats like WebP.