Comparison

Reveals the difference between two layers with a draggable divider

Category: display · WCAG 2.2-AA · comparison, before-after, image, slider, display

States

Props

PropTypeDefaultDescription
afterReactNodeBase layer shown underneath
beforeReactNodeTop layer revealed up to the divider
positionnumberDivider position 0–100 (controlled)
defaultPositionnumber50The initial divider position (0–100) when uncontrolled.
onPositionChange(position: number) => voidCalled with the new divider position when it changes.
orientation'horizontal' | 'vertical'horizontalLayout orientation of the component.
keyboardStepnumber5How far the divider moves per arrow-key press.
labelstringText label for the control.

Design tokens

When to use

When not to use

How to build an accessible Comparison in React →

Examples

Image before/after

<Comparison before={<img src="/edited.jpg" alt="" />} after={<img src="/original.jpg" alt="Original" />} label="Reveal edited image" />

Vertical

<Comparison orientation="vertical" before={<Before />} after={<After />} />

Controlled

<Comparison position={position} onPositionChange={setPosition} before={<Before />} after={<After />} />

Related components

← Back to docs