Skip to content
All articles Browser and accessibility

Refract a React Scene with opticalSource

Align a decorative copy of a known scene inside your lens so the filter has a direct input.

Use opticalSource when the glass should refract scenery you can reproduce inside the lens. The React wrapper mounts that scene in an absolutely positioned, pointer-transparent layer hidden from assistive technology. QuickLiquid filters that layer directly.

Give both layers the same coordinate system

import { LiquidGlass } from 'quick-liquid/react';

const scene = 'repeating-linear-gradient(115deg, #152544 0 24px, #a3bdff 24px 27px)';

export function OpticalCard() {
  return (
    <div style={{ width: 320, maxWidth: '100%', background: scene }}>
      <LiquidGlass
        config={{ material: 'thin', refractionStrength: 26, borderRadius: 18 }}
        opticalSource={<div style={{ height: '100%', background: scene }} />}
      >
        <p style={{ margin: 0, padding: '2.5rem 1.25rem' }}>Forecast</p>
      </LiquidGlass>
    </div>
  );
}

Both layers start at the same origin here because the lens begins at its container's top-left edge. For a lens at an offset, render a crop of the same full-size scene and compensate by shifting that copy by the lens offset. Keep its dimensions, background sizing, and animation state synchronized with the original. The playground uses the same principle for its movable lens.

Use a decorative source

Use an image, gradient, or display-only visual as the duplicate. Interactive content belongs in the main application tree or in LiquidGlass children. For a responsive scene, resize the window and check a line crossing the rim. A discontinuity in the scene away from the rim usually points to a positioning mismatch. With ordinary live body content, choose the appropriate backdrop or fallback path.