AI CSS Animations

Arrow Button

A pill with a round arrow chip at its end. Every few seconds the arrow pulls back, shoots out of the chip and a fresh one slides in behind it. Two arrows on one track, clipped by the chip.

Also known as: css button with arrow, next button css, arrow button animation.

HTML

<button class="btn-arrow-loop" type="button">
  Continue
  <span class="btn-arrow-loop-chip" aria-hidden="true">
    <span class="btn-arrow-loop-track">
      <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14M13 6l6 6-6 6"/></svg>
      <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14M13 6l6 6-6 6"/></svg>
    </span>
  </span>
</button>

CSS

.btn-arrow-loop {
  --c: var(--btn-color, #3b82f6);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  padding: 0.75em 1.6em;
  border: 0;
  border-radius: 0.6em;
  font: 600 var(--btn-size, 18px)/1.1 system-ui, sans-serif;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  gap: 0.9em;
  padding: 0.35em 0.35em 0.35em 1.4em;
  border-radius: 2em;
  background: var(--c);
  color: #fff;
  transition: transform 0.2s ease, background-color 0.25s ease;}
.btn-arrow-loop-chip {
  display: block;
  overflow: hidden;
  width: 2.3em;
  height: 2.3em;
  border-radius: 50%;
  background: #fff;
  color: var(--c);
}
.btn-arrow-loop-track {
  display: flex;
  width: 4.6em;
  transform: translateX(-2.3em);
  animation: btn-arrow-loop-go 2.8s infinite;
}
.btn-arrow-loop-track svg {
  display: block;
  flex: none;
  width: 2.3em;
  height: 2.3em;
  padding: 0.6em;
}
.btn-arrow-loop:is(:hover, :focus-visible) { background-color: color-mix(in srgb, var(--c) 85%, #000); }
.btn-arrow-loop:active { transform: scale(0.96); }
@keyframes btn-arrow-loop-go {
  0%        { transform: translateX(-2.3em); animation-timing-function: cubic-bezier(0.4, 0, 0.6, 1); }
  10%       { transform: translateX(-2.6em); animation-timing-function: cubic-bezier(0.7, 0, 0.2, 1); }
  38%, 100% { transform: translateX(0); }
}

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

Customizing this snippet

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