React Medium-style Image Zoom

5.4.3 · active · verified Sun Apr 19

React Medium-style Image Zoom is a JavaScript library providing an accessible, high-fidelity image zooming experience inspired by Medium.com, specifically designed for React applications. Currently stable at version `5.4.3`, the project maintains an active release cadence with frequent patch and minor updates addressing bug fixes and introducing new features. A key differentiator is its comprehensive support for various image and content types, including standard `<img>` tags (with `object-fit`, `object-position`, `loading="lazy"`), `<div>` and `<span>` elements with `background-image` properties, `<picture>`, `<figure>`, and even `<svg>`. The library prioritizes accessibility, offering robust screen reader support across major platforms (JAWS, NVDA, VoiceOver, TalkBack). It integrates seamlessly with modern React frameworks like Next.js and Gatsby, requiring React `^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0` and React DOM as peer dependencies. Notably, it boasts zero *direct* runtime dependencies, relying on native browser features like the `<dialog>` element and `ResizeObserver` for its core functionality. It expects an `ES2021` build target, potentially requiring transpilation for older environments.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic usage of the `Zoom` component with a standard `<img>` tag and an example of custom zoom content and icons.

import React from 'react'
import Zoom from 'react-medium-image-zoom'
import 'react-medium-image-zoom/dist/styles.css'

export const MyZoomableImage = () => (
  <Zoom>
    <img
      alt="That Wanaka Tree, New Zealand by Laura Smetsers"
      src="https://rpearce.github.io/react-medium-image-zoom/static/media/thatwanakatree.ed672a9e.jpg"
      width="500"
      loading="lazy"
    />
  </Zoom>
)

// Example of using custom content (more advanced)
import { ICompress, IEnlarge } from 'react-medium-image-zoom/dist/ui'

export const MyCustomZoomContent = () => (
  <Zoom
    overlayBg='rgba(0, 0, 0, 0.9)'
    classDialog='custom-zoom-dialog'
    IconUnzoom={ICompress}
    IconZoom={IEnlarge}
  >
    <img
      alt="Another image with custom zoom"
      src="https://rpearce.github.io/react-medium-image-zoom/static/media/another-image.jpeg"
      width="400"
    />
  </Zoom>
)

view raw JSON →