Components

Lens

A magnifying glass effect for React: a round lens follows the cursor over an image, illustration or any content and shows a zoomed view inside it. Works with the mouse, with press-and-hold on touch screens and with the keyboard, and never re-renders React while it moves.

  • Any content, not only images
  • Keyboard & touch
  • Motion values
  • Zoom & size props
  • prefers-reduced-motion
N 52.3676° E 4.9041° · 02:14 local · 1,842 windows lit

Hover, press and hold on touch, or Tab in and use the arrow keys.

Installation

$ npx shadcn@latest add https://duskui.com/r/lens.json

Usage

product-photo.tsx
import Image from "next/image"
import { Lens } from "@/components/dusk/lens/lens"

export function ProductPhoto() {
  return (
    <Lens zoom={2.5} size={180} aria-label="Product photo magnifier">
      <Image src="/sneaker.jpg" alt="Sneaker, side view" width={800} height={600} />
    </Lens>
  )
}

Examples

Fine print

The lens magnifies any markup, including text. Here a smaller size and a higher zoom make tiny terms readable.

Pro plan

$12 / month

Billed annually at $144. Prices exclude local taxes. Cancel any time from your account settings and keep access until the end of the billing period. Seats beyond the first ten are charged pro rata on the next invoice. Usage over 100,000 requests per month is billed at $0.20 per additional 1,000 requests.

Zoom & size

A 3.5× lens with a larger ring over a fine dot grid. Restyle the ring with lensClassName. For images, pass a higher-resolution copy as lensContent for a sharper view.

API Reference

Put padding on the content rather than on Lens, so the magnified copy lines up exactly. Also accepts any div attribute; pass aria-label to describe what is being magnified.

PropTypeDefaultDescription
childrenReactNode—The content to magnify.
zoomnumber2Magnification inside the lens (minimum 1).
sizenumber170Lens diameter in px.
lensContentReactNode—Optional sharper content for the lens, laid out like children.
keyboardStepnumber16Pixels per arrow-key press; ×4 with Shift.
holdDelaynumber220Milliseconds a finger must rest before the lens appears on touch.
lensClassNamestring—Classes for the lens ring.

Accessibility

  • The area is focusable. Keyboard focus shows the lens in the centre; the arrow keys move it (Shift for bigger steps), Enter or Space brings it back and Escape hides it.
  • On touch screens, press and hold to show the lens, then drag; a quick swipe still scrolls the page as usual.
  • The magnified copy is aria-hidden and inert, so screen readers and the Tab key only meet the original content once.
  • Give the area an aria-label that says what is being magnified, and keep alt text on the image itself.
  • With prefers-reduced-motion the lens appears and disappears without fading or scaling; it still follows the pointer directly.