GlassmorphismPremium

Glass Caustics

Patches of light drifting over a dark card, like sun on the floor of a pool: a plain 2D canvas blended over the content, no WebGL.

CanvasAnimationCaustics

Updated

This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Glassmorphism has 47 effects, including 6 free. Explore the category →

3 usage examples

Water reflections behind the headline — home page of a thermal spa — Glass Caustics example 1

① Water reflections behind the headline — home page of a thermal spa

WhenA visitor lands on a thermal baths website: a mosaic pool floor, the menu, a large headline and the booking button. The reflections slide over the whole page, headline included.
WhyThe page needs no photo to say “warm water”: moving light is enough. Because it is blended on top, it touches the headline the way it would touch an object lying on the pool floor, without ever masking it.
SettingsThe effect's scene stretched to the whole page (540 × 360 px, corners at 0); background replaced by a grid of tiles under a deep blue; light layer at full opacity with filter: brightness(1.7); glass strip cut down to 58 px to act as the menu bar, with the links on top.
Light inside the stone — an aquamarine in a gem cutter's catalogue — Glass Caustics example 2

② Light inside the stone — an aquamarine in a gem cutter's catalogue

WhenProduct page for an emerald-cut aquamarine: the stone drawn on the left on dark velvet, its size, colour and price on the right.
WhyA coloured stone sells on its sparkle. Here the light lives inside the stone only: bright points come on and go off from one facet to the next, as when you turn it under a lamp, while the rest of the page stays still.
SettingsLight layer shrunk to the stone's box (inset: 22% 20%) and cut to its shape by an eight-sided clip-path; opacity at 1 and brightness(1.8); glass strip hidden; stone drawn in CSS inside .lg-caustics-content. The caption states that the light is simulated.
Fountains running today — a town hall's summer page — Glass Caustics example 3

③ Fountains running today — a town hall's summer page

WhenA list of the town's four fountains with today's status. The three that are running have a thumbnail where the water shimmers; the one under maintenance has a grey, still thumbnail.
WhyThe status reads before the text does: it moves, so there is water. Each small thumbnail costs about a tenth of a millisecond of computing per frame (measured: 0.11 ms), where three WebGL contexts on a simple list would be out of proportion.
SettingsOne root per 78 × 42 px thumbnail, 8 px corners, teal background; glass strip hidden; layer at full opacity with brightness(2); the stopped fountain is a plain hatched block, without the effect.

How it works

The .lg-caustics-scene card (260 × 170 px, midnight-blue gradient, 14 px corners) stacks three things. At the back, your content (.lg-caustics-content, z-index: 1). Over it, the light layer .lg-caustics-layer: a <canvas> stretched across the whole card, at 60% opacity and in mix-blend-mode: screen — in that mode black adds nothing and light adds up, so the light also runs over the title without hiding it. Right at the top, a strip of glass (.lg-caustics-glass, 40% of the height, backdrop-filter: blur(6px)) frosts whatever passes beneath: the patches are blurred at the top of the card, sharp at the bottom.

The pattern is computed by the processor, frame by frame, in the canvas's 2d context. For each 2 × 2 px block, the script adds three crossing sine waves, keeps only the positive part, raises it to the power 2.5 and multiplies it by a gain (INTENSITY = 3): only the crests remain, soft oval patches in cyan (rgb(120, 220, 255) at full strength), the brighter the more opaque. The result is written in one go with putImageData. These are not caustics in the optical sense — no web of filaments — but reflections that slide, merge and come apart.

The pattern's time advances by 0.48 units per second, worked out from the time that actually elapsed: with a simulated clock, one second at 120, 60 or 30 frames per second gives exactly the same image. Each scene on the page has its own canvas and its own loop; an IntersectionObserver stops the loop as soon as the card leaves the viewport (measured: 121 draws per second per card on a 120 Hz screen, then a stop once off screen). The canvas takes the card's size in CSS pixels, capped at 240,000 pixels: beyond that it is computed smaller and stretched. Cost measured in Chromium: between 0.7 and 1 ms of script per frame for the original card, 2.7 ms at 540 × 360 px, 3.4 ms at 1920 × 1080.

Accessibility

  • Reduced motion: if the visitor has asked for less animation, the script draws a single image of the pattern and starts no loop (measured: zero draws per second afterwards, in all three engines). The light is there, standing still.
  • Contrast: the light runs over the text, that is the idea. Measured on the original card over twelve seconds: the white title stays between 18.4:1 and 5.4:1 when a patch passes; the subtitle, 50% white at 9.6 px, drops from 5.3:1 to 2.6:1. Keep small text in solid white, or lower the layer's opacity.
  • Keyboard and screen readers: nothing to operate, the effect is decoration. The canvas carries aria-hidden="true" and the layer has pointer-events: none: links and buttons placed in the content stay clickable and keyboard-reachable under the light.
  • Pace: no flashing — the patches drift slowly and change shape over several seconds. If the card sits next to long text, still provide a way to freeze the decoration: hiding .lg-caustics-layer stills the screen; the loop itself only stops when the whole card leaves the screen or is hidden.

