uimaxxer

Image compare

Two versions of one picture split by a divider that follows your finger exactly. Tap anywhere to jump the divider there, or nudge it with the arrow keys.

npx shadcn@latest add @uimaxxer/image-compare
Pro
yourproduct.com
The same harbour graded: blue and red fishing boats, warm evening light on the hills
Cheung Chau harbour, Hong Kong, as a flat ungraded file: washed out and grey
Cheung Chau harbour, Hong Kong. Photograph by Bernard Spragg, CC0.

Usage

import { ImageCompare } from "@/components/ui/image-compare"

<ImageCompare
  beforeLabel="Flat"
  afterLabel="Graded"
  before={<img src="/flat.jpg" alt="" />}
  after={<img src="/graded.jpg" alt="" />}
/>

Props

PropTypeDefaultWhat it does
beforeReactNodeLeft of the divider. Images inside fill the frame with object-fit: cover.
afterReactNodeRight of the divider.
beforeLabelstring"Before"Tag in the top left corner; it fades when the divider covers it.
afterLabelstring"After"Tag in the top right corner.
defaultValuenumber0.5Where the divider starts, 0 to 1.
onValueChange(value: number) => voidCalled as the divider moves.
aspectnumber16 / 10Width over height. Use the image's own ratio.

Keyboard

← →
Move 2%
Shift + ← →
Move 10%
Home / End
All after or all before

Accessibility

  • The grip is a role=slider with its value as a percentage.
  • Pressing anywhere on the picture moves focus to the grip, so pointer and keyboard drive one control.
  • Vertical swipes still scroll the page on touch.
  • Reduced motion makes tap-to-jump instant.