Skip to content
WANCRAFT

E.139Backgrounds & Effects

Glass Refraction

A liquid-glass pane that bends the content behind it, with a specular rim that leans toward the pointer.

NewReactCSSSVGTailwindadvanced

Overview

Glass Refraction is a panel that refracts whatever sits behind it. In Chromium browsers the backdrop runs through an inline SVG filter: feDisplacementMap driven either by a generated bezel map (lens — content bends and magnifies toward the rounded rim, like thick glass) or by blurred feTurbulence noise (liquid — a rippled pane), followed by a light blur and a saturation lift. The map is rebuilt whenever the pane resizes, so the bezel always matches its corners. Browsers that cannot run SVG filters inside backdrop-filter get a frosted blur instead. A hairline rim, inner light and shade, and a specular highlight that slides around the edge toward the pointer finish the material; the tint follows the theme. Children render on top, crisp and fully interactive — the filters only ever touch the backdrop.

01Installation

Method 01 · Registry

CLI verified

Uses the shadcn CLI in a project initialised with shadcn init. Installs the file to components/ui/glass-refraction.tsx and adds its dependencies.

npx shadcn@latest add https://wancraft.my/r/glass-refraction.json

Method 02 · Copy and paste

  1. 1. No extra dependencies — React and Tailwind CSS only.
  2. 2. Copy the source from the Code tab into components/ui/glass-refraction.tsx.
  3. 3. Import it and adjust props.
Dependencies
None
Peer
react ≥ 18, tailwindcss ≥ 4
Added
13 Oct 2026
Updated
—

02Usage

The default configuration. Change properties above to generate a tailored example in the Usage tab.

example.tsx
import { GlassRefraction } from "@/components/ui/glass-refraction";

export function GlassRefractionExample() {
  return (
    <div className="relative grid h-80 place-items-center overflow-hidden rounded-xl bg-[linear-gradient(120deg,#FF7448,#B6F3D1)]">
      <GlassRefraction className="w-80">
        <div className="p-6">
          <p className="text-xl font-semibold tracking-tight">Light, bent politely.</p>
        </div>
      </GlassRefraction>
    </div>
  );
}

03Props

PropTypeDefaultDescription
distortionnumber40Displacement scale in px; 0 turns refraction off (frost only).
blurnumber2Frost in px. The fallback path adds 8px so it still reads as glass.
tintnumber0.2Surface tint strength, 0–1: white on light themes, near-black on dark ones.
edgenumber0.6Specular rim highlight intensity, 0–1.
radiusnumber24Corner radius in px; the bezel map follows it. Half the size makes a round lens.
surface"lens" | "liquid""lens"A convex bezel that bends content toward the rim, or a turbulent, rippled pane.
followPointerbooleantrueSlide the specular highlight toward the mouse or pen pointer.
tintColorstring—Overrides the theme tint colour (any CSS colour).
childrenReactNode—Content rendered crisply on top of the glass.
...propsHTMLAttributes<HTMLDivElement>—Forwarded to the root. Size it with className (e.g. w-80 h-48). The root gets data-refraction="svg" or "frost".

04Features

  • 01backdrop-filter: url(#svg) with feDisplacementMap, then a light blur and saturation lift
  • 02Lens surface: a rounded-rect bezel displacement map generated on a canvas and rebuilt on resize
  • 03Liquid surface: blurred feTurbulence fractal noise as the displacement source
  • 04Specular rim highlight that slides toward the pointer, via CSS variables written once per frame
  • 05Frosted blur fallback for browsers without SVG backdrop filters; theme-aware tint
  • 06Children are never filtered, so text and controls stay sharp and interactive
input · pointerinput · viewport

05Accessibility

  • Every glass layer (filter, tint, rim, highlight) is aria-hidden and ignores pointer events; only your children are exposed.
  • The pane has no role of its own — wrap content in the semantic elements it needs.
  • prefers-reduced-motion keeps the highlight still at the top-left instead of following the pointer.
  • Keep the tint high enough for legible text over busy backgrounds; the default is 20%.

06Limitations

  • True refraction needs SVG filters inside backdrop-filter, which only Chromium renders (Chrome, Edge, Opera, Arc). Safari and Firefox get the frosted fallback.
  • Backdrop filters see only what is painted behind the pane within the same backdrop root; an ancestor with opacity, filter, mask or clip-path limits it.
  • Very large panes are costlier to refract; prefer cards and lenses over full-screen glass.