LayerwiseLayerwise
  • Features
  • Pricing
  • Templates
  • Docs
DownloadDownload
FeaturesPricingTemplatesDocsAI Website BuilderVibe CodingPersonal Software
DownloadDownload
  1. Glossary
  2. /
  3. Visual effects

Before/after slider

Also called image comparison slider, comparison slider, or before and after slider

A comparison control that stacks two versions of an image and lets people drag a divider to reveal more of one or the other.

import { useState } from 'react';
import { Slider } from '@base-ui/react/slider';

const LABEL =
  'absolute top-3 rounded-full bg-black/60 px-2.5 py-1 text-xs font-medium text-white';

export function BeforeAfterSlider() {
  const [position, setPosition] = useState(50);

  return (
    <div className='relative aspect-video w-full max-w-2xl overflow-hidden rounded-2xl select-none'>
      <img
        src='/kitchen-after.jpg'
        alt='Kitchen after the renovation'
        className='absolute inset-0 size-full object-cover'
      />
      {/* Clip the top image instead of resizing it, so the two stay perfectly aligned. */}
      <img
        src='/kitchen-before.jpg'
        alt='Kitchen before the renovation'
        className='absolute inset-0 size-full object-cover'
        style={{ clipPath: `inset(0 ${100 - position}% 0 0)` }}
      />
      <span className={`${LABEL} left-3`}>Before</span>
      <span className={`${LABEL} right-3`}>After</span>
      {/* Base UI handles dragging anywhere on the image, touch, and the arrow keys. */}
      <Slider.Root
        value={position}
        onValueChange={setPosition}
        className='absolute inset-0'
      >
        <Slider.Control className='size-full cursor-ew-resize touch-none'>
          <Slider.Track className='size-full'>
            <Slider.Thumb
              aria-label='Comparison position'
              className='h-full w-0.5 bg-white has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-white'
            >
              <span className='absolute top-1/2 left-1/2 grid size-11 -translate-x-1/2 -translate-y-1/2 place-items-center rounded-full bg-white text-black shadow-lg'>
                ↔
              </span>
            </Slider.Thumb>
          </Slider.Track>
        </Slider.Control>
      </Slider.Root>
    </div>
  );
}
Build a before/after image comparison slider: stack the two images, clip the top one with clip-path: inset(0 calc(100% - var(--position)) 0 0), and start the divider at 50%. Support mouse and touch dragging anywhere on the image, a 44px round handle, "Before" and "After" labels, and Left and Right arrow keys that move the divider by 5%.

Paste into Layerwise or any AI coding tool.

What is Before/after slider?

A before/after slider places two versions of the same picture on top of each other. A vertical divider with a round handle sits in the middle, and dragging it clips the top image so more of the bottom one shows. People compare details directly instead of flipping between two pictures.

It suits photo edits, redesigns, renovations, cleaning and beauty results, image upscalers, and maps that change over time. Both images need the same size and framing, or the comparison falls apart.

Clip the top image with clip-path: inset() driven by the divider position, which is cheaper than resizing it. Let people drag anywhere on the image, keep the handle at least 44px wide for touch, and make it keyboard accessible: a native range input, or an element with role="slider" that responds to the arrow keys.

Related terms

All terms

Clip-path

A CSS property that cuts an element to a shape, such as a circle, an inset rectangle, or a polygon, and hides everything outside it.

Drag gesture

Moving an element by pressing on it and sliding the pointer or finger, usually within set bounds and with a glide after release.

Mask

A CSS technique that uses an image or gradient to set how visible each part of an element is, often used to fade edges softly.

Crossfade

A transition where the old content fades out while the new content fades in at the same spot, so the two briefly overlap.

Build it with Layerwise

Describe your app, watch it run in a live preview, and publish it with a database, storage, and sign-in built in.

DownloadDownloadRead the docs
LayerwiseLayerwise

Build full-stack web apps in minutes with AI.

Product

  • Features
  • Pricing
  • Download
  • Templates

Solutions

  • AI Website Builder
  • Vibe Coding
  • Personal Software

Resources

  • Documentation
  • Changelog
  • Blog
  • Vibe Coding Glossary
  • llms.txt
  • llms-full.txt

Company

  • About
  • Contact

Legal

  • Privacy
  • Analytics Privacy
  • Terms
  • Security
  • Abuse

© 2026 Layerwise. All rights reserved.

Entrances & exits

  • Fade in
  • Slide in
  • Scale in
  • Pop in
  • Blur in
  • Reveal animation
  • Enter and exit animations

