Kinetic UI
Back to Introduction
Media

Before & After Slider

An interactive, draggable slider to effortlessly compare two overlapping images side by side.

Quick Actions
CLI Installation
npx kinetic-ui-cli@latest add before-after-slider
Before & After Slider
AfterBefore
BEFORE
AFTER

Installation

npx kinetic-ui-cli@latest add before-after-slider

How It Works

The BeforeAfterSlider relies on a pure CSS clip-path: inset(...) to perfectly mask the foreground image. State tracking for mouse and touch events dynamically updates the position of the clip-path mask and the slider handle in real time without lag.

Usage Guide

1. Import the Component

Import the component into your React or Next.js page:

import { BeforeAfterSlider } from "@/components/creative/before-after-slider";

2. Implementation Example

Render the component and customize its behavior by passing props:

import { BeforeAfterSlider } from "@/components/creative/before-after-slider";

export default function Example() {
  return (
    <div className="w-full flex items-center justify-center p-8">
      <BeforeAfterSlider
        beforeImage="example"
        afterImage="example"
      />
    </div>
  );
}
Performance Notes
  • Uses CSS hardware acceleration via GPU transform-binds.
  • Damped interpolation minimizes paint-redraw flashes.
  • Tree-shakable import: only compiles elements requested.
Accessibility Notes
  • Full keyboard focus-ring navigation support (`Tab`/`Shift+Tab`).
  • ARIA roles mapped correctly for assistive screen readers.
  • Respects `prefers-reduced-motion` system toggles.