Xzero UI
Pro library

Image compare

Drag a divider across two images to see what changed.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui/image-compare
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui/image-compare

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { ImageCompare } from "@/components/xzero/image-compare/image-compare";

export function Retouch() {
  return (
    <ImageCompare
      before={<img src="/photo-raw.jpg" alt="Unedited photo" />}
      after={<img src="/photo-edit.jpg" alt="Retouched photo" />}
      aspectRatio="4 / 3"
    />
  );
}

API reference

ImageCompare

A before and after slider with a draggable divider over two stacked images.

PropTypeDefaultDescription
before (required)ReactNode–Original, shown left or top. Pass an image with its own alt text.
after (required)ReactNode–Result, shown right or bottom.
positionnumber–Controlled divider position in percent from the left or top.
defaultPositionnumber50Initial position when uncontrolled.
onPositionChange(position: number) => void–Called when the divider settles on a new position.
orientation"horizontal" | "vertical""horizontal"Vertical stacks images top and bottom; changing it swings the divider.
labels[string, string] | false["Before", "After"]Captions over each side. False hides them.
labelstring"Before and after"Accessible name of the divider.
aspectRatiostring"3 / 2"Frame proportions as a CSS aspect-ratio.
classNamestring–Class for the root.

Keyboard interactions

KeysAction
Arrow keysMoves the divider by 1 percent, or 10 with Shift.
PageUp / PageDownMoves the divider by 10 percent.
Home / EndShows all of the before or all of the after image.
Double clickOn the handle, recenters the divider.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in media

Guidance for AI tools

Image compare: Drag a divider across two images to see what changed. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components