Browser compatibility

Run in Chromium 149, Firefox 151 and WebKit 26.5: two cards on one page both drawn, pause off screen, still image under reduced motion, no error, nothing added to window, no overflow at 320 px. The pattern and its screen blending were looked at in Chromium (the scenes on this page). The glass strip, however, is only blurred by Chromium in our automated captures; the Firefox and WebKit test engines leave it sharp — real Firefox and Safari not verified. On a Retina screen the canvas stays at CSS resolution: the pattern being soft by nature, it would gain nothing and cost four times as much. Per MDN: mix-blend-mode (Chrome 41, Firefox 32, Safari 8), IntersectionObserver (Chrome 51, Firefox 55, Safari 12.1), inset (Chrome 87, Firefox 66, Safari 14.1).

Chrome 87+✓ Full (measured)
Firefox 66+✓ Pattern measured; glass strip blurred from 103, not verified
Safari 14.1+✓ Not verified on a real Safari (pattern measured in WebKit)
Edge 87+✓ Not verified (same engine as Chrome)
Mobile iOS 14.5+✓ Not verified
Android Chrome 87+✓ Measured in mobile emulation: canvas sized to the card, no overflow

Without JavaScript the card keeps its background, its content and its glass strip: only the light is missing. Without IntersectionObserver the loop runs continuously. Without backdrop-filter the top strip is just a 4% white veil. Since no WebGL is used, there is no graphics context to lose and no fallback to plan on that side.

The code

HTML structure to paste into your page (the CSS + JS come with your purchase):

index.html — structure
<div class="fx-0332-root">
  <div class="lg-caustics-scene" data-caustics-scene>
    <div class="lg-caustics-glass"></div>
    <div class="lg-caustics-layer">
      <canvas class="lg-caustics-canvas" data-caustics-canvas aria-hidden="true"></canvas>
    </div>
    <div class="lg-caustics-content">
      <span class="lg-caustics-title">…</span>
      <span class="lg-caustics-sub">…</span>
    </div>
  </div>
</div>

One-time payment, no subscription — the code is yours forever

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
Light strength (JS — var INTENSITY = 3) 3 At 1 you can barely make out two or three glimmers; at 6 the patches become wide solid areas. To tune a single card without touching the script, go through the CSS: .lg-caustics-layer { opacity: 1; filter: brightness(1.7) }.
Speed (JS — var SPEED = 0.48) 0.48 pattern units per second 0.2 gives almost still water, 1 a restless pool. The value does not depend on the screen's refresh rate.
Blending and opacity (CSS — .lg-caustics-layer) mix-blend-mode: screen, opacity 0.6 screen needs a dark background: on a light one the light disappears. Try overlay over a photo, or plus-lighter for bolder sparkles.
Colour (JS — the three factors 120, 220, 255 in draw()) cyan-white They are the red, green and blue of the light at full strength: 255, 200, 120 gives a golden reflection. Quicker: filter: hue-rotate(…) on the layer.
Grain (JS — var CELL = 2) 2 px blocks 1 computes every pixel (four times the work, hardly any finer); 4 gives mosaic-like light and divides the cost by four.
Glass strip (CSS — .lg-caustics-glass) top 40%, 6 px blur height: 100% frosts all the light; display: none leaves it sharp everywhere. The strip can also serve as a title or menu bar.
Size and background (CSS — .lg-caustics-scene) 260 × 170 px, #0c1222 → #1a1a3e gradient The card can span the full width of a section: the script reads its size again on load and at every window resize. The pattern stretches with it, it does not repeat.

FAQ

The WebGL version computes a real web of caustics in a shader, on the graphics card, sharp on Retina screens, and shows it under a pane: it is the one you want for a realistic pool at large size. This one keeps it simpler: soft patches of light, computed by the processor on a 2D canvas and blended over the content. It opens no WebGL context — nothing to lose when the tab goes to the background, no limit on the number of cards — and it can sit on a headline, an image or a small thumbnail. Take the other for realism, this one for a light mood you can repeat.
Because of the screen blend mode: it lightens what is underneath, and a background that is already light cannot get any lighter. The effect is made for a dark or mid-tone background. On a light page, keep a dark card — which is what the fountains example does — or change the blend mode and the colour of the light.
Yes. A hidden card (display: none, a collapsed tab) does not count as visible: its loop stops, and it starts again when the card is displayed. If it had no size at load time, call window.dispatchEvent(new Event('resize')) after showing it, so that the canvas picks up its dimensions.