# Water caustics

> A rippling net of light, like sunshine on the bottom of a swimming pool, made with an SVG filter.

- Category: [Backgrounds](https://library.aimran.es/components/patterns)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/pt-water
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

Caustics bring summer straight onto the screen. They look right on the homepage of a beach hotel, a surf shop’s summer sale or the booking page of a boat trip. The light keeps shifting, so the page feels fresh without anything busy on it. An animated water background in HTML and CSS, drawn by an SVG filter.

Blues and turquoise are the obvious pick, but a deep green turns it into a lake or a spa. SVG filters are heavier than plain gradients, so if the page is already full of images, test it on a mid-range phone first.

## Code

### HTML

```html
<div class="pt-water"><svg><filter id="pt-water-f" x="0" y="0" width="100%" height="100%"><feTurbulence id="pt-water-t" type="turbulence" baseFrequency="0.006 0.009" numOctaves="1" seed="4"/><feColorMatrix type="matrix" values="0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 -40 3"/></filter><animate href="#pt-water-t" attributeName="baseFrequency" dur="18s" values="0.006 0.009;0.008 0.007;0.006 0.009" repeatCount="indefinite"/><rect width="100%" height="100%" filter="url(#pt-water-f)"/></svg><b></b></div>
```

### CSS

```css
.pt-water {
  --c1: #0071e3;
  --c2: #22d3ee;
  --c3: #0c4a6e;
  --k: 1;
  /* velocidad */
  --d: 1;
  /* densidad / escala */
  --o: 1;
  /* opacidad */
  --bg: #05060a;
  --fg: #ffffff;
  --blend: screen;
  min-height: 100vh;
}

.pt-water {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg);
  container-type: size;
  isolation: isolate;
}

.pt-water>* {
  opacity: var(--o);
}

.pt-water {
  background: linear-gradient(180deg,color-mix(in srgb,var(--c2) 45%,var(--c1)),var(--c1) 45%,var(--c3))!important;
}

.pt-water svg {
  position: absolute;
  inset: -5%;
  width: 110%;
  height: 110%;
  mix-blend-mode: overlay;
  animation: pt-water-d calc(20s / var(--k)) ease-in-out infinite alternate;
}

.pt-water b {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% -10%,rgba(255,255,255,.35),transparent 60%),linear-gradient(0deg,color-mix(in srgb,var(--c3) 60%,transparent),transparent 50%);
}

@keyframes pt-water-d {
  from {
    transform: translate(-2%,-1%) scale(calc(1 / var(--d)));
  }
  to {
    transform: translate(2%,1%) scale(calc(1.05 / var(--d)));
  }
}
```

### React

```tsx
// @ts-nocheck
import { useEffect, useRef } from "react";

const css = `
.pt-water {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg);
  container-type: size;
  isolation: isolate;
}

.pt-water>* {
  opacity: var(--o);
}

.pt-water {
  background: linear-gradient(180deg,color-mix(in srgb,var(--c2) 45%,var(--c1)),var(--c1) 45%,var(--c3))!important;
}

.pt-water svg {
  position: absolute;
  inset: -5%;
  width: 110%;
  height: 110%;
  mix-blend-mode: overlay;
  animation: pt-water-d calc(20s / var(--k)) ease-in-out infinite alternate;
}

.pt-water b {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% -10%,rgba(255,255,255,.35),transparent 60%),linear-gradient(0deg,color-mix(in srgb,var(--c3) 60%,transparent),transparent 50%);
}

@keyframes pt-water-d {
  from {
    transform: translate(-2%,-1%) scale(calc(1 / var(--d)));
  }
  to {
    transform: translate(2%,1%) scale(calc(1.05 / var(--d)));
  }
}

`;

export default function PatternWater() {
  const ref = useRef(null);
  return (
    <>
      <style>{css}</style>
      <div
        ref={ref}
        className="pt-water"
        style={{
          "--c1": "#0071e3",
          "--c2": "#22d3ee",
          "--c3": "#0c4a6e",
          "--k": 1,
          "--d": 1,
          "--o": 1,
          "--bg": "#05060a",
          "--fg": "#ffffff",
          "--blend": "screen",
          minHeight: "100vh",
        }}
      >
        <svg><filter id="pt-water-f" x="0" y="0" width="100%" height="100%"><feTurbulence id="pt-water-t" type="turbulence" baseFrequency="0.006 0.009" numOctaves="1" seed="4" /><feColorMatrix type="matrix" values="0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 -40 3" /></filter><animate href="#pt-water-t" attributeName="baseFrequency" dur="18s" values="0.006 0.009;0.008 0.007;0.006 0.009" repeatCount="indefinite" /><rect width="100%" height="100%" filter="url(#pt-water-f)" /></svg><b></b>
      </div>
    </>
  );
}
```

