Backgrounds✨ Premium

Star Field

100% CSS star field — five radial gradients in a 200 × 200 px tile drift diagonally via @keyframes background-position, with zero JavaScript.

CSSStarsSpace

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. Backgrounds has 50 effects, including 6 free. Explore the category →

3 usage examples

Full-screen hero — Astronomy application — Star Field example 1

① Full-screen hero — Astronomy application

WhenThe landing page of a sky-observation app opens — the user wants to plan a session or identify tonight's visible stars.
WhyThe CSS star field instantly anchors the product's universe and replaces a heavy asset (photo, video) with zero network cost. The slow animation (100 s) stays out of the way of the headline.
SettingsNo tweaks needed out of the box. Add a semi-transparent rgba(0,0,0,0.4) overlay layer to improve headline legibility; use #000218 as the base color for a blue-night tint.
Card component — Sky conditions widget — Star Field example 2

② Card component — Sky conditions widget

WhenAn astrophotography or stargazing dashboard shows a 'Tonight's conditions' card with seeing and atmospheric transparency data.
WhyThe CSS star field applies to a 300 × 200 px container with no JavaScript and no network request. The animation keeps running across multiple card instances with zero CPU overhead.
SettingsChange 100s to 200s in animation for imperceptible drift behind the card. Reduce background-size to 100px 100px to pack more stars into a small container.
Article header — Cosmology longform — Star Field example 3

③ Article header — Cosmology longform

WhenAn online magazine publishes a cosmology or space-exploration longform and wants an immersive header without loading a video or HD image.
WhyAt a 100-second cycle, the drift is imperceptible while reading. Network cost is zero (pure CSS), and the effect adapts to any page width without a single media query.
SettingsCap the header height at 240px. Add background-attachment: fixed to .bg-stars for a subtle parallax on page scroll. Use #020208 instead of #000 for a faint blue-night tint.

How it works

.bg-stars stacks five radial-gradient() layers in a single background property. Each layer creates a sharp star by placing a white dot (2 × 2 px, or 1 × 1 px for dimmer stars) at a fixed coordinate — at 20px 30px, at 40px 70px, at 90px 40px, at 130px 80px, at 160px 120px — with the remainder of the gradient fully transparent. No blur, no intentional anti-aliasing: each star is a surgical point of light.

The first layer carries background-size: 200px 200px: the browser tiles that square across the element's full surface, multiplying the star pattern indefinitely. @keyframes starsMove shifts background-position from 0 0 to -200px -200px — exactly one tile width and height — over 100 linear infinite seconds. As a star exits one edge, its twin in the adjacent tile enters from the opposite edge, producing a perfectly seamless loop with no visible jump.

Zero JavaScript, zero Canvas, zero dependencies: a single <div class="bg-stars"> and a CSS block are all you need. Compositing is handled by the browser's rendering engine (GPU layer on Chrome, Safari, and Firefox) — CPU load at runtime is near zero. Overlay content (.bg-label or any other element) sits in the normal DOM flow, layered above the animated background.

Accessibility

  • prefers-reduced-motion: not implemented. There is no @media (prefers-reduced-motion: reduce) block: the 100-second animation runs indefinitely even when the OS signals a reduced-motion preference. Recommendation: add @media (prefers-reduced-motion: reduce) { .bg-stars { animation: none; } } to your stylesheet.
  • .bg-stars carries no role or aria-label by default. For a purely decorative background this is acceptable; if the background carries narrative meaning, add role="img" and a descriptive aria-label.
  • Star / background contrast: white #fff dots on a black #000 background — ratio above 21:1, well above the WCAG AA threshold (4.5:1).
  • No interactive elements in the background itself: no keyboard trap, no tabindex, no mouse events. Keyboard navigation is not affected.
  • Overlay content (.bg-label) is in the standard DOM and remains readable by screen readers, independent of the animated CSS background.

Browser compatibility

Relies on CSS multiple backgrounds and CSS animations — supported in all modern browsers since ~2013. Zero external dependencies.

Chrome 26+✓ Full
Firefox 16+✓ Full
Safari 7+✓ Full
Edge 12+✓ Full
Mobile iOS 7+✓ Full
Android Chrome✓ Full

If <code>radial-gradient()</code> or <code>@keyframes</code> are not supported, the element displays its default background color (<code>#000</code>) — no JS errors, no broken dependencies.

The code

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

index.html — structure
<div class="bg-stars" role="img" aria-label="Continuously animated star field" style="position:relative;min-height:400px;">

  <!-- Optional: overlay text content (position:absolute required) -->
  <span class="bg-label">Your message</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
Animation duration (100s) 100s Cycle speed — edit 100s directly in the animation rule. 60 s = livelier, 200 s = barely perceptible drift.
background-size (200px 200px) 200px 200px Star tile size (first layer). 100px 100px doubles visible density; 400px 400px spreads stars apart for an emptier sky.
Star color (#fff) #fff Color of the dot in each radial-gradient. #aac8ff = cold blue stars, #ffeecc = warm tone, #c8ffc8 = sci-fi green.
Background color (#000) #000 Last value in the background shorthand. #000218 = deep blue night, #0a0014 = cosmic violet.
@keyframes to {} endpoint -200px -200px background-position travel endpoint. 0 -200px = pure vertical (stars rise), -200px 0 = pure horizontal, 200px -200px = reverse diagonal (top-right).
background-attachment scroll Add background-attachment: fixed to .bg-stars for a page-scroll parallax effect — stars drift slower than the page content.
Layer count (5) 5 gradients Add extra radial-gradient(1px 1px at Xpx Ypx, #fff, transparent), lines before the background color to place more stars per tile.

FAQ

Yes, the effect is 100% CSS: a single <div class="bg-stars"> and a CSS block are all you need. No npm dependency, no canvas, no JS file to load. Copy the class and the CSS rules into your stylesheet — framework-agnostic by design.
Not in the base version: there is no @media (prefers-reduced-motion: reduce) block. For accessible sites, add this rule to your CSS: @media (prefers-reduced-motion: reduce) { .bg-stars { animation: none; } }. The element then shows as a static star field with no movement.
Edit the endpoint in @keyframes starsMove { to { background-position: X Y } }. Useful values: 0 -200px = pure vertical (stars rise), -200px 0 = pure horizontal (stars slide left), 200px 200px = reverse diagonal (bottom-right). For a circular effect, combine two animations on separate axes with different durations.