Image Compare

Two pictures one over the other with a handle to wipe between them: before and after.

PROGet Image Compare and 168 other Pro components with pro lifetime — Get Pro

Category
Data & feedback
Access
Pro
Source
172 lines · one file
States
5 drawn

The decision inside it

The handle is a slider

Arrow keys move it, Shift moves further, Home and End go to the ends, and it says how much of each picture is showing.

When to use it

Use Image Compare to show a change between two versions of the same picture: before and after an edit, a redesign, light and dark. Both images should be the same size and framing.

Installation

How you get it

Paste this into Claude Code, Cursor, Codex or any coding agent. It installs the file and uses it as it is, instead of writing a new one.

Use Liro's Image Compare for this.
Install it: npx shadcn@latest add @liro/image-compare
(the @liro registry is set up in components.json, with LIRO_KEY in .env.local)
Import it from @/components/ui/image-compare.
Do not rewrite or restyle it. Pass my data through its props
and keep its built-in states.

For the full brief with every prop and the mistakes assistants usually make, use Copy prompt above. Pro components install through the @liro registry with your CLI token: see the Namespaced tab.

Usage

components/edit-preview.tsx
import { ImageCompare } from "@/components/ui/image-compare";

export function EditPreview() {
  return (
    <ImageCompare
      before={{ src: "/scan.jpg", alt: "The scanned page", label: "Scan" }}
      after={{ src: "/clean.jpg", alt: "The cleaned-up page", label: "Cleaned" }}
    />
  );
}

API reference

“Copy prompt” above puts a full brief on your clipboard, install command, dependencies, props, and the mistakes an assistant usually makes with this component.

Props

Read from the component’s own TypeScript interface when the site is built, so this table cannot drift from the file you install.

TypeNotes
beforeCompareImage Yes–
afterCompareImage Yes–
positionnumber NoWhere the handle is, 0 to 100 (share of "before" showing).
defaultPositionnumber No–
onPositionChange(position: number) => void No–
mode"drag" | "hover" NoMove by dragging, or follow the pointer. Default "drag".
orientation"horizontal" | "vertical" NoWipe sideways or up and down. Default "horizontal".
aspectRationumber NoWidth over height. Default 16 / 10.
labelstring NoThe handle's name for screen readers. Default "Compare images".

Dependencies

npm packages

clsxlucide-reacttailwind-merge

Liro foundations, installed alongside it

liro-theme

States

All of them are drawn by the component. None is left for you to design.

  • Middle
  • Dragging
  • Hover mode
  • Vertical
  • Keyboard

Accessibility

  • Keyboard reachable throughout, in visual order
  • Focus trapped in overlays, Escape closes them
  • Focus returns to whatever opened it
  • Live regions announce what changed, not that something did
  • Honours prefers-reduced-motion

Responsive behavior

  • Sizes to its container, not the viewport
  • Usable from 320px up
  • Pointer-based interaction, so trackpad and touch both work
  • No hover-only affordances