AI CSS Animations

Arrow Sweep Button

The fill arrives with a pointed chevron leading edge, so the button itself seems to say 'this way'. The chevron is a clip-path polygon on a pseudo-element wider than the button.

Also known as: chevron fill button, pointed sweep hover, arrow fill hover.

HTML

<button class="hfx-arrow-sweep">Next step</button>

CSS

.hfx-arrow-sweep {
  --c: var(--hfx-color, #3b82f6);
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  padding: 0.75em 1.75em;
  border-radius: 0.5em;
  font: 600 var(--hfx-size, 16px)/1.2 system-ui, sans-serif;
  white-space: nowrap;
  cursor: pointer;
  border: 2px solid var(--c);
  background: transparent;
  color: var(--c);
  transition: color 0.25s ease 0.1s;
}
.hfx-arrow-sweep::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: -1;
  width: calc(100% + 1.4em);
  background: var(--c);
  clip-path: polygon(0 0, calc(100% - 1.4em) 0, 100% 50%, calc(100% - 1.4em) 100%, 0 100%);
  transform: translateX(-100%);
  transition: transform 0.45s cubic-bezier(0.65, 0, 0.35, 1);
}
.hfx-arrow-sweep:is(:hover, :focus-visible) {
  background-color: var(--c); /* hides the hairline where the fill meets the border */
  color: #fff;
  transition: color 0.25s ease 0.1s, background-color 0s 0.45s;
}
.hfx-arrow-sweep:is(:hover, :focus-visible)::before { transform: translateX(0); }

@media (prefers-reduced-motion: reduce) {
  .hfx-arrow-sweep, .hfx-arrow-sweep *, .hfx-arrow-sweep::before, .hfx-arrow-sweep::after, .hfx-arrow-sweep *::before, .hfx-arrow-sweep *::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