Browse docsLens

Effects

Glass Lens

A draggable magnifier with a glass rim that bends the content beneath it.

Preview

A closer look at the details.

Demos ready. Update 0.

Installation

For React 19+ apps with Tailwind CSS 4.

npx shadcn@4.14.1 add @glassyui/glass-lens

Adds 11 files to components/glassyui and installs clsx.

Usage

The complete preview above, artwork included. Save it as lens-example.tsx.

Usage

'use client';

import { GlassLens } from '@/components/glassyui/glass-lens';

export function LensExample() {
  return (
    <GlassLens
      defaultPosition={{ x: 0.62, y: 0.5 }}
      size={116}
      style={{ width: '100%', maxWidth: 440, height: 240, borderRadius: 22 }}
      zoom={1.7}
    >
      <div
        style={{
          display: 'grid',
          placeItems: 'center',
          boxSizing: 'border-box',
          width: '100%',
          height: '100%',
          padding: 24,
          background:
            'linear-gradient(rgb(142 142 147 / .14) 1px, transparent 1px) 0 0 / 20px 20px, linear-gradient(90deg, rgb(142 142 147 / .14) 1px, transparent 1px) 0 0 / 20px 20px, linear-gradient(135deg, transparent 62%, rgb(255 117 76 / .2) 64%, rgb(240 74 40 / .2) 70%, transparent 72%), linear-gradient(135deg, var(--lg-bg), var(--lg-opaque-surface))',
          color: 'var(--lg-foreground)',
          textAlign: 'center',
        }}
      >
        <p
          style={{
            maxWidth: '12ch',
            margin: 0,
            fontSize: 30,
            fontWeight: 700,
            lineHeight: 1.12,
            letterSpacing: '-0.025em',
          }}
        >
          A closer look at the details.
        </p>
      </div>
    </GlassLens>
  );
}

Install every component it uses:

npx shadcn@4.14.1 add @glassyui/glass-lens

Examples

Render the copied example

import { LensExample } from "./lens-example";

export default function Page() {
  return <LensExample />;
}

API reference

GlassLens

A stage that renders its children with a draggable lens over them.

PropTypeDefaultDescription
childrenRequiredReactNodeNoneContent to magnify. It renders twice, so give it its own background and avoid ids.
sizenumber160Lens diameter in pixels.
zoomnumber1.6Magnification inside the lens.
defaultPosition{ x: number; y: number }{ x: 0.5, y: 0.5 }Starting centre as fractions of the stage's width and height.
labelstring'Magnifier'Accessible name of the lens.

Also accepts HTML div attributes.

Types
GlassLensProps
Accessibility
The lens is focusable: arrow keys move it 10px, or 50px with Shift.