Skip to content
Thrum

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-compare

This 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

PropTypeDefaultDescription
beforeReactNodeRequiredWhat shows on the start side of the divider: left, or top when vertical. An image inside fills the frame and is cropped to it.
afterReactNodeRequiredWhat shows on the end side of the divider.
beforeLabelstringDefault "Before"The name of the start side: its chip, and part of what a screen reader hears.
afterLabelstringDefault "After"The name of the end side.
showLabelsbooleanDefault trueShow the two names as chips in the corners. Each chip is cut by the divider with its side.
valuenumber–Where the divider is, in percent of the frame from the start edge, when the parent holds the state. Use it with onValueChange.
defaultValuenumberDefault 50Where 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.
hoverbooleanDefault falseThe divider follows the mouse without a press. Touch and pen still drag it, and the keyboard still moves it.
rationumber | stringDefault 16 / 9Width divided by height of the frame: a number or a CSS ratio such as "4 / 3". The frame keeps it before the images load.
stepnumberDefault 1How far an arrow key moves the divider, in percent. Shift with an arrow key, Page Up and Page Down move 10%.
soundbooleanDefault truePlay a subtle tick when crossing the 50% center detent, if the visitor has sound on.
disabledbooleanDefault falseThe divider stays where it is and takes no focus.
aria-labelstringDefault "Before and after"The divider's accessible name. The default joins the two labels with and.
classNamestring–Extra classes for the frame, merged last. Set the width here.
...propsSliderPrimitive.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.
KeysAction
TabFocus the divider.
Arrow Right / Arrow LeftMove the divider 1% towards the end or the start side. Up and Down on a vertical one.
Shift + Arrow, Page Up / Page DownMove it 10%.
Home / EndShow all of the end side, or all of the start side.

Source

SourcePro

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. 1.0.0 · 2026-12-03First release.

Loading index…

Keyboard shortcuts

/Ctrl KSearch components, docs and actions
?Show this list
AAppearance studio
SSound on or off
MFull or reduced motion
TTheme: auto, light, dark
GSurface: solid or frosted
BBackdrop photograph (under glass)
CCorner radius: square to round
RReplay the demo, on a component page
DDraw new data, on a component page
←→HomeEndMove the cursor in a focused chart
EscClose a dialog, or leave a chart cursor