Back to library
INTERACTION_099

Card To Modal Transition.

The card expands into a modal from its own position. The modal unmounted and the card in the grid before the trigger; animating the modal from the card's bounding rect to its final size once clicking the card.

CATEGORY
Cards
COMPLEXITY
Advanced
TECH
CSS + JS
PLATFORM
Both
PERFORMANCE
Medium
LIVE PLAYGROUND
CSS / CSS
/* Card To Modal Transition — The card expands into a modal from its own position. */
.card-to-modal-transition {
  --dur: 520ms;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --stagger: 60ms;
  will-change: transform, opacity;
}

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

/* the modal unmounted and the card in the grid -> animating the modal from the card's bounding rect to its final size */
@keyframes card-to-modal-transition-in {
  to {
    opacity: 1;
    transform: none;
    filter: none;
  }
}

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

/** Card To Modal Transition — trigger: clicking the card */
export function CardToModalTransition({ 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="card-to-modal-transition" data-state="out">
      {children}
    </div>
  );
}

IF YOU LIKE THIS, STEAL THESE TOO.

INTERACTION_104CSS

Comparison Card Transition

Two states swap inside the same card frame.

Cards / LightView
INTERACTION_093CSS

Expandable Card

A card grows in place to reveal its detail without a page change.

Cards / LightView
INTERACTION_096CSS

Glass Reflection Card

A soft reflection sweeps across the glass surface on hover.

Cards / LightView
INTERACTION_097CSS + JS

Cursor Reactive Card

The card content shifts subtly with pointer position.

Cards / LightView