website-glass
Components

Glass

Frosted glass panel with SVG feDisplacementMap lens refraction and WebGL fallback.

Preview

SVG feDisplacementMap lens refraction — the rim bends real DOM pixels. Text stays sharp and selectable.

Install

npx shadcn@latest add https://websiteglass.com/r/glass.json

Usage

import { Glass } from '@/components/ui/glass';

export default function Example() {
  return (
    <div className="relative h-64 w-full bg-gradient-to-br from-indigo-500 to-purple-600">
      <Glass
        className="absolute inset-4 rounded-2xl"
        contentClassName="p-6"
        intensity={0.6}
        blur={20}
      >
        <p className="text-white">Content sits above the glass layer.</p>
      </Glass>
    </div>
  );
}

Props

PropTypeDefaultDescription
intensitynumber0.5Refraction + highlight strength (0–1). Controls displacement scale and tint opacity.
blurnumber20Backdrop blur in px.
bgOpacitynumberderivedGlass tint opacity (0–1). Defaults to a function of intensity.
classNamestringClasses on the root element (controls size, rounding, positioning).
contentClassNamestringClasses on the inner content wrapper.
askeyof JSX.IntrinsicElements"div"Root element tag — use "section", "article", etc. for semantics.
childrenReactNodeContent rendered above the glass layers.

How it works

The component stacks four layers bottom → top:

  1. Backdrop + displacementbackdrop-filter: blur() combined with an SVG feDisplacementMap on the same element. The filter shifts background pixels using a canvas-generated annulus map, producing a real lens rim at the edges while keeping the center clear.
  2. Tint + rim light — a gradient overlay using color-mix() against --color-card, plus inset box-shadow for the inner rim highlight.
  3. Specular hotspot — a blurred radial gradient in the upper-left quadrant mimicking a real light reflection.
  4. Content — sits in a relative wrapper, unaffected by filters; text stays sharp and fully selectable.

When SVGFEDisplacementMapElement is unavailable, a WebGL GLSL shader renders the rim and specular directly onto a canvas overlay.