CompareSlider
Before/after slider to compare two layers of content
Source
LLM docs
Docs
Package
Usage
CompareSlider displays two layers in the same box with a draggable divider between them.
It is commonly used to compare two versions of an image. The before layer is displayed
on the left/top side of the divider, the after layer – on the right/bottom side.


Compare any content
before and after accept any React node: videos, maps, charts, code blocks or plain markup.
Both layers fill the container, make sure they have the same dimensions:
After
New design
Before
Old design
Vertical orientation
Set orientation="vertical" to move the divider vertically:


Controlled
Set position and onPositionChange props to control the divider position.
The position is a number between 0 and 100:


Divider position: 30%
Change position on hover
Set changePositionOnHover to update the divider position when the pointer moves over the
component:


Custom handle
Use the handle prop to replace the default divider handle with any React node:


Set withHandle={false} to hide the handle. The divider line stays visible and the component
remains interactive:
Container size
CompareSlider does not have an intrinsic size. It takes the full width of its parent,
so in most layouts you only need to set a height with h prop or an aspect-ratio.
If the parent does not constrain the width (for example, a flex container), set w or maw prop.
Make both layers fill the box:
Transition
Set transition prop to animate position changes made with the keyboard or with a controlled
value. Pass true to use the default 150ms duration or a number to set the duration in
milliseconds. The transition is not applied while the divider is dragged and when
changePositionOnHover is set:
Disabled
Set the disabled prop to lock the divider and prevent user interaction:


Accessibility
The divider handle is a role="slider" element. To make the component accessible for screen
readers, set the aria-label prop:
Keyboard interactions when the handle is focused:
For vertical orientation, ArrowUp/ArrowLeft decrease the position and
ArrowDown/ArrowRight increase it.