## Prompt for AI assistants

Paste this into ChatGPT, Claude, Cursor, v0 or Lovable to adapt the block to your stack (Tailwind, Vue, Svelte…):

````text
I want to add the “Water caustics” block (Backgrounds) from AIMRAN Library to my project.

## What it is
A rippling net of light, like sunshine on the bottom of a swimming pool, made with an SVG filter.

## Chosen settings
- Color 1: #0071e3
- Color 2: #22d3ee
- Color 3: #0c4a6e
- Speed: 1x (from 0.2 to 3x)
- Density / scale: 1x (from 0.5 to 2x)
- Opacity: 1 (from 0.2 to 1)

## What I need
1. Add it to my project with the same look and animation as the reference code: same sizes, colours, radii, shadows, timings and easing.
2. It is built with plain HTML and CSS (the reference wraps it in a React component with its CSS). If my project uses something else (Vue, Svelte, Astro, plain HTML…), translate it without losing any behaviour. If I use Tailwind, turn the styles into classes; if not, keep the CSS in its own file.
3. Expose the settings above as props (or CSS variables) with those values as defaults.
4. Make it work well on phones: nothing that depends only on hover, touch targets of at least 44 px and no overflow on 320 px screens.
5. Make it look right in light and dark mode.
6. Keep it accessible: semantic HTML, roles and aria-* where needed, visible focus and keyboard support.
7. Respect prefers-reduced-motion: with reduced motion, no big animations but the same end result.

## Reference code
```tsx
// @ts-nocheck
import { useEffect, useRef } from "react";

const css = `
.pt-water {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg);
  container-type: size;
  isolation: isolate;
}

.pt-water>* {
  opacity: var(--o);
}

.pt-water {
  background: linear-gradient(180deg,color-mix(in srgb,var(--c2) 45%,var(--c1)),var(--c1) 45%,var(--c3))!important;
}

.pt-water svg {
  position: absolute;
  inset: -5%;
  width: 110%;
  height: 110%;
  mix-blend-mode: overlay;
  animation: pt-water-d calc(20s / var(--k)) ease-in-out infinite alternate;
}

.pt-water b {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% -10%,rgba(255,255,255,.35),transparent 60%),linear-gradient(0deg,color-mix(in srgb,var(--c3) 60%,transparent),transparent 50%);
}

@keyframes pt-water-d {
  from {
    transform: translate(-2%,-1%) scale(calc(1 / var(--d)));
  }
  to {
    transform: translate(2%,1%) scale(calc(1.05 / var(--d)));
  }
}

`;

export default function PatternWater() {
  const ref = useRef(null);
  return (
    <>
      <style>{css}</style>
      <div
        ref={ref}
        className="pt-water"
        style={{
          "--c1": "#0071e3",
          "--c2": "#22d3ee",
          "--c3": "#0c4a6e",
          "--k": 1,
          "--d": 1,
          "--o": 1,
          "--bg": "#05060a",
          "--fg": "#ffffff",
          "--blend": "screen",
          minHeight: "100vh",
        }}
      >
        <svg><filter id="pt-water-f" x="0" y="0" width="100%" height="100%"><feTurbulence id="pt-water-t" type="turbulence" baseFrequency="0.006 0.009" numOctaves="1" seed="4" /><feColorMatrix type="matrix" values="0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 -40 3" /></filter><animate href="#pt-water-t" attributeName="baseFrequency" dur="18s" values="0.006 0.009;0.008 0.007;0.006 0.009" repeatCount="indefinite" /><rect width="100%" height="100%" filter="url(#pt-water-f)" /></svg><b></b>
      </div>
    </>
  );
}
```

Give me the complete final code, ready to paste, and tell me in one line where to put it in my project.
````
