AI CSS Animations

Gradient Shift Button

A two-tone gradient slides across the button on hover by moving the background position. The second color is mixed from your accent, so it always matches.

Also known as: animated gradient button, gradient hover.

HTML

<button class="hfx-gradient-shift">Start free trial</button>

CSS

.hfx-gradient-shift {
  --c: var(--hfx-color, #3b82f6);
  font-size: var(--hfx-size, 16px);
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.7em 1.6em;
  border-radius: 0.5em;
  font: 600 1em system-ui, sans-serif;
  cursor: pointer;
  border: 0;
  color: #fff;
  background: linear-gradient(120deg, var(--c), color-mix(in srgb, var(--c) 55%, #ec4899), var(--c));
  background-size: 200% 100%;
  background-position: 0% 50%;
  transition: background-position 0.5s ease;}
.hfx-gradient-shift:hover { background-position: 100% 50%; }

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

Customizing this snippet

  • Color: set --hfx-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --hfx-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 16px.
  • 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 hover effects