Marketing

Compare Slider

new

A before/after comparison with a draggable divider.

Graded photo
Original photo
Before
After

Installation

npx shadcn@latest add @blank/compare-slider

Usage

import {
  CompareSlider,
  CompareSliderAfter,
  CompareSliderBefore,
  CompareSliderHandle,
  CompareSliderLabel,
} from "@/components/ui/compare-slider"
<CompareSlider className="aspect-video">
  <CompareSliderAfter>
    <img src="/after.jpg" alt="After" />
  </CompareSliderAfter>
  <CompareSliderBefore>
    <img src="/before.jpg" alt="Before" />
  </CompareSliderBefore>
  <CompareSliderHandle />
</CompareSlider>

CompareSliderAfter stays in the flow and sizes the slider; CompareSliderBefore lies on top and is clipped at the divider. Press anywhere to move the divider there and drag from that point. The slider is one focusable control: arrow keys move it by step, Shift and the Page keys by ten steps, Home and End to the edges.

Examples

Vertical

Any content compares, not only images.

Monthly report
Updated 2 minutes ago
$12.4k
8.1%
342
Monthly report
Updated 2 minutes ago
$12.4k
8.1%
342
Wireframe
Final

API Reference

CompareSlider

PropTypeDefault
value / defaultValuenumber (0–100)50
onValueChange(value: number) => void—
stepnumber1
orientation"horizontal" | "vertical""horizontal"
interaction"drag" | "hover""drag"

CompareSliderLabel

PropTypeDefault
side"before" | "after""before"

CompareSliderHandle takes children to replace the grip.