OriginalGraded
Installation
$ pnpm dlx shadcn@latest add @synccn/image-compareFirst time in this project? Connect synccn with one command.
Usage
import { ImageCompare } from "@/components/ui/image-compare";<ImageCompare before={<img />} after={<img />} />API reference
Generated from the component's TypeScript types, so it always matches the code.
ImageCompare
Before/after slider. Drag the handle, click anywhere, or use the arrow keys.
PropTypeDescription
- beforerequired
React.ReactNodeImage (or any element) on the left.
- afterrequired
React.ReactNodeImage on the right; sets the height.
- beforeLabel
stringDefault
"Before"Label on the left.
- afterLabel
stringDefault
"After"Label on the right.
- initial
numberDefault
50Starting position, 0–100.
- className
stringExtra classes for the root element.
Dependencies
Read from the component's imports when the site builds. The CLI installs all of these for you.
Helpers
- lib/utilscn (merges class names)
npm packages
- clsx for cn()
- tailwind-merge for cn()
- lucide-react for ChevronsLeftRight
Keyboard
- ←or→Move the divider
Accessibility
- The divider is a focusable slider with aria-valuenow.
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA roles: slider
- ARIA attributes: aria-label, aria-valuemax, aria-valuemin, aria-valuenow
- Keys handled: ArrowLeft, ArrowRight
- Shows a visible focus ring for keyboard users
More display
CardSurface with header, content and footer slots.BadgeSmall status label with an optional dot.AvatarImage with initials fallback, presence dot and stacked groups.KbdKeyboard key for shortcuts and hints.SeparatorHorizontal, vertical or labelled divider.AccordionExpanding sections with smooth height animation.