Skip to content
animorio
IT
Back to the library

Starfield background

Backgrounds, HoverCanvas, GSAP, CSS onlyMediumCompressed weight: Demo 7.2 KBGSAP 28 KBFreeDownload the zip

An animated background for a product’s hero, on blue-black, in the style of Libraries.dev: a field of thin stars flying towards you, each star a segment that stretches as it comes closer. The pointer moves the vanishing point on a spring; holding it down the stars speed up into streaks of light with a blue tail, and letting go they slow down and settle, while the headline steps back a hair and returns.

The code

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>
<!--
  "Starfield 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>The background of stars flying behind the headline</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 an invented deploy platform, Skylane, on near black: behind the words a field of thin stars flies
       towards you. The pointer moves the vanishing point on a spring; holding the pointer down the stars speed up into
       streaks of light, and letting go they slow down again -->
  <main class="stage" data-stage>
    <canvas class="sky" data-sky aria-hidden="true"></canvas>
    <span class="hush" aria-hidden="true"></span>

    <section class="hero" aria-labelledby="hero-title">
      <p class="pill" data-in>
        <span class="pill__tag">Beta</span>
        <span class="pill__text">Edge deploys in 0.8 s</span>
        <svg class="pill__arrow" viewBox="0 0 16 16" aria-hidden="true"><path d="M6 3.5 10.5 8 6 12.5"></path></svg>
      </p>
      <h1 class="title" id="hero-title" data-in data-title>Go live at the<br>speed of light</h1>
      <p class="lede" data-in>Skylane ships every commit to 312 edge regions before you let go of the key.</p>
      <div class="actions" data-in>
        <button class="cta" type="button" data-cta>
          <span class="cta__beam" aria-hidden="true"></span>
          <span class="cta__label">Start deploying</span>
          <svg class="cta__arrow" viewBox="0 0 16 16" aria-hidden="true"><path d="M3 8h9.5M8.5 4 12.5 8l-4 4"></path></svg>
        </button>
        <span class="note">No card required</span>
      </div>
    </section>

    <p class="hint" data-hint>
      <svg viewBox="0 0 16 16" aria-hidden="true"><path d="M8 2.5v7.2M5.2 7l2.8 2.9L10.8 7"></path><path d="M3 13.5h10"></path></svg>
      <span data-hint-text>Hold anywhere to warp</span>
    </p>

    <svg class="ghost" data-ghost viewBox="0 0 20 20" aria-hidden="true"><path d="M4 2.5v13.2l3.5-3.3 2.4 5.3 2.3-1-2.4-5.2 4.8-.2z"></path></svg>
  </main>

  <script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
  <script src="script.js"></script>
</body>
</html>

Playground

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.

23 values to change

Or ask your AI assistant for it

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 “Starfield background” from Animorio and fit it into my site
Platform licenseFree on your sites and your clients’ sites. Want it inside a website builder, a template platform or a client dashboard? There’s a license for agencies and platforms.

What it does

On blue-black there is the opening of Skylane, a made-up platform that ships websites: the Beta pill with Edge deploys in 0.8 s, the large headline Go live at the speed of light, a line of explanation and the light Start deploying button. Behind the words a field of thin stars flies: each one is a short segment that starts far away and dim near the vanishing point, lights up and stretches as it comes closer, and disappears past the edge; the near ones are brighter and thicker, a few slightly colder. On arrival the stars come in already launched and slow down to cruise. The vanishing point follows the pointer on a soft spring, with a hair of bounce: the field leans towards where you look. Holding down anywhere (or the space bar) the stars speed up to nine times and turn into streaks of light, with a blue tail and a white head; the headline steps back a hair and the line below dims, and at the bottom of the page Hold anywhere to warp becomes Release to cruise. Letting go, the stars slow down, go for a moment a little slower than cruise and settle, and the headline comes forward again with an elastic. A streak of light like a star crosses the button; pressed it squashes, comes back with an elastic and sends a short jump. A drawn pointer moves the sky, holds down for a jump, then goes to the button and presses it.

How it works

The stars in perspective

Each star has an x and y position around the axis and a depth z, from 1 (far) to almost zero. On every frame z shrinks with the speed, and the star is drawn where x and y divided by z, times the focal length, land from the vanishing point. When it passes the edge or comes too close it is born again far away, in a new place.

Segments, not dots

The tail is the same star a little further back in depth: the tail’s distance grows with the square of the speed. While cruising they are short dashes, in the jump, nine times faster, streaks almost twenty times longer. A star that is too short is stretched by hand towards the vanishing point to 2.4 pixels, so it never becomes a dot.

The jump and the return

The speed is the cruise times a multiplier, from 1 to WARP, driven by a boost value that GSAP takes to 1 in 0.9 s with power2.in while holding, and to 0 in 2.1 s with back.out on release: back.out takes it briefly below zero, so the stars go a little slower than cruise before they settle.

The vanishing point on a spring

The vanishing point chases its aim on a spring (stiffness 18, damping 6.2): the aim is the centre plus the pointer’s offset times SWAY. Without a pointer the aim drifts slowly a few points around the centre, so the field is never still.

Values to change

NameFileDefaultWhat it changes
STARSscript.js440How many stars are in the field.
SPEEDscript.js1How fast the stars fly while cruising (0 stops them).
WARPscript.js9How many times faster they go while holding down.
STREAKscript.js1How long the streaks are.
SWAYscript.js0.35How much the pointer moves the vanishing point (0 leaves it in the centre).
BEAMscript.js#8fb4ffThe colour of the streaks’ tail during the jump.
AUTO_PILOTscript.js3After how many seconds without a pointer the drawn one moves (0 never).

Try them in the Playground

When to use it

As the background of the first screen of a product about speed on a dark background: a platform for shipping websites, a network service, an app that promises to do things in a moment, the launch of something new. The stars sit behind the headline without covering it, and the jump when holding down is a small game people remember.

On phones

The same field at adapted sizes: the focal length follows the longer side, so on a narrow phone the stars leave from the top and the bottom and the headline goes on two smaller lines. A sliding finger moves the vanishing point, and holding it still on the screen makes the jump.

With reduced motion

The field stays still, like a photo: thin dashes already in place, no flight, no jump and no drawn pointer. The words only fade in.

Pitfalls

  • A far star projected with only the tail’s depth becomes shorter than a pixel, and with round caps it looks like a dot: it is stretched by hand towards the vanishing point to a minimum length.
  • The return with back.out takes the multiplier below zero: the speed has to be kept at zero at least, otherwise with a high WARP the stars would fly backwards.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

Compressed with gzip, the three demo files weigh 7.2 KB; the libraries: GSAP 28 KB.

Testing

Tested on 28 October 2026

  • Desktop: Done
  • Phone: Done
  • Reduced motion: Done
  • Safari on iPhone: To do

License

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.

All animations