Timing & sequencing

  • Duration
  • Delay
  • Keyframes
  • Tweening
  • Stagger
  • Orchestration
  • Fill mode
  • Stepped animation
  • Looping animation
  • Yoyo animation

Easing

  • Easing
  • Linear easing
  • Ease-in
  • Ease-out
  • Ease-in-out
  • Cubic-bezier
  • Asymmetric easing
  • Overshoot easing

Springs & physics

  • Spring animation
  • Stiffness
  • Damping
  • Mass
  • Bounce
  • Velocity
  • Momentum
  • Interruptible animation
  • Rubber-banding

Transforms

  • Translate
  • Scale
  • Rotate
  • Skew
  • 3D flip
  • Perspective
  • Transform origin
  • Origin-aware animation

State transitions

  • Crossfade
  • Morph
  • Shared element transition
  • Layout animation
  • Height auto animation
  • Direction-aware transition
  • Continuity transition
  • Page transition
  • View Transitions API

Scroll effects

  • Scroll reveal
  • Scroll-driven animation
  • Parallax scrolling
  • Scrollytelling
  • Scroll pinning
  • Horizontal scroll section
  • Scroll progress bar
  • Scroll snap
  • Smooth scrolling

Interaction feedback

  • Hover effect
  • Press feedback
  • Ripple effect
  • Shake animation
  • Hold to confirm
  • Drag gesture
  • Drag to reorder
  • Swipe to dismiss
  • Pull to refresh
  • Magnetic button
  • Custom cursor
  • 3D tilt card
  • Spotlight card

Text effects

  • Typewriter effect
  • Text scramble
  • Split text animation
  • Text morph
  • Rotating words
  • Gradient text
  • Shimmer text
  • Number ticker
  • Tabular numbers
  • Underline animation

Loops & ambient motion

  • Marquee
  • Pulse animation
  • Float animation
  • Orbit animation
  • Idle animation
  • Particle background
  • Border beam
  • Confetti
  • Animated gradient

Visual effects

  • Blur
  • Clip-path
  • Mask
  • Before/after slider
  • SVG line drawing
  • Lottie animation

Motion principles

  • Purposeful animation
  • Anticipation
  • Follow-through
  • Squash and stretch
  • Perceived performance
  • Frequency of use
  • Spatial consistency
  • Reduced motion

Animation performance

  • Frame rate (FPS)
  • Jank
  • GPU acceleration
  • will-change
  • Layout thrashing

Layout

  • Hero section
  • Above the fold
  • Sticky header
  • Sidebar
  • Bento grid
  • Card
  • Flexbox
  • CSS Grid
  • Padding vs margin
  • Responsive design
  • Container
  • Masonry layout
  • Split screen
  • Z-index
  • Overflow

Components

  • Button variants
  • Modal
  • Drawer
  • Popover
  • Tooltip
  • Dropdown menu
  • Context menu
  • Toast notification
  • Tabs
  • Segmented control
  • Accordion
  • Carousel
  • Command palette
  • Combobox
  • Toggle switch
  • Checkbox
  • Radio button
  • Date picker
  • Breadcrumb
  • Pagination
  • Infinite scroll
  • Badge
  • Avatar stack
  • Empty state
  • Skeleton screen
  • Spinner
  • Progress bar
  • Data table
  • Stepper
  • Floating label
  • Inline validation
  • Alert banner
  • Tag input

States & patterns

  • Interaction states
  • Focus ring
  • Loading state
  • Optimistic UI
  • Debounce
  • Lazy loading
  • Dark mode
  • Micro-interaction
  • Affordance
  • Undo
  • Drag and drop
  • Keyboard shortcut

Visual styles

  • Glassmorphism
  • Liquid glass
  • Neumorphism
  • Claymorphism
  • Neo-brutalism
  • Skeuomorphism
  • Flat design
  • Mesh gradient
  • Aurora background
  • Grain texture
  • Glow effect
  • Drop shadow
  • Border radius
  • Grid background
  • Typographic hierarchy
  • Accent color
  • Color contrast

Vibe coding & AI

  • Vibe coding
  • Prompt
  • Context window
  • Token
  • AI agent
  • Tool call
  • Hallucination
  • Diff
  • Live preview
  • Checkpoint
  • Git commit
  • Deploy
  • Frontend and backend
  • API
  • Database
  • Rules file
  • MCP
  • Plan mode
  • Visual edit
A winding road through yellow and orange trees, seen from above
BeforeAfter