Image Compare

A before/after comparison on one layout-stable stage, driven by a native range input so it works with a mouse, a keyboard and a screen reader.

UIimage-compareView JSON

Both images share one stage, so the block never jumps while the two files load. The split is a native range input rather than a decorative handle: arrow keys move it, the value is announced, and the visual divider follows the same state.

Preview

The frame in black and white
The frame in color
Black and whiteColor

Installation

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

pnpm dlx shadcn@latest add litingyes/blocove/image-compare

Requires a shadcn/ui project set up with Base UI primitives. Blocove is developed against the b0 preset, but it installs no base config or theme tokens: your own preset, fonts and colors stay in place.

Or install from the namespace after adding the registry: npx shadcn@latest add @blocove/image-compare

API Reference

Props accepted by the exported components.

ImageCompare

A before/after comparison on one layout-stable stage. The range input drives the split and stays visible for keyboard and screen-reader users.

PropTypeDefault
beforeImageCompareSideRequired
afterImageCompareSideRequired
beforeLabelstring'Before'
afterLabelstring'After'
defaultPositionnumber50
aspectRationumber | string'16 / 9'
widthsreadonly number[]-
transform(src, width) => stringIdentity
sizesstring-
rangeLabelstring'Comparison position'
classNamestring-

ImageCompareSide

One side of the comparison.

PropTypeDefault
srcstringRequired
altstringRequired