StealThis .dev

Diff Slider

Before/after image comparison slider — drag the handle to reveal the difference. Touch support included.

Open in Lab
vanilla-js css
Targets: JS HTML

Code

Diff Slider

A before/after image comparison slider. Drag the center handle to reveal how much of each image is visible. Works with both mouse and touch input.

How it works

The “after” image is clipped using clip-path: inset(0 X% 0 0) where X is derived from the handle’s horizontal position. Moving the handle updates the clip in real time via JavaScript.

Features

  • Mouse drag + touch drag support
  • Keyboard accessible (left/right arrow keys)
  • CSS-only handle design (no image assets required)
  • Works with any images of the same dimensions
  • prefers-reduced-motion respected

Usage

Wrap two <img> elements (or any content) inside .diff-slider. The first child is the “before” layer, the second is the “after” layer.