Back to library
INTERACTION_083

Animated Border Button.

A light segment travels around the border on hover. A static 1px border at low contrast before the trigger; rotating a conic gradient behind a masked border once hover, or a slow loop for the single primary CTA.

CATEGORY
Buttons
COMPLEXITY
Intermediate
TECH
CSS
PLATFORM
Both
PERFORMANCE
Light
LIVE PLAYGROUND
Animated border
CSS / CSS
/* Animated Border Button — A light segment travels around the border on hover. */
.animated-border-button {
  --dur: 2.6s;
  --ease: linear;
  --stagger: 60ms;
  will-change: transform, opacity;
}

.animated-border-button > * {
  opacity: 0;
  transform: translateY(14px);
  animation: animated-border-button-in var(--dur) var(--ease) forwards;
  animation-delay: calc(var(--i, 0) * var(--stagger));
}

/* a static 1px border at low contrast -> rotating a conic gradient behind a masked border */
@keyframes animated-border-button-in {
  to {
    opacity: 1;
    transform: none;
    filter: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .animated-border-button > * {
    opacity: 1;
    transform: none;
    animation: none;
  }
}
React / TSX
import { useEffect, useRef } from "react";

/** Animated Border Button — trigger: hover, or a slow loop for the single primary CTA */
export function AnimatedBorderButton({ children }: { children: React.ReactNode }) {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current;
    if (!el) return;
    if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
      el.dataset["state"] = "in";
      return;
    }
    const io = new IntersectionObserver(
      ([entry]) => {
        if (entry?.isIntersecting) {
          el.dataset["state"] = "in";
          io.unobserve(el);
        }
      },
      { threshold: 0.2 },
    );
    io.observe(el);
    return () => io.disconnect();
  }, []);

  return (
    <div ref={ref} className="animated-border-button" data-state="out">
      {children}
    </div>
  );
}

IF YOU LIKE THIS, STEAL THESE TOO.

INTERACTION_090CSS

Button Loading Transition

The label collapses into a compact progress indicator.

Buttons / LightView
INTERACTION_003CSS + JS

Magnetic Button

Subtle cursor-following CTA interaction.

Buttons / LightView
INTERACTION_082CSS

Liquid Hover Button

A rounded fill rises from the bottom edge and floods the button.

Buttons / LightView
INTERACTION_084CSS + JS

Cursor Following Glow Button

A soft glow tracks the pointer inside the button surface.

Buttons / LightView