Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Before & After Slider

Pro

Original-image comparisons with a draggable or hover reveal, labels, a vertical option and a multi-pair carousel.

Installation

pnpm dlx shadcn@latest add @viewport/before-and-after-slider

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above comes with Truffle Pro.

Props

PropTypeDefault
pairs*BeforeAfterPair[]—
layout"list" | "carousel"

A stacked series or a one-at-a-time carousel.

"list"
direction"horizontal" | "vertical"

The reveal moves left-to-right or top-to-bottom.

"horizontal"
interaction"dragclick" | "hover"

`hover` follows a mouse without a press; touch and keyboard still work.

"dragclick"
defaultPositionnumber50
resetOnMouseOutbooleanfalse
dividerColorstring"#fff"
dividerSizenumber6
dividerArrowsbooleantrue
imageRationumber

Width divided by height of each image pair.

1
maxWidthnumber820
headingstring—
backgroundstring—
classNamestring—

Accessibility

  • Each comparison exposes a named keyboard slider with orientation and position.
  • Arrow keys move by 2%, Shift by 10%, Home and End reach both edges.
  • Carousel changes fade instead of sliding under ordinary motion and swap instantly under reduced motion.