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.
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



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 haspointer-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-layerstills 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).
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):
<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 / property | Default | Effect |
|---|---|---|
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
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.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.