Image compare
Two images stacked with a draggable divider.
When to use
- Showing before and after, such as an edit or a redesign.
- Pointer and keyboard comparison.
When not to use
- The images differ in framing or size.
Installation
terminal
pnpm dlx shadcn@latest add @caliper/image-compare
Adds its 2 files to components/ui/, each with its own stylesheet, and installs their packages. Pro installs with your access token, set up once per project. See Pro access. The first part also adds Caliper UI’s tokens; import them once as in Installation.
API reference
ImageCompare
10 props
PropTypeDefaultDescription
label *string—
before *ReactNode—Any visual content, usually an <img> that fills its box.
after *ReactNode—
beforeLabelstring"Before"
afterLabelstring"After"
defaultValuenumber50Percentage of the width that shows `before`.
valuenumber—
onValueChange((value: number) => void)—
aspectRatiostring"4 / 3"
classNamestring—
Keyboard
- →
- Moves to the next item or value.
- ↑
- Moves to the previous item or value.
- ←
- Moves to the previous item or value.
- ↓
- Moves to the next item or value.
- Home
- Jumps to the first item or the minimum.
- End
- Jumps to the last item or the maximum.
- PageUp
- Moves by a larger step, or to the previous page.
- PageDown
- Moves by a larger step, or to the next page.
Accessibility
It exposes slider semantics, with aria-hidden, aria-label, aria-orientation, aria-valuemin, aria-valuemax and aria-valuenow kept in step with state.
Notes for AI
Give your coding assistant this page as Markdown instead of screenshots: the props, keyboard and examples in one file.
/docs/components/image-compare.mdThe index of every part is at /llms.txt.
