Le Thanh

Image Comparison

Component 1

About

Image Comparison: Drag the handle or use the keyboard to compare images.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Image Comparison to your project and fits it to your theme.

Code

How Image Comparison is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

import { ImageComparison } from "@/components/ui/image-comparison";

export default function DemoOne() {
  return (
    <div className="mx-auto max-w-4xl p-6 space-y-8">
      <h1 className="text-2xl font-semibold tracking-tight">Image Comparison Demo</h1>
      <p className="text-gray-600 dark:text-gray-400">Drag the handle or use the keyboard to compare images.</p>

      {/* 16:9 example */}
      <div className="aspect-[16/9] w-full">
        <ImageComparison
          beforeSrc="https://cdn.21st.dev/assets/mirror/7c/7c7e85c1b4ea7a0291ca978cb98aa42beaade7cf17f3874c0c7b8b694acb3562.jpg"
          afterSrc="https://cdn.21st.dev/assets/mirror/f0/f0d31009ac30a60709a1881c4e5d782ca8d8f51869df716dce9ab58ae14d1d31.jpg"
          beforeAlt="Before"
          afterAlt="After"
          initialPosition={0.5}
          orientation="horizontal"
          className="w-full h-full"
        />
      </div>

      {/* Vertical example */}
      <div className="aspect-[16/9] w-full">
        <ImageComparison
          beforeSrc="https://cdn.21st.dev/assets/mirror/62/623301384253f3b512283784bea3f96c9be8c800af3ada8f5941bd899c2dd0bd.jpg"
          afterSrc="https://cdn.21st.dev/assets/mirror/e5/e53594621a8dde42b926113fbdfcb0b9ae890a487d3d29bb514dda8ae039e103.jpg"
          beforeAlt="Before"
          afterAlt="After"
          initialPosition={0.4}
          orientation="vertical"
          className="w-full h-full"
        />
      </div>
    </div>
  )
}

Dependencies

More by Le Thanh

View all
  • Interactive Image Accordion

    Interactive Image Accordion

    4.2K
  • Interactive Selector

    Interactive Selector

    2.6K
  • Gradient Menu

    Gradient Menu

    2.3K
  • Animated Shader Background

    Animated Shader Background

    2.1K
  • Shader Background

    Shader Background

    2K
  • Waitlist Hero

    Waitlist Hero

    1.8K
  • Image Comparison Slider

    Image Comparison Slider

    1.6K
  • Digital Serenity - Animated Landing Page

    Digital Serenity - Animated Landing Page

    1.4K