# Film grain gradient

> Animated film grain over a dark gradient with a drifting light, for an analog, cinematic texture.

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

## Where to use it

Grain takes the digital edge off a gradient and makes it feel shot on film. It suits the portfolio of a photographer or filmmaker, the homepage of a creative studio or an album release page. The noise flickers like real film while a patch of light moves slowly. It’s a CSS film grain background, noise included.

The grain is kept faint on purpose. If you raise the opacity, check it on a phone too, because noise looks stronger on small bright screens. It pairs well with big serif headlines and generous white space.

## Code

### HTML

```html
<div class="pt-grain"><b></b><i></i></div>
```

### CSS

```css
.pt-grain {
  --c1: #0071e3;
  --c2: #8b5cf6;
  --c3: #14b8a6;
  --k: 1;
  /* velocidad */
  --d: 1;
  /* densidad / escala */
  --o: 1;
  /* opacidad */
  --bg: #05060a;
  --fg: #ffffff;
  --blend: screen;
  min-height: 100vh;
}

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

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

.pt-grain {
  background: radial-gradient(120% 90% at 15% 10%,color-mix(in srgb,var(--c1) 55%,var(--bg)),transparent 60%),radial-gradient(100% 80% at 90% 95%,color-mix(in srgb,var(--c2) 50%,var(--bg)),transparent 60%),var(--bg)!important;
}

.pt-grain b {
  position: absolute;
  inset: 0;
  background: radial-gradient(40% 50% at 70% 30%,color-mix(in srgb,var(--c3) 45%,transparent),transparent);
  animation: pt-grain-d calc(12s / var(--k)) ease-in-out infinite alternate;
}

.pt-grain i {
  position: absolute;
  inset: -100%;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-size: calc(200px * var(--d));
  opacity: calc(var(--o) * .22);
  mix-blend-mode: overlay;
  animation: pt-grain-j calc(0.8s / var(--k)) steps(1) infinite;
}

@keyframes pt-grain-d {
  from {
    transform: translate(-10%,5%) scale(1);
  }
  to {
    transform: translate(10%,-5%) scale(1.3);
  }
}

@keyframes pt-grain-j {
  0% {
    transform: translate(0,0);
  }
  20% {
    transform: translate(-5%,-10%);
  }
  40% {
    transform: translate(-15%,5%);
  }
  60% {
    transform: translate(7%,-25%);
  }
  80% {
    transform: translate(-5%,25%);
  }
  100% {
    transform: translate(0,0);
  }
}
```

### React

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

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

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

.pt-grain {
  background: radial-gradient(120% 90% at 15% 10%,color-mix(in srgb,var(--c1) 55%,var(--bg)),transparent 60%),radial-gradient(100% 80% at 90% 95%,color-mix(in srgb,var(--c2) 50%,var(--bg)),transparent 60%),var(--bg)!important;
}

.pt-grain b {
  position: absolute;
  inset: 0;
  background: radial-gradient(40% 50% at 70% 30%,color-mix(in srgb,var(--c3) 45%,transparent),transparent);
  animation: pt-grain-d calc(12s / var(--k)) ease-in-out infinite alternate;
}

.pt-grain i {
  position: absolute;
  inset: -100%;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-size: calc(200px * var(--d));
  opacity: calc(var(--o) * .22);
  mix-blend-mode: overlay;
  animation: pt-grain-j calc(0.8s / var(--k)) steps(1) infinite;
}

@keyframes pt-grain-d {
  from {
    transform: translate(-10%,5%) scale(1);
  }
  to {
    transform: translate(10%,-5%) scale(1.3);
  }
}

@keyframes pt-grain-j {
  0% {
    transform: translate(0,0);
  }
  20% {
    transform: translate(-5%,-10%);
  }
  40% {
    transform: translate(-15%,5%);
  }
  60% {
    transform: translate(7%,-25%);
  }
  80% {
    transform: translate(-5%,25%);
  }
  100% {
    transform: translate(0,0);
  }
}

`;

export default function PatternGrain() {
  const ref = useRef(null);
  return (
    <>
      <style>{css}</style>
      <div
        ref={ref}
        className="pt-grain"
        style={{
          "--c1": "#0071e3",
          "--c2": "#8b5cf6",
          "--c3": "#14b8a6",
          "--k": 1,
          "--d": 1,
          "--o": 1,
          "--bg": "#05060a",
          "--fg": "#ffffff",
          "--blend": "screen",
          minHeight: "100vh",
        }}
      >
        <b></b><i></i>
      </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 “Film grain gradient” block (Backgrounds) from AIMRAN Library to my project.

## What it is
Animated film grain over a dark gradient with a drifting light, for an analog, cinematic texture.

## Chosen settings
- Color 1: #0071e3
- Color 2: #8b5cf6
- Color 3: #14b8a6
- 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-grain {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg);
  container-type: size;
  isolation: isolate;
}

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

.pt-grain {
  background: radial-gradient(120% 90% at 15% 10%,color-mix(in srgb,var(--c1) 55%,var(--bg)),transparent 60%),radial-gradient(100% 80% at 90% 95%,color-mix(in srgb,var(--c2) 50%,var(--bg)),transparent 60%),var(--bg)!important;
}

.pt-grain b {
  position: absolute;
  inset: 0;
  background: radial-gradient(40% 50% at 70% 30%,color-mix(in srgb,var(--c3) 45%,transparent),transparent);
  animation: pt-grain-d calc(12s / var(--k)) ease-in-out infinite alternate;
}

.pt-grain i {
  position: absolute;
  inset: -100%;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-size: calc(200px * var(--d));
  opacity: calc(var(--o) * .22);
  mix-blend-mode: overlay;
  animation: pt-grain-j calc(0.8s / var(--k)) steps(1) infinite;
}

@keyframes pt-grain-d {
  from {
    transform: translate(-10%,5%) scale(1);
  }
  to {
    transform: translate(10%,-5%) scale(1.3);
  }
}

@keyframes pt-grain-j {
  0% {
    transform: translate(0,0);
  }
  20% {
    transform: translate(-5%,-10%);
  }
  40% {
    transform: translate(-15%,5%);
  }
  60% {
    transform: translate(7%,-25%);
  }
  80% {
    transform: translate(-5%,25%);
  }
  100% {
    transform: translate(0,0);
  }
}

`;

export default function PatternGrain() {
  const ref = useRef(null);
  return (
    <>
      <style>{css}</style>
      <div
        ref={ref}
        className="pt-grain"
        style={{
          "--c1": "#0071e3",
          "--c2": "#8b5cf6",
          "--c3": "#14b8a6",
          "--k": 1,
          "--d": 1,
          "--o": 1,
          "--bg": "#05060a",
          "--fg": "#ffffff",
          "--blend": "screen",
          minHeight: "100vh",
        }}
      >
        <b></b><i></i>
      </div>
    </>
  );
}
```

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