AI CSS Animations

Sparkle Text Effect

Four-point stars pop and spin over a gradient word, one after another, like a magic label. Each star is a clip-path shape with its own position and negative delay set inline.

Also known as: twinkle text css, magic sparkle text, sparkling stars text.

Brand new

HTML

<div class="txt-sparkle-text">Brand new<span class="txt-sparkle-text-stars" aria-hidden="true">
  <i style="--x: 3%; --y: 22%; --d: 0s; --s: 0.8"></i>
  <i style="--x: 24%; --y: 88%; --d: -1.2s; --s: 1"></i>
  <i style="--x: 45%; --y: 6%; --d: -0.6s; --s: 1.2"></i>
  <i style="--x: 68%; --y: 84%; --d: -1.5s; --s: 0.9"></i>
  <i style="--x: 86%; --y: 14%; --d: -0.3s; --s: 1.1"></i>
  <i style="--x: 99%; --y: 66%; --d: -0.9s; --s: 0.7"></i>
</span></div>

CSS

.txt-sparkle-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;
  position: relative;
  display: inline-block;
  background: linear-gradient(90deg, var(--c), color-mix(in srgb, var(--c) 55%, #a855f7));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;}
.txt-sparkle-text-stars {
  position: absolute;
  inset: -0.25em -0.2em;
  pointer-events: none;
}
.txt-sparkle-text-stars i {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: calc(0.6em * var(--s));
  height: calc(0.6em * var(--s));
  margin: calc(-0.3em * var(--s));
  background: radial-gradient(circle, #fff 0 9%, color-mix(in srgb, var(--c) 45%, #fff) 20%, color-mix(in srgb, var(--c) 60%, #a855f7) 42%);
  clip-path: polygon(50% 0, 60% 40%, 100% 50%, 60% 60%, 50% 100%, 40% 60%, 0 50%, 40% 40%);
  transform: scale(0);
  animation: txt-sparkle-text-twinkle 1.8s cubic-bezier(0.3, 0, 0.3, 1) infinite;
  animation-delay: var(--d);
}
@keyframes txt-sparkle-text-twinkle {
  0%, 55%, 100% { transform: scale(0) rotate(0deg); }
  22%           { transform: scale(1) rotate(70deg); }
  35%           { transform: scale(0.85) rotate(100deg); }
}

@media (prefers-reduced-motion: reduce) {
  .txt-sparkle-text, .txt-sparkle-text *, .txt-sparkle-text::before, .txt-sparkle-text::after, .txt-sparkle-text *::before, .txt-sparkle-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