Skip to content
synccn

Image Compare

Before/after slider you can drag or move with arrow keys.

OriginalGraded

Installation

$ pnpm dlx shadcn@latest add @synccn/image-compare

First 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.

  • beforerequired
    React.ReactNode

    Image (or any element) on the left.

  • afterrequired
    React.ReactNode

    Image on the right; sets the height.

  • beforeLabel
    string

    Default "Before"

    Label on the left.

  • afterLabel
    string

    Default "After"

    Label on the right.

  • initial
    number

    Default 50

    Starting position, 0–100.

  • className
    string

    Extra 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

npm packages

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