Menu

Build a Before/After Slider With One Range Input and clip-path (React + Tailwind) | DeliverWebsite UI
📰

Build a Before/After Slider With One Range Input and clip-path (React + Tailwind) | DeliverWebsite UI

DEV Community: tailwindcss·Pooja Deliver Website·6 days ago
#riLsIPp1
#devtotailwindcss#devto#dev#full#divider
Long article (428 words) — no AI summary yet.
Reading 0:00
15s threshold

A before/after slider is the most convincing thing you can put on a redesign page. The visitor drags a

divider and compares the old site with the new one themselves. It looks like it needs a drag library. It

doesn't: one <input type="range"> and one clip-path do the whole job.

The whole component

import { useState , type ReactNode } from "react" ;

export function BeforeAfter ( { before , after , } : { before : ReactNode ; after : ReactNode ; } ) { const [ split , setSplit ] = useState ( 50 ) ;

return ( < div className = "relative overflow-hidden rounded-xl" > < div > { after } </ div > < div className = "absolute inset-0" style = { { clipPath : `inset(0 ${100 - split}% 0 0)` } } > { before } </ div > < div className = "pointer-events-none absolute inset-y-0 w-px bg-blue-600" style = { { left : `${split}%` } } /> < input type = "range" min = { 0 } max = { 100 } value = { split } onChange = { ( event ) => setSplit ( Number ( event . target .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.