Back to library
INTERACTION_090

Button Loading Transition.

The label collapses into a compact progress indicator. The label visible at full width before the trigger; fading the label out, shrinking the button to a fixed width and revealing the indicator once the submit action starting.

CATEGORY
Buttons
COMPLEXITY
Intermediate
TECH
CSS
PLATFORM
Both
PERFORMANCE
Light
LIVE PLAYGROUND
CSS / CSS
/* Button Loading Transition — The label collapses into a compact progress indicator. */
.button-loading-transition {
  --dur: 320ms;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --stagger: 60ms;
  will-change: transform, opacity;
}

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

/* the label visible at full width -> fading the label out, shrinking the button to a fixed width and revealing the indicator */
@keyframes button-loading-transition-in {
  to {
    opacity: 1;
    transform: none;
    filter: none;
  }
}

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

/** Button Loading Transition — trigger: the submit action starting */
export function ButtonLoadingTransition({ 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="button-loading-transition" data-state="out">
      {children}
    </div>
  );
}

IF YOU LIKE THIS, STEAL THESE TOO.

Animated border
INTERACTION_083CSS

Animated Border Button

A light segment travels around the border on hover.

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