Atmosphere✨ Premium

Starfield

Pure CSS 3D starfield — each star bursts from the center via perspective and a randomized animation duration, simulating a lightspeed journey.

JSSpace

You'll get access to the interactive demo with a free account.

This effect is part of Effect.Labs — 811 vanilla effects, some free, some premium. Atmosphere has 57 effects, including 10 free. Explore the category →

3 usage examples

Hero / Landing — Space or tech product homepage — Starfield example 1

① Hero / Landing — Space or tech product homepage

WhenThe landing page of an astronomy app, a space game, or a futuristic tech SaaS, loaded on the visitor's first impression.
WhyThe starfield sets the atmosphere instantly with no network request — pure CSS, zero images. The infinite radial stream adds depth without competing with the main headline.
Settings150–200 stars, durations 1.5 s–4 s, perspective: 500px. Centered title with a semi-transparent scrim to guarantee WCAG AA contrast.
Loading screen — Full-screen spatial game or app — Starfield example 2

② Loading screen — Full-screen spatial game or app

WhenThe user launches a space game, astronomy app, or immersive experience — the loading screen occupies the full viewport for 2 to 5 seconds.
WhyAt full size, the radial stream is spectacular: stars burst from the center toward every edge, simulating lightspeed travel. This is exactly the format where the starfield is most impressive.
Settings160 stars, durations 1.2 s–3.0 s, perspective: 500px. Centered game title and progress bar — the starfield fills 100% of the surface with nothing to constrain it.
Conversion micro-interaction — Premium access confirmed — Starfield example 3

③ Conversion micro-interaction — Premium access confirmed

WhenThe user has just confirmed a paid plan — the success screen appears for 3–5 seconds before redirecting to the dashboard.
WhyThe spatial immersion reinforces the feeling of accessing a 'higher level'. The space theme associates the subscription with the infinite and the possible, positively anchoring the decision.
Settings120 stars, durations 1.2 s–2.5 s (higher perceived speed = momentum feel), perspective: 600px. Centered 'Premium activated' badge + CTA button with pointer-events: auto.

How it works

The effect relies entirely on CSS 3D transforms. The .starfield-container element carries perspective: 500px, establishing a central vanishing point. Each star is a <div class="star"> — a 2×2 px white circle in position: absolute — placed via inline left and top values clustered near the center.

The @keyframes starMove animation drives each star from translateZ(0) scale(0.1) to translateZ(500px) scale(2) in an infinite linear loop. Through the parent's perspective, this Z-axis motion creates the illusion of a distant star surging forward, growing, and vanishing off-screen. Opacity ramps from 0 to 1 between 0% and 10% of the cycle, then back to 0 between 90% and 100% — preventing a hard cut at loop restart.

Each star receives a distinct animation-duration via its inline style attribute (roughly 1.7 s to 3.5 s in the reference implementation). This duration offset, combined with slightly different starting positions, produces an asynchronous radial stream with no JavaScript involvement on the animation side. A negative animation-delay staggers each star's phase, avoiding a synchronized burst on first render.

The effect is 100% CSS for motion; stars must however be present in the DOM at initialization. In the reference implementation they are either hard-coded in HTML or generated by a short init script that creates <div class="star"> elements with random positions and durations via inline style. No requestAnimationFrame or canvas is used.

Accessibility

  • prefers-reduced-motion: the code includes no prefers-reduced-motion check — CSS animations run regardless of the user's OS motion preference. Fix: wrap all .star animation rules inside @media (prefers-reduced-motion: no-preference) { ... }.
  • The .starfield-container carries no role, aria-label, or aria-hidden in the source code. Add role="img" aria-label="Animated starfield" on the container and aria-hidden="true" on individual stars to make them transparent to screen readers.
  • The .starfield-text element uses rgba(255,255,255,0.5) on a black (#000) background — a contrast ratio of ~3.2:1, below WCAG AA (4.5:1) for normal text. Raise opacity to 0.85+ if the text conveys information.
  • The effect is purely decorative and has no keyboard interaction. If used as a background for a CTA, ensure the CTA itself is keyboard-focusable and meets contrast requirements.
  • Star <div> elements are empty and carry no semantics — screen readers naturally skip them, which is the expected behavior.

Browser compatibility

Requires CSS 3D transforms (perspective, translateZ, scale) and @keyframes — supported in all modern browsers. Zero JavaScript dependency for the animation.

Chrome 88+✓ Full
Firefox 87+✓ Full
Safari 15+✓ Full
Edge 88+✓ Full
Mobile iOS✓ Full
Android Chrome✓ Full

Without 3D transform support (very old browsers), stars remain visible and static at their initial position — no blocking errors, the page stays functional.

The code

HTML structure to paste into your page (CSS + JS available with a premium account):

index.html — structure
<div class="starfield-container" id="starfieldContainer" role="img" aria-label="Animated starfield — space journey">
  <!-- Stars: each div.star receives left, top, and animation-duration as inline styles.
       Generate 80–200 elements for a dense result. -->
  <div class="star" style="left: 268px; top: 178px; animation-duration: 2.4s;"></div>
  <!-- … repeat for each star … -->

  <!-- Optional text overlay -->
  <span class="starfield-text">Optional text</span>
</div>
🔒 Unlock the full code — from €2.99 the first month

Full HTML + CSS + JS, copy-paste ready — with hundreds of premium effects.

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
Number of div.star ~4 in the minimal example Adding <div class="star"> elements in the HTML (or via an init script) increases density. 80–200 stars give a dense, realistic result; below 30 the space looks empty.
animation-duration (inline) 1.7 s – 3.5 s (random per star) Short durations (1–2 s) = lightspeed feel; long durations (4–6 s) = slow drift. Greater variance makes the field feel more three-dimensional and natural.
perspective on .starfield-container 500px Lower (300 px) increases distortion and perceived speed; higher (800 px) gives softer motion. Edit the perspective: 500px line in the CSS.
translateZ in @keyframes starMove 0 → 500px Increasing the end value (e.g. 800 px) extends the visible trajectory — pair with a higher perspective to maintain perceived speed.
width / height on .star 2px × 2px 3–4 px for more visible stars; 1 px for a cosmic-dust feel. Adding box-shadow: 0 0 4px #fff creates a glow halo without changing the element's hit area.
background of .starfield-container #000 (pure black) A radial gradient (radial-gradient(ellipse at center, #0d1b2a 0%, #000 70%)) adds realistic depth and prevents the background from looking flat.
left / top on div.star Clustered near center (~W/2, ~H/2) The perspective vanishing point is at the container's center. Stars distributed within ~20% of the diagonal around center produce a balanced radial stream. Concentrating them further creates a narrower tunnel; spreading them out produces near-parallel streaks.

FAQ

The animation is 100% CSS (@keyframes, perspective, translateZ) — no JS is needed for movement. Stars must exist in the DOM, however. They can be hard-coded in HTML or generated by a short init script that creates <div class="star"> elements with random left, top, and animation-duration values in inline style attributes — a dozen lines are enough.
This is how CSS perspective works: the vanishing point defaults to the container's center (perspective-origin: 50% 50%). Stars positioned slightly around this center appear to streak outward as they advance along the Z axis, replicating a spacecraft's warp speed. To shift the vanishing point, change perspective-origin on .starfield-container.
Override the inline style on each <div class="star">: background: #a0d8ef for a cold blue tint, width: 3px; height: 3px to enlarge, or box-shadow: 0 0 3px 1px rgba(200,220,255,0.8) for a glow. Utility classes (e.g. star star--blue star--lg) let you define variants in the stylesheet without multiplying inline attributes.