
Woven thread background
Backgrounds, Hover
An animated background for the hero of a night train booking app: behind the heading the city seen from the window of a moving train, completely out of focus. Every light is a bokeh disc like through a real lens, with a brighter rim, faint rings inside, a warm fringe outside and a cool one inside, and toward the corners it squeezes into a cat's eye. Near lights are big and pass quickly, far ones are small and slow, the carriage sways a hair and now and then a catenary pole goes by. The pointer slowly moves the focus and the depth; booking the cabin the train brakes and the city comes into focus for a moment.
A folder that runs on its own: index.html, style.css, script.js and the libraries from a CDN. The React and Vue tabs hold the same demo as a ready component, which switches its animations off when it leaves the page.
<!doctype html>
<!--
"Night train background" from Animorio · https://animorio.com
License: free on your own sites and your clients’ sites, paid work included.
Not for resale, redistribution, templates or code collections · https://animorio.com/en/license/
-->
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Couchette</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
<link rel="stylesheet" href="style.css">
</head>
<body>
<!-- the hero of a night train booking app. Behind the heading a canvas draws the city at night seen through the
window of a moving train, completely out of focus: every light is a bokeh disc with a bright rim, a faint
onion-ring texture and a coloured fringe, squeezed into a cat's eye near the edges like through a real lens.
Near lights pass faster than far ones, the carriage sways a hair, a catenary pole crosses now and then.
The pointer moves the focus and the depth; booking a cabin slows the train and pulls the city into focus -->
<section class="stage" data-stage>
<canvas class="city" aria-hidden="true" data-canvas></canvas>
<div class="glass" aria-hidden="true" data-glass></div>
<div class="grain" aria-hidden="true" data-grain></div>
<header class="bar" data-in>
<span class="brand">
<svg class="brand__mark" viewBox="0 0 24 24" aria-hidden="true">
<path d="M15.6 4.2a8.2 8.2 0 1 0 4.2 11.4 6.6 6.6 0 0 1-4.2-11.4z"/>
<path d="M4.5 20.4h15"/>
</svg>
Couchette
</span>
<a class="bar__link" href="#">Sign in</a>
</header>
<div class="hero">
<a class="ticket" href="#" data-in>
<span class="ticket__when">Tonight</span>
<span class="ticket__leg">Paris <b>19:52</b></span>
<svg class="ticket__arrow" viewBox="0 0 22 10" aria-hidden="true"><path d="M1 5h19M16.5 1.6L20 5l-3.5 3.4"/></svg>
<span class="ticket__leg">Roma <b>09:30</b></span>
</a>
<h1 class="title" data-title><span class="title__line">Fall asleep in Paris.</span> <span class="title__line">Wake up in Rome.</span></h1>
<p class="lede" data-in>Private cabins on 140 night routes across Europe. Fresh sheets, a real bed, breakfast at the window.</p>
<div class="actions" data-in>
<button class="btn" type="button" data-btn>
<span class="btn__face">
<span class="btn__words" data-words>Book a cabin</span>
<svg class="btn__icon" viewBox="0 0 16 16" aria-hidden="true">
<path class="btn__arrow" data-arrow d="M3 8h9M8.5 4.2L12.3 8 8.5 11.8"/>
<path class="btn__check" data-check pathLength="1" d="M3.4 8.4l3 3 6.2-6.6"/>
</svg>
</span>
</button>
<a class="ghost" href="#" data-ghost><span class="ghost__shine" aria-hidden="true"></span><span class="ghost__words">See all routes</span></a>
</div>
</div>
<p class="hint" data-in>Move up and down to pull the focus</p>
<p class="sr" aria-live="polite" data-live></p>
</section>
<script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
<script src="script.js"></script>
</body>
</html>Change values, colours and text with the controls and watch the animation respond live. Or write in the code yourself. Then download the folder with your changes.
32 values to change
With the Animorio connector, Claude Code, ChatGPT, Cursor or VS Code take it from here, guide included, and fit it into your project. Paste this request:
Take “Night train background” from Animorio and fit it into my siteAt start each colour becomes a disc drawn pixel by pixel on a small canvas: a body slightly brighter toward the edge, a bright ring on the rim, the faint ‘onion’ rings of the lens and a light halo outside. Red sees a slightly wider disc and blue a slightly narrower one: hence the warm fringe outside and the cool one inside.
Each light has a depth z from 0 (the far city) to 1 (the lamps by the track). The disc's radius grows with the distance from the focus plane, and the bigger the disc the fainter it is. The focus plane turns slowly toward its goal, like a real focus ring.
The lights sit on a strip wider than the page that repeats: each slides at a speed that grows with z, so near ones pass quickly and far ones almost stand still. The discs add up with globalCompositeOperation lighter, like real light.
Toward the corners each disc is squeezed along the line to the middle, with a single setTransform per light. The carriage sways on two slow sines, far lights twinkle, a catenary pole passes every four to seven seconds as a dark band, the grain jumps 24 times a second.
The pointer high up brings the focus to the far city, sideways it shifts the layers in parallax, always with a slow chase. Pressing ‘Book a cabin’ a GSAP timeline brakes the train, brings the city into focus, lights the glow under the button and then melts it all again.
| Name | File | Default | What it changes |
|---|---|---|---|
BLUR | script.js | 1 | How out of focus the city is at rest: 0.4 almost sharp, 1.6 only big soft discs. |
LIGHTS | script.js | 74 | How many lights pass behind the window. |
SPEED | script.js | 1 | How fast the train runs: 0 stopped in a station, 2 twice as fast. |
CAT_EYE | script.js | 0.32 | How much the discs squeeze toward the corners, like through a real lens (0 all round). |
BRIGHTNESS | script.js | 1 | How bright the lights are. |
POLES | script.js | true | A catenary pole passes now and then. |
GRAIN | script.js | 0.07 | How strong the grain is. |
LOOP | script.js | true | Repeats the booking with the focus pull on its own. |
As the background of the first screen of a travel site, night trains, a city hotel, a festival or an evening venue, a late-night music app: wherever a soft night mood is needed behind a clear heading. The light colours are --sodium, --warm, --ice and --signal in the CSS.
The same animations at adapted sizes: the discs are measured on the shorter side, on tall screens the city rises higher up the window, the heading is measured on width and height. With a finger, dragging up and down moves the focus.
The city stays still, out of focus, and fades in; no sway, no poles. Pressing the button the glow lights up softly and the label and checkmark change with a fade.
GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.
Compressed with gzip, the three demo files weigh 10 KB; the libraries: GSAP 28 KB.
Tested on 2 November 2026
Use it in your own projects and in your clients’ projects. Do not resell it or redistribute it as is. GSAP stays under its own Standard license. Full license.
Support Animorio
Animorio stays free thanks to the people who support it. If you like, buy us a coffee: it helps us make the next animations.
You asked for
We made it for you: it’s in the library, with the preview, the Playground and the code to copy.
An animation you can’t find, or a site to take apart in the journal: tell us which. We pick the next ones from here.
With your account’s email and password.
or with your email
You’re signed in as .
With your account, you can download the zip of every animation and every pack, for free.