AI CSS Animations

Galaxy Text Effect

Letters filled with a violet nebula tinted by your accent while three layers of stars drift past at different speeds. The parallax comes from tiled dot layers, each moving whole tiles.

Also known as: starfield text css, space text effect, night sky text.

Deep Space

HTML

<div class="txt-galaxy-text">Deep Space</div>

CSS

.txt-galaxy-text {
  --c: var(--txt-color, #3b82f6);
  font-size: var(--txt-size, 32px);
  font-family: system-ui, sans-serif;
  font-weight: 700;
  line-height: 1.2;
  font-weight: 900;
  letter-spacing: 0.02em;
  background:
    radial-gradient(circle, #fff 0 0.035em, transparent 0.06em) 0 0 / 0.7em 0.55em,
    radial-gradient(circle, rgb(255 255 255 / 0.7) 0 0.025em, transparent 0.045em) 0.3em 0.2em / 0.45em 0.4em,
    radial-gradient(circle, #fff 0 0.04em, rgb(254 249 195 / 0.5) 0.06em, transparent 0.11em) 0.5em 0.35em / 1.3em 0.9em,
    radial-gradient(ellipse 60% 90% at 25% 40%, color-mix(in srgb, var(--c) 35%, #ec4899), transparent 70%),
    radial-gradient(ellipse 50% 90% at 80% 60%, color-mix(in srgb, var(--c) 35%, #a855f7), transparent 70%),
    linear-gradient(120deg, color-mix(in srgb, var(--c) 50%, #1e1b4b), color-mix(in srgb, var(--c) 45%, #312e81));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  animation: txt-galaxy-text-drift 8s linear infinite;}
@keyframes txt-galaxy-text-drift {
  to { background-position: -1.4em 0, -0.15em 0.2em, -2.1em 0.35em, 0 0, 0 0, 0 0; }
}

@media (prefers-reduced-motion: reduce) {
  .txt-galaxy-text, .txt-galaxy-text *, .txt-galaxy-text::before, .txt-galaxy-text::after, .txt-galaxy-text *::before, .txt-galaxy-text *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --txt-color on the element or a parent. Currently previewing #3b82f6.
  • Font size: set --txt-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 40px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar text animations