Image Compare

Before/after comparison whose top layer is clipped by a spring-smoothed clip-path divider, with a draggable knob, optional hover-follow mode, edge-fading labels, keyboard slider control, and images or any React node on either side.

Preview

Image Compare preview width

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @karaui/image-compare
@karaui not found? Add it to components.json
{
  "registries": {
    "@karaui": "https://karaui.kamisama-v0.my.id/r/{name}.json"
  }
}

@karaui is in shadcn's public registry directory, so the latest CLI needs no setup. On an older CLI, merge this into the existing file once and every @karaui/… install resolves.

API Reference

before
ReactNode

Left / underneath layer. An image URL or any node.

—
after
ReactNode

Right / clipped top layer. An image URL or any node.

—
beforeAlt?
string

Alt text when `before` is a URL.

—
afterAlt?
string

Alt text when `after` is a URL.

—
value?
number

Divider position in percent (controlled).

—
defaultValue?
number
50
onValueChange?
((value: number) => void)
—
hover?
boolean

Divider follows the pointer while hovering instead of needing a drag.

false
beforeLabel?
ReactNode
Before
afterLabel?
ReactNode
After
showLabels?
boolean
true
aria-label?
string
Comparison divider
className?
string
—

Updated