Red Canyon

Code

<script src="/lens-compare.free.js" defer></script>

<lens-compare width="460" ratio="4 / 3" lens="52" value="50">
  <img src="/photos/original.jpg" alt="Original">
  <img src="/photos/graded.jpg" alt="Graded">
</lens-compare>

In context

Neon Rain
Colour grade
Monument Road
Upscale, lens follows the cursor Pro

Install · Free Web Component

One file, no dependencies. Drag preset, every other option included. Host it yourself so your visitors never load anything from our servers.

1. Install with one command — or download the file
shadcn CLI · React
npx shadcn@latest add https://www.ui-design.co/r/lens-compare.json
2. Load it and use the element
HTML
<script src="/lens-compare.free.js" defer></script>

<lens-compare width="420" ratio="4 / 3" lens="52" value="50">
  <img src="/photos/original.jpg" alt="Original">
  <img src="/photos/graded.jpg" alt="Graded">
</lens-compare>
3. React + TypeScript (optional)

The shadcn command adds a typed React wrapper for you. Using the file directly? Custom elements work in React as-is; for type checking add:

TypeScript
// lens-compare.d.ts
declare namespace JSX {
  interface IntrinsicElements {
    'lens-compare': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> & {
      value?: number | string;
      width?: number | string;
      ratio?: string;
      radius?: number | string;
      lens?: number | string;
      'before-label'?: string;
      'after-label'?: string;
      label?: string;
    };
  }
}

Pro · React + TypeScript Pro

One payment of $4.99, yours forever. Use it in unlimited personal and commercial projects; no resale.

  • React component that takes any two nodes (images, video, live UI) with TypeScript types
  • Hover-follow: the lens tracks the cursor without a press, for hero sections
  • The vanilla Web Component, a demo page, README and license

Attributes & props

NameTypeDefaultDescription
before / after node—Left and right sides. In HTML these are the first and second child.
value 0..10050Where the divider starts, as a share of the width given to the left side.
width number (px)420Width; the height follows the ratio.
ratio CSS aspect-ratio'4 / 3'Shape of the frame.
lens number (px)52Lens diameter.
radius number (px)18Corner radius.
before-label / after-label string'Before' / 'After'Corner labels; an empty string hides one.
hover ProbooleanfalseThe lens follows the cursor without a press.

Drag anywhere on the picture, not only on the lens. Arrow keys move the divider by 2%, with Shift by 10%, and Home and End jump to the ends. Both sides are cropped to fill the frame, so use pictures of the same shape. The lens uses backdrop-filter; where that is unsupported it is a plain glass disc. It uses no WebGL.

More components