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 @captain/image-compare

Image compare is a Pro component
The demo and the docs are free. The source comes with Pro, through this page, the shadcn CLI and the MCP.
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
| Prop | Type | Default | What it does |
|---|---|---|---|
| before | ReactNode | Left of the divider. Images inside fill the frame with object-fit: cover. | |
| after | ReactNode | Right of the divider. | |
| beforeLabel | string | "Before" | Tag in the top left corner; it fades when the divider covers it. |
| afterLabel | string | "After" | Tag in the top right corner. |
| defaultValue | number | 0.5 | Where the divider starts, 0 to 1. |
| onValueChange | (value: number) => void | Called as the divider moves. | |
| aspect | number | 16 / 10 | Width 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.