Image compare
Two images, or any two pieces of content, one over the other, with a divider that shows more of one or the other: an edit against the original, a redesign against the old page, a map then and now. For a single image that opens larger, use the image zoom.
Install
npx shadcn@latest add @thrum-pro/image-compareThis is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.
Automatically installs icons arrow-left-right and arrow-up-down from the icon set.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
before | ReactNode | Required | What shows on the start side of the divider: left, or top when vertical. An image inside fills the frame and is cropped to it. |
after | ReactNode | Required | What shows on the end side of the divider. |
beforeLabel | string | Default "Before" | The name of the start side: its chip, and part of what a screen reader hears. |
afterLabel | string | Default "After" | The name of the end side. |
showLabels | boolean | Default true | Show the two names as chips in the corners. Each chip is cut by the divider with its side. |
value | number | – | Where the divider is, in percent of the frame from the start edge, when the parent holds the state. Use it with onValueChange. |
defaultValue | number | Default 50 | Where the divider starts, when the component holds its own state. |
onValueChange | (value: number) => void | – | Called with the new position, in percent, as the divider moves. |
orientation | "horizontal" | "vertical" | Default "horizontal" | vertical stacks the two sides, with a divider that moves up and down. |
hover | boolean | Default false | The divider follows the mouse without a press. Touch and pen still drag it, and the keyboard still moves it. |
ratio | number | string | Default 16 / 9 | Width divided by height of the frame: a number or a CSS ratio such as "4 / 3". The frame keeps it before the images load. |
step | number | Default 1 | How far an arrow key moves the divider, in percent. Shift with an arrow key, Page Up and Page Down move 10%. |
sound | boolean | Default true | Play a subtle tick when crossing the 50% center detent, if the visitor has sound on. |
disabled | boolean | Default false | The divider stays where it is and takes no focus. |
aria-label | string | Default "Before and after" | The divider's accessible name. The default joins the two labels with and. |
className | string | – | Extra classes for the frame, merged last. Set the width here. |
...props | SliderPrimitive.Root.Props | – | Other props of the headless slider root, such as name and onValueCommitted, are passed through. |
Motion and sound
Motion
- The divider follows the pointer, the keyboard and a press on the frame at once, with no easing: the two sides must line up with what the hand does.
- The handle grows to 110% while it is dragged, over 150 ms. Reduced motion: it does not grow.
Sound
- A soft tick when the divider crosses the 50% center detent.
Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works
Accessibility
- The divider follows the WAI-ARIA slider pattern through the headless slider part: a native range input with the slider role, its name from aria-label, and arrow, Page and Home and End keys.
- Its value is read in words, such as "Before 40%, after 60%", so a screen reader user knows what share of each side shows.
- Give each image its own alt text. The chips are drawn on a veil of the page colour, so the text keeps its contrast over any picture.
- The handle is 32 pixels round and the whole frame takes a press, so the target is never small.
| Keys | Action |
|---|---|
| Tab | Focus the divider. |
| Arrow Right / Arrow Left | Move the divider 1% towards the end or the start side. Up and Down on a vertical one. |
| Shift + Arrow, Page Up / Page Down | Move it 10%. |
| Home / End | Show all of the end side, or all of the start side. |
Source
The source comes with Pro
TypeScript source · Copy-paste ready · MIT-compatible for client projects · Includes all dependencies
Files and dependencies
- Adds
components/ui/image-compare.tsx- Packages
@base-ui/react@1.9.0- Brings along
- Sound engine
- Icons
arrow-left-rightarrow-up-down
Changelog
- 1.0.0 · 2026-12-03First release.