Starfield background for a website
A field of stars that drifts toward you, or stretches into warp streaks, behind your headline. Here is how the effect works, a canvas starter you can paste and run, and the skills that build a finished space hero.
Free skills to start. Pro is $79 a year for every skill, or $9.99 a month for 10. See pricing
What is a starfield background?
A starfield background is a dark page covered in points of light that move as if you were flying through them. Near stars are bigger, brighter and faster; far ones barely move. That difference in speed is what makes a flat screen read as deep space.
It suits launch pages, games, astronomy and anything that wants to feel vast or fast. The quiet version is a slow drift behind the copy. The loud version is the jump to lightspeed, where every star stretches into a streak racing out of the middle of the screen.
How the effect works
Each star is a point in 3D: an x and y between -1 and 1, and a depth z between 0 (at your nose) and 1 (far away). Every frame, z gets a little smaller, so the star comes closer. To draw it, divide x and y by z. That one division is the whole perspective trick: as z shrinks, the star slides away from the center and grows.
When a star passes the camera, send it back to the far end with a new random x and y. The field never runs out, and since stars are recycled, a few hundred points are enough for a full screen.
01
Place stars in a box
Random x and y in -1 to 1 and a random depth z in 0 to 1, so the field starts already full instead of filling from the middle.
02
Move them by time, not frames
Subtract speed × seconds from z each frame. A 144 Hz screen and a 60 Hz one then fly at the same speed.
03
Project to the screen
Screen position = center + (x / z) × scale. Size and brightness grow as z falls, so near stars pop.
04
Streak for warp
For the lightspeed look, draw a line from where the star was last frame to where it is now. At high speed the lines become the tunnel.
HTML
A canvas starfield in plain JavaScript
About 600 stars on a 2D canvas, sized for sharp screens and paused for reduced motion. Raise SPEED for a faster drift.
<canvas id="stars" style="position:fixed;inset:0;width:100%;height:100%;background:#05060a"></canvas>
<script>
const canvas = document.getElementById('stars')
const g = canvas.getContext('2d')
const N = 600, SPEED = 0.12 // depth units per second
const still = matchMedia('(prefers-reduced-motion: reduce)').matches
let w, h
function size() {
w = canvas.width = innerWidth * devicePixelRatio
h = canvas.height = innerHeight * devicePixelRatio
}
size(); addEventListener('resize', size)
const rand = () => Math.random() * 2 - 1
const stars = Array.from({ length: N }, () => ({ x: rand(), y: rand(), z: Math.random() }))
let last = performance.now()
function frame(now) {
const dt = Math.min(0.05, (now - last) / 1000); last = now
g.fillStyle = '#05060a'; g.fillRect(0, 0, w, h)
const scale = Math.max(w, h) / 2
for (const s of stars) {
if (!still) s.z -= SPEED * dt
if (s.z <= 0.02) { s.x = rand(); s.y = rand(); s.z = 1 }
const px = w / 2 + (s.x / s.z) * scale * 0.5
const py = h / 2 + (s.y / s.z) * scale * 0.5
const r = (1 - s.z) * 1.8 * devicePixelRatio
g.globalAlpha = 1 - s.z
g.fillStyle = '#fff'
g.beginPath(); g.arc(px, py, r, 0, Math.PI * 2); g.fill()
}
g.globalAlpha = 1
if (!still) requestAnimationFrame(frame)
}
requestAnimationFrame(frame)
</script>A starting point written for this page, free to use in your own projects. The skills below build the finished version with checks, fallbacks and a recorded video.
What to get right on a real page
01
Keep the copy readable
Stars behind a headline flicker against the letters. Dim or thin the field where the text sits, or put the field to one side of it.
02
Size the canvas for the screen
Multiply the canvas size by devicePixelRatio, or the stars turn into soft blobs on phones and Retina screens.
03
Stop when nobody is looking
Respect prefers-reduced-motion: show one finished frame instead of the loop. A visitor who turned motion off still gets the look.
04
Give it a still fallback
If the script fails, a blank black hero looks broken. A static image of the same field keeps the page whole.
Skills that build a starfield background
Both build a finished hero section around the effect, with your headline, colors, fonts and buttons, and record a 1080p video of it for launch posts.
- Starfield Warp HeroClaude CodeCodexCursor+3 more agents
Motion Heroes · Pro
Starfield Warp Hero
Animated WebGL hero · page + embed + 1080p video
The jump to lightspeed: a calm starfield with a ringed planet, then stars stretch into streaks out of a vanishing point, a flash and a ring mark the drop-out, and the planet swings back in, every 12 seconds. A readout under the copy follows the jump.
Worth knowing: The build only accepts a near-black background.
Needs: Node.js 18+, Chrome (or Chromium/Edge), and ffmpeg for the video
See what Starfield Warp Hero makes - Constellation Map HeroClaude CodeCodexCursor+3 more agents
Motion Heroes · Pro
Constellation Map Hero
Animated canvas hero · page + embed + 1080p video
The quiet version: an engraved star chart of twinkling stars, a soft Milky Way and a slowly turning grid, with up to six constellations you name drawing themselves one by one, then a meteor.
Worth knowing: The stars are generated, not real sky positions, and the chart does not pan or zoom.
Needs: Node.js 18+, Chrome (or Chromium/Edge), and ffmpeg for the video
See what Constellation Map Hero makes
Install
Build a starfield background with your agent
Each skill is a SKILL.md folder, so it installs the same way in Claude Code, Codex, Cursor and other agents. The example below uses Starfield Warp Hero; each skill page has its own prompt.
1. Paste the install prompt
Your agent runs the installer. The first time, it shows a sign-in link so you can approve it in the browser.
Install the "Starfield Warp Hero" skill from Lookbk (https://lookbk.dev/skills/starfield-warp-hero). 1. Run: curl -fsSL https://lookbk.dev/cli.js | node - add starfield-warp-hero 2. If it prints a sign-in link, show it to me. When I say I approved it, run the same command again. 3. When the install finishes, read the SKILL.md it installed and tell me what you need from me to make the first result.
Or run it in a terminal
curl -fsSL https://lookbk.dev/cli.js | node - add starfield-warp-hero2. Start a new session
Agents load skills when a session starts. The installer writes the folder where your agent looks:
- Claude Code
- ~/.claude/skills/starfield-warp-hero
- Codex
- ~/.agents/skills/starfield-warp-hero
- Cursor
- ~/.agents/skills/starfield-warp-hero
3. Ask for the result
Describe it in plain words, for example:
Build a Starfield Warp hero for Kestrel Edge, our edge network: violet streaks on blue-black, a ringed gas giant, headline 'Deploys that jump, not crawl.', a readout counting up to 212 regions live, and record the launch video.
Another agent? Install a skill in any agent
FAQ
Questions
Still stuck? The guides cover installing, agents and licensing in more detail.
Read the guidesHow do I make a starfield background in CSS only?
Stack two or three layers of tiny radial-gradient dots at different sizes and move each layer with a keyframe at a different speed. It gives a parallax drift but not the fly-through depth, which needs per-star perspective in canvas or WebGL.
Is a canvas starfield heavy on phones?
A few hundred stars on a 2D canvas is light. Cost comes from huge canvases and long trails, so cap the device pixel ratio at 2 and stop the loop when the hero scrolls out of view.
How do I make the warp speed effect?
Raise the speed over a second or two and draw each star as a line from its previous screen position to its current one. Fade the lines from white at the head to your brand color at the tail.
Can I use the starfield as a video background instead?
Yes. Starfield Warp Hero and Constellation Map Hero both record a seamless 1080p MP4 and a poster, so you can post the same loop on social or use it where scripts are not allowed.

