How it works
Moving noise, moving pixels
Water and hot air bend light a little differently at every point, and the pattern drifts. An SVG filter fakes both: a noise texture says how far each pixel moves, and sliding the noise makes it flow.
1. Where to move each pixel: feTurbulence
<feTurbulence type="fractalNoise"> fills its area with smooth Perlin
noise, an independent random field in each of R, G, B and A. Low baseFrequency values give large, soft blobs; numOctaves adds finer
copies on top. Two numbers make it anisotropic: "0.008 0.04" squeezes the blobs
into thin horizontal bands, which is what rising hot air looks like (the Stretch control). Right now the filter uses 0.01171875 0.01171875.
2. Move them: feDisplacementMap
<feDisplacementMap scale="s"> draws each output pixel from somewhere else
in its input: s × (R − ½) px to the side and s × (G − ½) px up or
down, with R and G read from the noise. Mid-grey noise means no shift, so the content is
pushed around by at most half of Strength in each direction. Because neighbouring noise
values are close, neighbouring pixels move together, and straight lines bend into waves instead
of breaking up.
3. Make it flow, cheaply
A filter has no time input, so something has to change an attribute per frame. Changing seed would jump to unrelated noise, and changing baseFrequency makes the waves breathe in place. What reads as water is noise that slides. The obvious way is
also the expensive one: the browser recomputes feTurbulence over the whole element
on every frame, and that is probably the costliest primitive in the chain (an estimate, not measured).
So the noise is computed on one small tile only. stitchTiles="stitch" nudges
the frequency until a whole number of noise periods fits into the tile, which makes it
repeat without seams; feTile repeats it over the region. To slide it, feOffset cuts a shifted tile back out of that repeated plane, and a second feTile repeats the shifted tile. Since the plane repeats every tile, the shift
never needs to be more than one tile, so JavaScript wraps it into [0, tile) and the motion
can run forever. The tile size also snaps the frequency: with a 256 px tile the
waves can only have 256 / n px periods, so very low frequencies need a bigger
tile.
Cross waves adds a second shifted copy, travelling 125° off the first at
80% speed, and averages the two with feComposite operator="arithmetic". A plain average of two independent noises
huddles closer to grey, so both get the weight 1/√2 instead of ½ and the result is shifted
back to centre on ½. The interference is what makes a pond surface churn rather than slide
past like a conveyor belt.
<svg width="0" height="0" aria-hidden="true">
<!-- W × H: the element's size in px; the region reaches at least 2 × 256 -->
<filter id="ripple" filterUnits="userSpaceOnUse"
x="-9" y="-9" width="max(W, 512) + 18"
height="max(H, 512) + 18"
color-interpolation-filters="sRGB">
<!-- noise on one 256 × 256 tile, made opaque, repeated -->
<feTurbulence type="fractalNoise" baseFrequency="0.01171875 0.01171875"
numOctaves="2" seed="3" stitchTiles="stitch"
x="0" y="0" width="256" height="256" result="raw" />
<feColorMatrix in="raw" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1"
x="0" y="0" width="256" height="256" result="tile" />
<feTile in="tile" result="plane" />
<!-- dx, dy: set from JavaScript every frame, wrapped into [0, 256) -->
<feOffset in="plane" dx="…" dy="…" x="256" y="256" width="256" height="256" result="a" />
<feOffset in="plane" dx="…" dy="…" x="256" y="256" width="256" height="256" result="b" />
<feComposite in="a" in2="b" operator="arithmetic"
k2="0.7071" k3="0.7071" k4="-0.2071" x="256" y="256" width="256" height="256" result="a" />
<feTile in="a" result="waves" />
<feDisplacementMap in="SourceGraphic" in2="waves" scale="14"
xChannelSelector="R" yChannelSelector="G" />
</filter>
</svg> Two details in there. The noise's own alpha channel is noise too and would premultiply the
colors, so a feColorMatrix sets alpha to 1 on the tile. And the region has to reach
at least two tiles from the element's top-left corner, because the shifted tile is cut out at
[tile, 2 × tile); Chromium clips subregions that stick out of the filter region, which leaves
stripes without noise on small elements.
The loop that moves it:
const mod = (v, n) => ((v % n) + n) % n;
let time = 0, last = performance.now();
function tick(now) {
raf = requestAnimationFrame(tick);
if (now - last < 1000 / fps - 1) return; // frame-rate cap
if (!el.closest('[data-motion="paused"]')) {
time += Math.min(now - last, 100) / 1000; // no jump after a pause
}
last = now;
const dir = (angle * Math.PI) / 180;
offsetA.setAttribute('dx', mod(Math.cos(dir) * speed * time, TILE));
offsetA.setAttribute('dy', mod(Math.sin(dir) * speed * time, TILE));
}
// runs only while on screen (IntersectionObserver), the tab is visible
// and prefers-reduced-motion is not set The filter goes on the content, or on what is behind an element:
.under-water {
filter: url(#ripple);
} Presets
- water
- round, medium waves from two directions at a calm speed
- heat haze
- stretched noise (vertical frequency five times the horizontal), small strength, one layer rising straight up
- underwater
- big slow swells with three octaves of detail, a bigger tile for the low frequency, and a
blue-green wash (
feFloodcompositedatopthe result, so transparent areas stay transparent)
Backdrop mode
The same filter can warp what is behind an element through backdrop-filter: url(#ripple), like the frosted and liquid glass effects here. backdrop-filter itself has been Baseline since September 2024, but only
Chromium renders an SVG filter reference in it. Firefox (checked for the frosted glass page) drops the whole backdrop filter when the
list contains url(), and CSS.supports() only checks the syntax, so
it can't tell. The component therefore checks for Chromium after mount and uses a plain blur() elsewhere, which still reads as a hazy surface. The tint becomes the pane's
background in this mode, so it shows in both cases.
Browser support and performance
feTurbulence, feDisplacementMap, feTile and feOffset on HTML through filter: url() are Baseline widely available
(SVG filters, 2015). Checked in headless Chromium; Firefox and Safari are untested for this page.
- Every frame reruns the filter over the whole element: tile noise, displacement and, with a tint, two more steps. Keep the element as small as the effect needs, and the frame rate low. The default cap is 30 fps; water moves slowly, so 20–30 looks the same as 60 for half the work or less.
- It stops when nobody sees it. The loop only runs while the element
intersects the viewport (
IntersectionObserver) and the tab is visible. Inside a[data-motion="paused"]region (the pause button on the stage) the clock stops. Underprefers-reduced-motion: reducenothing moves at all; the waves stay as a still distortion, which is harmless. - Readability. Displacement smears text. Put the filter on a picture or a background layer and keep reading text outside it, as on this stage; the filtered text is still real text for screen readers and selection, but it is hard to read while it moves.
- Edges. Pixels near the border are drawn from outside the element, where
there is nothing, so the edges wobble too. Clip with
overflow: hiddenon a parent, or make the content a little larger than its frame.