Matrix digital rain in one file. Drop it on a page and the page rains: a canvas, zero dependencies, 5.6 KB gzipped.
It started life as the background of RJL OS, a fake operating system on a single web page, and it keeps everything that made it fun there:
- Touch the rain. Glyphs brighten around the pointer and fall faster under it. Click and a ripple rolls out through the drops.
- A hidden word. Every so often the falling drops spell a word (
RJLby default) in bright ones, then wash it away. Give it a list and it spells them in turn, or callrain.form('HELLO')to spell one on demand. - Anywhere. Full-screen behind the page, inside any element (a hero, a card, a footer), or
over a photo or video with a transparent background. No JavaScript needed:
<rjl-rain>works on its own. - Respectful. With
prefers-reduced-motionit paints one still frame and never animates, and it switches live if the setting changes. An optional pause button covers WCAG 2.2.2. The canvas isaria-hiddenand ignores the pointer, so the page under it works as normal. - Cheap. One
requestAnimationFrameloop at a deliberate 20 fps retro cadence, nothing at all in a hidden tab or while the rain is scrolled out of view. Crisp on high-DPI screens.
Try every option in the playground and copy the code it writes, or see it live at rjl.sh - move the mouse, click, and wait for the word.
Full-screen rain behind your page, from a CDN:
<script src="https://cdn.jsdelivr.net/gh/rjlsoftware/[email protected]/rjl-rain.min.js" integrity="sha384-BzL4UuKSJUM7w459NZ7D0gbQ7F8fvcuMuG0e5V3JitJ4pdDoO5VNwJFJpZjHxb/T" crossorigin="anonymous"></script>
<script>RJLRain();</script>That is the whole install. RJLRain() with no target creates a fixed, full-viewport canvas behind
everything else on the page (it waits for <body> if you call it from <head>). jsDelivr serves the
file straight from the release tag, and the integrity hash makes the browser refuse any other
bytes. The same file is on the CDNs that mirror npm too:
https://cdn.jsdelivr.net/npm/[email protected]/rjl-rain.min.js and
https://unpkg.com/[email protected]/rjl-rain.min.js.
No JavaScript at all: load the script, then put the rain where you want it:
<rjl-rain word="HELLO" color="#FFB000" style="height: 320px"></rjl-rain>
<rjl-rain fullscreen></rjl-rain> <!-- or behind the whole page -->npm:
npm install rjl-rain
# or straight from GitHub:
npm install github:rjlsoftware/rjl-rain#v1.1.4import RJLRain from 'rjl-rain'; // or: const RJLRain = require('rjl-rain');
RJLRain();ES module from a CDN, no build step:
<script type="module">
import RJLRain from 'https://cdn.jsdelivr.net/gh/rjlsoftware/[email protected]/rjl-rain.min.mjs';
RJLRain();
</script>Self-hosted: copy rjl-rain.min.js (or the readable rjl-rain.js, or the .mjs modules) from
this repository or from the files attached to each
release, and point the <script> at your copy.
rjl-rain.js is UMD: a classic <script> gets window.RJLRain, and CommonJS gets the same
function as the module export. import resolves to rjl-rain.mjs, and TypeScript types ship for
both.
Pass an element (or a selector for one) and the rain fills it, behind its content:
<section id="hero" style="height: 420px">
<h1>Welcome</h1>
</section>
<script>RJLRain('#hero', { word: 'WELCOME' });</script>RJLRain adds a canvas as the element's first child, makes the element position: relative and
isolation: isolate if it was not already, and puts both back on destroy(). It follows the
element's size as the layout changes.
Your own canvas: give it a <canvas> sized with CSS and it draws on that instead:
<canvas id="screen" style="width: 100%; height: 320px"></canvas>
<script>RJLRain('#screen', { chars: 'RJL', color: '#FFB000', bright: '#FFE2A8' });</script>background: 'transparent' lets whatever is behind the canvas show through: a photo, a video, a
gradient.
<section id="hero" style="height: 420px; background: url(city.png) center / cover">
<h1>Night shift</h1>
</section>
<script>RJLRain('#hero', { background: 'transparent', fade: 0.08 });</script>A fade can only shrink a pixel's alpha, so every trail would leave a faint tint behind; rjl-rain clears that tail away, one band of the canvas per frame, so the canvas stays truly clear between the drops.
Any palette, any glyphs, any words, and every option can change live with rain.set(). For the
film's look, give each drop a white-hot leader and let the columns fall at their own speeds:
RJLRain({ head: '#E8FFE8', speedVariance: 0.6 });Spell several words in turn, centered, and react to each one:
RJLRain({
word: ['WAKE UP', 'FOLLOW', 'THE RAIN'],
wordPosition: 'center',
onWord: (word) => console.log('the rain spelled', word)
});Loading the script defines a <rjl-rain> element. Its attributes are the options in kebab-case
(font-size, speed-variance, word-position...), word takes a comma-separated list, chars
takes a preset name (classic, rjl, binary, hex) or any glyphs, and changing an attribute
updates the rain live. fullscreen puts the rain behind the whole page. It fires a word event
each time a word forms, and its controller is element.rain.
<rjl-rain chars="binary" word="HELLO, WORLD" word-position="center" head="#FFFFFF" controls
style="height: 50vh"></rjl-rain>Or start any element from a data-rjl-rain attribute holding the options as JSON (or nothing):
<div data-rjl-rain='{"word": "HELLO", "color": "#9BD4FF"}' style="height: 300px"></div>
<canvas data-rjl-rain style="width: 100%; height: 200px"></canvas>
<body data-rjl-rain> <!-- full-screen -->Elements present when the page loads start by themselves; call RJLRain.auto() after adding more.
Each one's controller is element.rjlRain.
Import it anywhere: nothing touches the DOM until you call it, so server rendering is safe. Start
the rain once the element exists, and destroy it when the component goes away - every example below
does both. Or skip the wiring in any framework: import 'rjl-rain' once and use <rjl-rain> in
your templates, which starts when it is added to the page and cleans up when it is removed.
React - also Next.js, React Router and TanStack Start
import { useEffect, useRef } from 'react';
import RJLRain from 'rjl-rain';
export function Hero() {
const ref = useRef(null);
useEffect(() => {
const rain = RJLRain(ref.current, { word: 'HELLO' });
return () => rain.destroy();
}, []);
return <section ref={ref} style={{ height: 420 }}><h1>Hello</h1></section>;
}In Next.js, put it in a 'use client' component.
Vue - also Nuxt
<script setup>
import { onMounted, onBeforeUnmount, useTemplateRef } from 'vue';
import RJLRain from 'rjl-rain';
const hero = useTemplateRef('hero');
let rain;
onMounted(() => { rain = RJLRain(hero.value, { word: 'HELLO' }); });
onBeforeUnmount(() => rain.destroy());
</script>
<template>
<section ref="hero" style="height: 420px"><h1>Hello</h1></section>
</template>Nuxt runs it as is: onMounted only runs in the browser.
Angular
import { Component, DestroyRef, ElementRef, afterNextRender, inject, viewChild } from '@angular/core';
import RJLRain from 'rjl-rain';
@Component({
selector: 'app-hero',
template: `<section #hero style="height: 420px"><h1>Hello</h1></section>`
})
export class Hero {
private hero = viewChild.required<ElementRef<HTMLElement>>('hero');
private destroyRef = inject(DestroyRef);
constructor() {
afterNextRender(() => {
const rain = RJLRain(this.hero().nativeElement, { word: 'HELLO' });
this.destroyRef.onDestroy(() => rain.destroy());
});
}
}afterNextRender only runs in the browser, so it is safe with Angular SSR. To use <rjl-rain> in
an Angular template instead, add schemas: [CUSTOM_ELEMENTS_SCHEMA] to the component.
Svelte - also SvelteKit
<script>
import RJLRain from 'rjl-rain';
// An attachment: it runs when the element mounts and cleans up when it goes.
const rain = (options) => (node) => {
const r = RJLRain(node, options);
return () => r.destroy();
};
</script>
<section {@attach rain({ word: 'HELLO' })} style="height: 420px"><h1>Hello</h1></section>Attachments need Svelte 5.29 or later. On older versions, use an action (use:rain) that returns
{ destroy }.
Astro
<section id="hero" style="height: 420px"><h1>Hello</h1></section>
<script>
import RJLRain from 'rjl-rain';
RJLRain('#hero', { word: 'HELLO' });
</script>Astro bundles the script and runs it in the browser. With <ClientRouter /> (view transitions),
start it in a document.addEventListener('astro:page-load', ...) handler, or use <rjl-rain>,
which starts and stops with each page by itself.
SolidJS
import { onCleanup, onMount } from 'solid-js';
import RJLRain from 'rjl-rain';
export function Hero() {
let hero;
onMount(() => {
const rain = RJLRain(hero, { word: 'HELLO' });
onCleanup(() => rain.destroy());
});
return <section ref={hero} style={{ height: '420px' }}><h1>Hello</h1></section>;
}Preact
import { useEffect, useRef } from 'preact/hooks';
import RJLRain from 'rjl-rain';
export function Hero() {
const ref = useRef(null);
useEffect(() => {
const rain = RJLRain(ref.current, { word: 'HELLO' });
return () => rain.destroy();
}, []);
return <section ref={ref} style={{ height: 420 }}><h1>Hello</h1></section>;
}Qwik
import { component$, useSignal, useVisibleTask$ } from '@builder.io/qwik';
import RJLRain from 'rjl-rain';
export const Hero = component$(() => {
const hero = useSignal<HTMLElement>();
// Runs in the browser once the section scrolls into view, so the rain costs nothing until then.
useVisibleTask$(({ cleanup }) => {
const rain = RJLRain(hero.value!, { word: 'HELLO' });
cleanup(() => rain.destroy());
});
return <section ref={hero} style={{ height: '420px' }}><h1>Hello</h1></section>;
});That is Qwik 1. On the Qwik 2 beta, import the same names from @qwik.dev/core.
Lit - and other web components
import { LitElement, html } from 'lit';
import RJLRain from 'rjl-rain';
class RainHero extends LitElement {
async connectedCallback() {
super.connectedCallback();
await this.updateComplete;
this.rain = RJLRain(this.renderRoot.querySelector('section'), { word: 'HELLO' });
}
disconnectedCallback() {
super.disconnectedCallback();
this.rain?.destroy();
}
render() {
return html`<section style="height: 420px"><h1>Hello</h1></section>`;
}
}
customElements.define('rain-hero', RainHero);It works inside a shadow root: the canvas lands next to the section's content there.
Alpine.js
<script>
document.addEventListener('alpine:init', () => {
Alpine.data('rain', (options = {}) => {
let rain; // kept out of Alpine's reactive state on purpose
return {
init() { rain = RJLRain(this.$el, options); },
destroy() { rain.destroy(); }
};
});
});
</script>
<section x-data="rain({ word: 'HELLO' })" style="height: 420px"><h1>Hello</h1></section>htmx, Hotwire Turbo, Livewire, Phoenix LiveView
Server-driven pages swap HTML in and out, so use <rjl-rain>: it starts when it is swapped in and
destroys itself when it is swapped out, with no events to wire up.
<rjl-rain id="hero-rain" word="HELLO" style="height: 420px"></rjl-rain>In Livewire add wire:ignore, and in LiveView phx-update="ignore" (it needs the id), so a
re-render leaves its canvas alone.
WordPress, Webflow, Shopify, Squarespace and other site builders
Paste this into a custom code or HTML embed block (in WordPress, a Custom HTML block, or the theme footer for every page):
<script src="https://cdn.jsdelivr.net/gh/rjlsoftware/[email protected]/rjl-rain.min.js" integrity="sha384-BzL4UuKSJUM7w459NZ7D0gbQ7F8fvcuMuG0e5V3JitJ4pdDoO5VNwJFJpZjHxb/T" crossorigin="anonymous"></script>
<rjl-rain fullscreen word="HELLO"></rjl-rain>Swap fullscreen for a style="height: 420px" to rain in that spot only. The
playground writes this snippet for any look
you pick.
- Reduced motion. With
prefers-reduced-motion: reduceit paints one still frame and never animates;reducedMotion: trueorfalseoverrides the visitor's setting. - A pause button. WCAG 2.2.2 asks for a way to pause motion that runs for more than five
seconds next to other content.
controls: trueadds a small round button in the corner (anaria-pressedtoggle labeled "Pause animation");controls: '#my-button'turns a button of your own into one. A visitor's choice is remembered inlocalStorage(rjl-rain:paused), so the rain stays paused on their next page. - Out of the way. The canvas is
aria-hiddenandpointer-events: none, and clicks on links, buttons and form fields never make ripples.
Every option is optional.
| Option | Default | What it does |
|---|---|---|
chars |
half-width katakana + digits | The glyphs that rain. Any string, or a preset from RJLRain.glyphs: classic, rjl, binary, hex. |
color |
'#00FF00' |
The rain. |
bright |
'#B6FFB6' |
The pointer glow, the ripples and the word. |
head |
'' |
The leading glyph of every drop. '' keeps it the rain color. |
background |
'#000000' |
The color the trails fade into, or 'transparent' to rain over whatever is behind the canvas. |
fade |
0.05 |
How much each frame darkens the last, from 0 to 1. Lower means longer trails. |
fontSize |
16 |
Glyph size in px, which is also the column width. |
fontFamily |
'monospace' |
Any CSS font family list. A web font is requested for you. |
fps |
20 |
Frames per second, 1 to 60. |
speed |
1 |
Rows a drop falls per frame, 0.1 to 3. |
speedVariance |
0 |
0 to 1: how much slower than speed each column may fall. |
word |
'RJL' |
The word the drops spell now and then, or an array spelled in turn. '' turns it off. Letters, digits and ! ? . - : _ '. |
wordChance |
0.005 |
Chance per frame that a new word starts. |
wordFrames |
50 |
How many frames a word lasts. |
wordChar |
'1' |
The glyph the word is drawn with. |
wordScale |
1 |
Cells per letter pixel. 2 doubles the word's size. |
wordPosition |
'random' |
'random' or 'center'. |
onWord |
null |
Called with the word each time one forms. |
interactive |
true |
Pointer glow and click ripples. |
glowRadius |
70 |
Radius of the pointer glow in px. |
ignore |
links, buttons, form fields | A CSS selector. Clicks on matching elements make no ripple. |
reducedMotion |
'auto' |
'auto' follows the visitor's setting, true always paints one still frame, false always animates. |
pauseOffscreen |
true |
Stop drawing while the canvas is scrolled out of view. |
controls |
false |
true adds a pause button; a selector or element turns a button of your own into one. |
RJLRain(target?, options?) returns a controller. target is an element or a selector for one (the
rain fills it), a <canvas> (it draws on it), or nothing (full-screen).
| Member | What it does |
|---|---|
form(word?) |
Spells word (default: the next word option) now. Returns false if it does not fit. |
pause() / resume() |
Stops and restarts the animation loop. |
set(options) |
Changes any options live, for example rain.set({ color: '#9BD4FF' }). |
resize() |
Re-measures the canvas. Rarely needed: size changes are picked up automatically. |
destroy() |
Stops everything, removes every listener, and removes the canvas if RJLRain created it. |
running |
Whether the loop is running (false while paused, off-screen or in reduced motion). |
paused |
Whether it was paused, by pause() or by the pause button. |
forming |
Whether a word is showing. |
canvas |
The canvas being drawn on. |
Also on the function: RJLRain.version, RJLRain.defaults, RJLRain.glyphs,
RJLRain.wordShape(word, scale) (the cells a word lights up) and RJLRain.auto(root?) (starts new
data-rjl-rain elements).
TypeScript: types ship in the package (rjl-rain.d.ts, and rjl-rain.d.mts for import), with
RJLRain.Options, RJLRain.Controller and a typed <rjl-rain> element.
- Backgrounds. The full-screen canvas sits at
z-index: -1. If both<html>and<body>set a background color, the<body>one paints over the rain, so set the color on<html>(or make the body transparent). - Katakana. The classic glyphs need a font with half-width katakana. Every desktop and mobile OS
ships one, but
chars: RJLRain.glyphs.binary(or any ASCII string) needs no special font at all. - Web fonts. A canvas never asks for a web font on its own, so rjl-rain requests the one in
fontFamilyand repaints when it arrives. - Content Security Policy. No
eval, no inline scripts, no injected stylesheets: it sets styles through the DOM, which a strict CSP allows. - Browsers. Any current browser. It uses
ResizeObserverandIntersectionObserverwhen present and falls back to the windowresizeevent and always drawing.
GitHub will not run a canvas in a README, but it will animate an SVG. The banner at the top of this
page is rendered by scripts/render-svg.js: CSS animation only, no script, and it shows a still
frame to anyone who asked for reduced motion. Make your own:
npm run svg -- --word HELLO --chars 01 --width 1600 --height 240 --out hello.svgOptions: --width, --height, --font, --chars, --word, --scale, --seed, --color,
--bright, --background, --title, --out. The same seed always produces the same file.
Working on rjl-rain itself needs Node 22.12 or later (devEngines in package.json). Using it does
not: the package has no Node requirement and no dependencies.
npm install
npm test # Vitest unit tests, the type tests, then Playwright in Chromium
npm run build # regenerates the minified and ES module builds, their types, and the banner
npm run serve # the demo and the playground, at the URL it printsrjl-rain.js and rjl-rain.d.ts are the source. The build generates rjl-rain.min.js,
rjl-rain.mjs, rjl-rain.min.mjs, rjl-rain.d.mts and assets/rain.svg, and keeps this README's
CDN version, integrity hash and size in step. All of it is committed (the CDN serves the files
straight from a tag), and CI fails if anything is out of date.
Bump the version (npm version X.Y.Z --no-git-tag-version, then the banner and VERSION in
rjl-rain.js), add a CHANGELOG.md entry, run npm run build and npm test, commit, then push a
vX.Y.Z tag. The tag runs .github/workflows/release.yml, which checks the tag against the version
and the changelog, rebuilds and tests, creates the GitHub release from the changelog entry with the
builds attached and the integrity hash in its notes, publishes the playground to GitHub Pages, and
publishes to npm with provenance through trusted publishing - no npm token is stored anywhere.
MIT (c) 2026 RJ Lindelof. Born in RJL OS. More at rjl.dev.
The MIT license only asks that copies of the code keep its copyright and license notice: the LICENSE file, and the comment at the top of the script, which the minified build keeps. Credit on your page is not required, but when someone asks "how did you do that?", a link to rjl-rain on GitHub is always appreciated.


