All effectsPlay & loop

Matrix Rain

数字雨

Columns of changing glyphs fall at different speeds, leaving fading trails.

Play the demo to see the glyphs fall and change

Where to use it

Add a technical backdrop to a systems, encryption, or developer page. Give the brightest glyphs plenty of room away from text, and pause the rain when the scene is out of view.

Practical example

An online programming puzzle uses low-contrast green columns behind its landing screen. The puzzle chooser is on a solid panel.

Also called

  • Digital Rain
  • Code Rain

AI prompt

Add Matrix Rain behind [section]. Columns of glyphs fall at slightly different speeds and change characters as they drop. Keep the foreground UI readable. Show a static glyph pattern for reduced motion.

Example code

Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.

View HTML
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Matrix Rain</title>
  <style>
    :root {
      color-scheme: dark;
      --demo-bg: #171629;
      --demo-ink: #f8f5ff;
      --demo-accent: #b9a6ff;
      --demo-muted: #bfbbd3;
      font-family: system-ui, sans-serif;
      color: var(--demo-ink);
      background: var(--demo-bg);
    }

    *, *::before, *::after { box-sizing: border-box; }
    body { margin: 0; min-width: 0; }
    button, input { font: inherit; }

    .demo {
      display: grid;
      place-items: center;
      align-content: center;
      min-height: 100vh;
      padding: 14px;
      overflow: hidden;
      background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
    }

    .demo-button {
      border: 1px solid #ffffff3d;
      border-radius: 7px;
      background: #ffffff12;
      color: var(--demo-ink);
      padding: 6px 11px;
      font-size: 12px;
      cursor: pointer;
    }

    :focus-visible {
      outline: 2px solid var(--demo-accent);
      outline-offset: 3px;
    }

    .demo { position: relative; padding: 0; }
    .showcase { position: absolute; inset: 0; isolation: isolate; overflow: hidden; }
    .showcase .demo-button {
      position: absolute;
      z-index: 3;
      bottom: 10px;
      left: 50%;
      transform: translateX(-50%);
      border-radius: 999px;
      background: #101026d9;
      color: #f1efff;
      white-space: nowrap;
    }
    .showcase :is(h1, p) { margin: 0; }
    .scene-copy {
      position: absolute;
      z-index: 1;
      inset: 0;
      display: grid;
      place-content: center;
      padding: 14px;
      text-align: center;
      pointer-events: none;
    }
    .scene-copy h1 {
      font-size: clamp(25px, 8vw, 62px);
      line-height: 1;
      letter-spacing: -.045em;
    }
    .showcase [data-motion] { animation-play-state: paused; }
    .showcase[data-playing] [data-motion] { animation-play-state: running; }
    @media (prefers-reduced-motion: reduce) {
      .showcase [data-motion] { animation: none; }
      .showcase [data-loop-toggle] { display: none; }
    }

    .showcase { background: radial-gradient(ellipse at 54% 67%, #13382b, #081611 83%); }
    .matrix-columns {
      position: absolute;
      inset: 0 -6px;
      display: grid;
      grid-template-columns: repeat(28, minmax(0, 1fr));
      overflow: hidden;
      mask-image: linear-gradient(transparent, #000 18%, #000 85%, #0005);
    }
    .glyph-column {
      position: relative;
      align-self: start;
      display: flex;
      flex-direction: column;
      align-items: center;
      color: #68bd91;
      font: 600 clamp(8px, 2.5vw, 16px) / 1.33 monospace;
      text-align: center;
      white-space: pre;
      opacity: .64;
      mask-image: linear-gradient(transparent, #000 92%);
      transform: translateY(var(--rest));
    }
    .showcase[data-playing] .glyph-column {
      animation: matrix-fall var(--duration) linear var(--delay) infinite;
    }
    .glyph-column:nth-child(3n) { opacity: .45; }
    .glyph-column:nth-child(5n) { opacity: .79; }
    .glyph-column b { color: #bcffd5; text-shadow: 0 0 8px #59df8d; }
    .scene-copy {
      background: radial-gradient(ellipse at center, #081812db 0, #0b1f1773 26%, transparent 56%);
    }
    .scene-copy h1 {
      color: #e6fff0;
      font-family: ui-monospace, monospace;
      font-weight: 650;
      font-size: clamp(19px, 6.5vw, 47px);
      letter-spacing: -.05em;
      text-shadow: 0 2px 11px #05130d;
    }
    @keyframes matrix-fall { from { transform: translateY(-100%); } to { transform: translateY(105vh); } }
  </style>
</head>
<body>
  <main class="demo">
    <div class="showcase">
      <div class="matrix-columns" aria-hidden="true"><span class="glyph-column" style="--duration:2.7s;--delay:-0s;--rest:-62%" data-motion><span>0&#10;ヌ&#10;ヘ&#10;0&#10;ヌ&#10;ヘ&#10;0&#10;ヌ</span><b>タ</b></span><span class="glyph-column" style="--duration:2.99s;--delay:-1.615s;--rest:-33%" data-motion><span>ツ&#10;ム&#10;ヤ&#10;ツ&#10;ム&#10;ヤ&#10;ツ&#10;ム</span><b>メ</b></span><span class="glyph-column" style="--duration:3.2800000000000002s;--delay:-3.23s;--rest:-4%" data-motion><span>ナ&#10;ユ&#10;ヒ&#10;ナ&#10;ユ&#10;ヒ&#10;ナ&#10;ユ</span><b>ヘ</b></span><span class="glyph-column" style="--duration:3.5700000000000003s;--delay:-0.855s;--rest:25%" data-motion><span>コ&#10;タ&#10;リ&#10;コ&#10;タ&#10;リ&#10;コ&#10;タ</span><b>ヒ</b></span><span class="glyph-column" style="--duration:3.8600000000000003s;--delay:-2.47s;--rest:54%" data-motion><span>モ&#10;ク&#10;シ&#10;モ&#10;ク&#10;シ&#10;モ&#10;ク</span><b>シ</b></span><span class="glyph-column" style="--duration:4.15s;--delay:-0.095s;--rest:83%" data-motion><span>ラ&#10;メ&#10;キ&#10;ラ&#10;メ&#10;キ&#10;ラ&#10;メ</span><b>ネ</b></span><span class="glyph-column" style="--duration:4.4399999999999995s;--delay:-1.71s;--rest:-53%" data-motion><span>カ&#10;1&#10;ネ&#10;カ&#10;1&#10;ネ&#10;カ&#10;1</span><b>ツ</b></span><span class="glyph-column" style="--duration:2.7s;--delay:-3.325s;--rest:-24%" data-motion><span>ヌ&#10;ヘ&#10;0&#10;ヌ&#10;ヘ&#10;0&#10;ヌ&#10;ヘ</span><b>コ</b></span><span class="glyph-column" style="--duration:2.99s;--delay:-0.95s;--rest:5%" data-motion><span>ム&#10;ヤ&#10;ツ&#10;ム&#10;ヤ&#10;ツ&#10;ム&#10;ヤ</span><b>ラ</b></span><span class="glyph-column" style="--duration:3.2800000000000002s;--delay:-2.565s;--rest:34%" data-motion><span>ユ&#10;ヒ&#10;ナ&#10;ユ&#10;ヒ&#10;ナ&#10;ユ&#10;ヒ</span><b>ヌ</b></span><span class="glyph-column" style="--duration:3.5700000000000003s;--delay:-0.19s;--rest:63%" data-motion><span>タ&#10;リ&#10;コ&#10;タ&#10;リ&#10;コ&#10;タ&#10;リ</span><b>ユ</b></span><span class="glyph-column" style="--duration:3.8600000000000003s;--delay:-1.805s;--rest:92%" data-motion><span>ク&#10;シ&#10;モ&#10;ク&#10;シ&#10;モ&#10;ク&#10;シ</span><b>ク</b></span><span class="glyph-column" style="--duration:4.15s;--delay:-3.42s;--rest:-44%" data-motion><span>メ&#10;キ&#10;ラ&#10;メ&#10;キ&#10;ラ&#10;メ&#10;キ</span><b>1</b></span><span class="glyph-column" style="--duration:4.4399999999999995s;--delay:-1.045s;--rest:-15%" data-motion><span>1&#10;ネ&#10;カ&#10;1&#10;ネ&#10;カ&#10;1&#10;ネ</span><b>ヤ</b></span><span class="glyph-column" style="--duration:2.7s;--delay:-2.66s;--rest:14%" data-motion><span>ヘ&#10;0&#10;ヌ&#10;ヘ&#10;0&#10;ヌ&#10;ヘ&#10;0</span><b>リ</b></span><span class="glyph-column" style="--duration:2.99s;--delay:-0.28500000000000003s;--rest:43%" data-motion><span>ヤ&#10;ツ&#10;ム&#10;ヤ&#10;ツ&#10;ム&#10;ヤ&#10;ツ</span><b>キ</b></span><span class="glyph-column" style="--duration:3.2800000000000002s;--delay:-1.9s;--rest:72%" data-motion><span>ヒ&#10;ナ&#10;ユ&#10;ヒ&#10;ナ&#10;ユ&#10;ヒ&#10;ナ</span><b>0</b></span><span class="glyph-column" style="--duration:3.5700000000000003s;--delay:-3.515s;--rest:101%" data-motion><span>リ&#10;コ&#10;タ&#10;リ&#10;コ&#10;タ&#10;リ&#10;コ</span><b>ナ</b></span><span class="glyph-column" style="--duration:3.8600000000000003s;--delay:-1.1400000000000001s;--rest:-35%" data-motion><span>シ&#10;モ&#10;ク&#10;シ&#10;モ&#10;ク&#10;シ&#10;モ</span><b>モ</b></span><span class="glyph-column" style="--duration:4.15s;--delay:-2.755s;--rest:-6%" data-motion><span>キ&#10;ラ&#10;メ&#10;キ&#10;ラ&#10;メ&#10;キ&#10;ラ</span><b>カ</b></span><span class="glyph-column" style="--duration:4.4399999999999995s;--delay:-0.38s;--rest:23%" data-motion><span>ネ&#10;カ&#10;1&#10;ネ&#10;カ&#10;1&#10;ネ&#10;カ</span><b>ム</b></span><span class="glyph-column" style="--duration:2.7s;--delay:-1.995s;--rest:52%" data-motion><span>0&#10;ヌ&#10;ヘ&#10;0&#10;ヌ&#10;ヘ&#10;0&#10;ヌ</span><b>タ</b></span><span class="glyph-column" style="--duration:2.99s;--delay:-3.61s;--rest:81%" data-motion><span>ツ&#10;ム&#10;ヤ&#10;ツ&#10;ム&#10;ヤ&#10;ツ&#10;ム</span><b>メ</b></span><span class="glyph-column" style="--duration:3.2800000000000002s;--delay:-1.235s;--rest:-55%" data-motion><span>ナ&#10;ユ&#10;ヒ&#10;ナ&#10;ユ&#10;ヒ&#10;ナ&#10;ユ</span><b>ヘ</b></span><span class="glyph-column" style="--duration:3.5700000000000003s;--delay:-2.85s;--rest:-26%" data-motion><span>コ&#10;タ&#10;リ&#10;コ&#10;タ&#10;リ&#10;コ&#10;タ</span><b>ヒ</b></span><span class="glyph-column" style="--duration:3.8600000000000003s;--delay:-0.475s;--rest:3%" data-motion><span>モ&#10;ク&#10;シ&#10;モ&#10;ク&#10;シ&#10;モ&#10;ク</span><b>シ</b></span><span class="glyph-column" style="--duration:4.15s;--delay:-2.09s;--rest:32%" data-motion><span>ラ&#10;メ&#10;キ&#10;ラ&#10;メ&#10;キ&#10;ラ&#10;メ</span><b>ネ</b></span><span class="glyph-column" style="--duration:4.4399999999999995s;--delay:-3.705s;--rest:61%" data-motion><span>カ&#10;1&#10;ネ&#10;カ&#10;1&#10;ネ&#10;カ&#10;1</span><b>ツ</b></span></div>
    <div class="scene-copy"><h1>System online</h1></div>
      <button class="demo-button" type="button" data-loop-toggle data-testid="effect-demo-loop-toggle">Play demo</button>
    </div>
  </main>
  <script>
    const showcase = document.querySelector('.showcase');
    const toggle = showcase.querySelector('[data-loop-toggle]');
    const preference = matchMedia('(prefers-reduced-motion: reduce)');
    let playing = false;

    const columns = [...showcase.querySelectorAll('.glyph-column')];
    const alphabet = "01ラシタナヤヌネメモリユツヘカキクコヒム";
    let glyphTimer = null;

    function changeGlyphs() {
      for (let index = 0; index < 5; index++) {
        const column = columns[Math.floor(Math.random() * columns.length)];
        const trail = column.firstElementChild;
        const letters = trail.textContent.split('\n');
        const position = Math.floor(Math.random() * letters.length);
        letters[position] = alphabet.charAt(Math.floor(Math.random() * alphabet.length));
        trail.textContent = letters.join('\n');
        column.lastElementChild.textContent = alphabet.charAt(Math.floor(Math.random() * alphabet.length));
      }
    }

    function setScenePlayback(active) {
      clearInterval(glyphTimer);
      if (active) glyphTimer = setInterval(changeGlyphs, 145);
    }

    function syncPlayback() {
      if (preference.matches) playing = false;
      const active = playing && !document.hidden;
      showcase.toggleAttribute('data-playing', active);
      toggle.textContent = playing ? "Pause demo" : "Play demo";
      setScenePlayback(active);
    }

    toggle.addEventListener('click', () => {
      playing = !playing;
      syncPlayback();
    });
    preference.addEventListener('change', syncPlayback);
    document.addEventListener('visibilitychange', syncPlayback);
  </script>
</body>
</html>

Original example by UI Skills