Comparison Slider

Before/after image comparison with draggable or hover controls

comparison-slider-tw
PC before
PC after

Customize

50
3
36

Props

NameTypeDefaultDescription
beforeImagestring""URL for the before image (left/top layer)
afterImagestring""URL for the after image (right/bottom layer)
beforeAltstring"Before"Alt text for the before image
afterAltstring"After"Alt text for the after image
initialPositionnumber50Initial position of the slider (0-100)
orientation"horizontal" | "vertical""horizontal"Orientation of the slider
enableInertiabooleantrueEnable inertia/momentum on drag release
dragOnHoverbooleanfalseEnable drag on hover without clicking
autoAnimatebooleanfalseAuto-animate slider with smooth random movement
dividerWidthnumber3Width of the divider line in pixels
showHandlebooleantrueShow the draggable handle with icon
handleSizenumber48Size of the handle in pixels
handleIconReact.ReactNodeundefinedCustom icon component for the handle
dividerColorstring"white"Color of the divider line
handleColorstring"white"Color of the handle background
onPositionChange(position: number) => voidundefinedCallback when slider position changes
classNamestring""Additional CSS classes for the container
imageClassNamestring""Additional CSS classes for both images
showLabelsbooleanfalseShow before/after labels on images
labelText{ before: string; after: string }{ before: "Before", after: "After" }Custom text for labels
labelPosition"top-left" | "top-right" | "bottom-left" | "bottom-right""top-left"Position of the labels
labelClassNamestring""Additional CSS classes for both labels
beforeLabelClassNamestring""Additional CSS classes for before label
afterLabelClassNamestring""Additional CSS classes for after label
showPercentagebooleanfalseShow percentage indicator
percentagePosition"top" | "bottom""top"Position of percentage indicator
onDragStart() => voidundefinedCallback when drag starts
onDragEnd() => voidundefinedCallback when drag ends
ariaLabelstring"Image comparison slider"Custom ARIA label for accessibility
reducedMotionbooleanfalseRespect prefers-reduced-motion setting

Demo images by Alexander Shatov @ unsplash.com, not part of the React Bits Pro offer.