AI CSS Animations

Color Morph Gradient Text

The two ends of a gradient fade between colors in place instead of sliding. Each end is a registered color property with its own keyframe, half a cycle apart, so the blend keeps changing.

Also known as: animate gradient colors css, gradient color transition, @property gradient animation.

Always Evolving

HTML

<div class="txt-color-morph-text">Always Evolving</div>

CSS

@property --txt-color-morph-text-from {
  syntax: "<color>";
  inherits: false;
  initial-value: #3b82f6;
}
@property --txt-color-morph-text-to {
  syntax: "<color>";
  inherits: false;
  initial-value: #a855f7;
}
.txt-color-morph-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: 800;
  --txt-color-morph-text-from: var(--c);
  --txt-color-morph-text-to: color-mix(in srgb, var(--c) 40%, #a855f7);
  background: linear-gradient(90deg, var(--txt-color-morph-text-from), var(--txt-color-morph-text-to));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  animation:
    txt-color-morph-text-a 6s ease-in-out infinite,
    txt-color-morph-text-b 6s ease-in-out -3s infinite;}
@keyframes txt-color-morph-text-a {
  0%, 100% { --txt-color-morph-text-from: var(--c); }
  33%      { --txt-color-morph-text-from: color-mix(in srgb, var(--c) 35%, #ec4899); }
  66%      { --txt-color-morph-text-from: color-mix(in srgb, var(--c) 35%, #14b8a6); }
}
@keyframes txt-color-morph-text-b {
  0%, 100% { --txt-color-morph-text-to: color-mix(in srgb, var(--c) 40%, #a855f7); }
  33%      { --txt-color-morph-text-to: color-mix(in srgb, var(--c) 30%, #22d3ee); }
  66%      { --txt-color-morph-text-to: color-mix(in srgb, var(--c) 35%, #f43f5e); }
}

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