中文
DEEP SPACE纯 CSS 星点飘动
Background & decoration · CSS only

Starfield particles

星空粒子飘动

Drift and softly pulse lightweight background stars with pure CSS and zero JavaScript.

Also searched as: 星空背景粒子漂浮, 深色背景星点闪烁, 轻量背景颗粒飘动, 只用CSS的星空装饰

AI Markdown (.md)
Placement
Background
Mood
Soft, Technical
Trigger
一直循环
Site types
品牌官网, 个人网站, 工具和应用

How it works & accessibility

Places aria-hidden dots inside an isolated stacking context and animates only translate and opacity via CSS keyframes with staggered delays; hides extra dots on narrow screens and pauses under reduced motion.

Best for: Background (一直循环).

Reduced motion: 关闭飘动和明暗呼吸动画,星点静止在原处作为静态底纹

Mobile & touch: 窄屏下自动隐藏部分星点(减少颗粒密度),仅动合成层属性保持流畅

Key parameters

ParameterKeyDefaultRangeNotes
一圈时长duration5000ms——
飘动幅度distance10px——

Ready-to-paste AI prompt

Add “Starfield particles” to the background in my project: Places aria-hidden dots inside an isolated stacking context and animates only translate and opacity via CSS keyframes with staggered delays; hides extra dots on narrow screens and pauses under reduced motion.
Parameters: duration: 5000ms, distance: 10px.
Preserve existing content and layout. Respect prefers-reduced-motion by showing the final state. Content must remain visible if JavaScript fails or is disabled.
Reference: https://donglang.linter.top/effects/starfield.md (canonical specification and reference code).

Dependency-free reference code

CSS
/* 星空粒子飘动(Starfield particles)· 只用 CSS,不需要脚本。 */
:where(.stf) {
  --stf-duration: 5000ms;
  --stf-distance: 10px;
  --stf-color: currentColor;
  position: relative;
}

.stf {
  isolation: isolate;
}

.stf-dots {
  position: absolute;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.stf-dots > i {
  position: absolute;
  border-radius: 50%;
  background: var(--stf-color);
  animation: stf-drift var(--stf-duration) ease-in-out infinite;
}

.stf-dots > i:nth-child(2) { animation-delay: calc(var(--stf-duration) * 0.16); }
.stf-dots > i:nth-child(3) { animation-delay: calc(var(--stf-duration) * 0.32); }
.stf-dots > i:nth-child(4) { animation-delay: calc(var(--stf-duration) * 0.48); }
.stf-dots > i:nth-child(5) { animation-delay: calc(var(--stf-duration) * 0.64); }
.stf-dots > i:nth-child(6) { animation-delay: calc(var(--stf-duration) * 0.80); }

:where(.stf-dots > i:nth-child(1)) { left: 12%; top: 24%; width: 4px; height: 4px; }
:where(.stf-dots > i:nth-child(2)) { left: 28%; top: 72%; width: 5px; height: 5px; }
:where(.stf-dots > i:nth-child(3)) { left: 48%; top: 18%; width: 3px; height: 3px; }
:where(.stf-dots > i:nth-child(4)) { left: 68%; top: 68%; width: 5px; height: 5px; }
:where(.stf-dots > i:nth-child(5)) { left: 82%; top: 28%; width: 4px; height: 4px; }
:where(.stf-dots > i:nth-child(6)) { left: 90%; top: 78%; width: 3px; height: 3px; }

@keyframes stf-drift {
  0%, 100% {
    translate: 0 0;
    opacity: 0.35;
  }
  50% {
    translate: 0 calc(var(--stf-distance) * -1);
    opacity: 0.95;
  }
}

@media (max-width: 720px) {
  .stf-dots > i:nth-child(n + 5) {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stf-dots > i {
    animation: none;
    opacity: 0.5;
  }
}
HTML
<section class="stf" style="padding:48px;background:#141519;color:#ffffff;border-radius:14px;">
  <span class="stf-dots" aria-hidden="true">
    <i></i><i></i><i></i><i></i><i></i><i></i>
  </span>
  <h2>星空背景区</h2>
  <p>细小星点在文字下方缓缓飘动。</p>
</section>

More in Background & decoration

Browse all 86 effects →

Shown once per release · Always available in changelog