AI CSS Animations

Gradient Shadow Text

Solid text in the page color sits on an offset copy filled with a flowing gradient, like a two-color screen print. The copy is a pseudo-element read from a data attribute.

Also known as: rainbow shadow text css, gradient drop shadow text, offset gradient text.

Stand Out

HTML

<div class="txt-gradient-shadow-text" data-text="Stand Out">Stand Out</div>

CSS

.txt-gradient-shadow-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;
  isolation: isolate;
  white-space: nowrap;
  font-weight: 900;
  letter-spacing: 0.02em;}
.txt-gradient-shadow-text::before {
  content: attr(data-text);
  content: attr(data-text) / "";
  position: absolute;
  inset: 0;
  z-index: -1;
  transform: translate(0.07em, 0.07em);
  background: linear-gradient(90deg, var(--c), color-mix(in srgb, var(--c) 30%, #ec4899), color-mix(in srgb, var(--c) 35%, #a855f7), color-mix(in srgb, var(--c) 30%, #22d3ee), var(--c)) 0 0 / 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  animation: txt-gradient-shadow-text-flow 3s linear infinite;
}
@keyframes txt-gradient-shadow-text-flow {
  to { background-position: 200% 0; }
}

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