A card with a soft glow that tracks the pointer across its surface.
A two-sided card that turns over in 3D on hover or click, with a sheen that sweeps across and a slight lift as it goes edge-on.
Customize
Usage
import { FlipCard } from "@/components/motionkit/flip-card";
<FlipCard
label="Ada Lovelace, team card"
front={<img src="/team/ada.jpg" alt="Ada Lovelace" className="size-full object-cover" />}
back={<p className="p-6 text-sm">Ten years designing motion systems…</p>}
/>Motion
The exact curves this component runs, plotted with Motion's own maths.
Card turns over
Hover or click
Team bios, feature reveals, flashcards and quizzes, pricing details, and before/after or question/answer pairs.
Both faces sit in one element with preserve-3d, the back already turned 180 degrees with its backface hidden. A spring drives the rotation, and two transforms of it add a sheen that sweeps across and a 6% lift at the edge-on moment. The face that's turned away is marked inert, so it can't be tabbed into or read. With reduced motion on, the faces cross-fade instead.
Works in the App Router as is. Requires Tailwind CSS v4.
One command adds the file and installs its dependencies. Needs a components.json (run npx shadcn@latest init once if you don't have one).
npx shadcn@latest add https://www.motionkitui.com/r/flip-card.jsonnpm install motionSave as components/motionkit/flip-card.tsx.
"use client";
import { useState, type KeyboardEvent, type ReactNode } from "react";
import { motion, useMotionValue, useReducedMotion, useSpring, useTransform } from "motion/react";
type FlipCardProps = {
front?: ReactNode;
back?: ReactNode;
/** "hover" flips on hover and focus; "click" flips on click, Enter or Space, and stays flipped. */
trigger?: "hover" | "click";
/** Turn around the vertical axis (side to side) or the horizontal one (top over bottom). */
direction?: "horizontal" | "vertical";
/** Describes the card for screen readers when it flips on click, e.g. "Ada Lovelace, team card". */
label?: string;
className?: string;
};
function DefaultFront() {
return (
<div className="flex h-full flex-col justify-between bg-[radial-gradient(circle_at_25%_20%,#2E9098,#0B6770_45%,#073E45)] p-6">
<span className="text-xs font-medium uppercase tracking-[0.2em] text-[#C5E3E5]">Design lead</span>
<div>
<p className="text-2xl font-semibold text-[#F6F1E8]">Ada Lovelace</p>
<p className="mt-1 text-sm text-[#C5E3E5]">Flip for more</p>
</div>
</div>
);
}
function DefaultBack() {
return (
<div className="flex h-full flex-col justify-between bg-[#141B1B] p-6">
<p className="text-sm leading-6 text-[#DCE3E2]">Ten years designing motion systems for products people use every day. Thinks every interface deserves a little delight.</p>
<p className="text-xs uppercase tracking-[0.2em] text-[#94A9A7]">London · since 2016</p>
</div>
);
}
/**
* A card with two faces that turns over in 3D, on hover or on click. A sheen sweeps across as it turns and the card
* lifts a little at the halfway point, so it reads as a real object. The hidden face is inert, so keyboard focus and
* screen readers only ever reach the side you can see. With reduced motion on, the faces cross-fade instead.
*/
export function FlipCard({ front = <DefaultFront />, back = <DefaultBack />, trigger = "hover", direction = "horizontal", label = "Card", className = "" }: FlipCardProps) {
const reduceMotion = useReducedMotion();
const [flipped, setFlipped] = useState(false);
const target = useMotionValue(0);
const angle = useSpring(target, { stiffness: 170, damping: 22, mass: 1 });
// a sheen that sweeps across, and a lift that peaks when the card is edge-on
const sheen = useTransform(angle, [0, 90, 180], ["-60%", "40%", "160%"]);
const lift = useTransform(angle, [0, 90, 180], [1, 1.06, 1]);
const axis = direction === "horizontal" ? "rotateY" : "rotateX";
function set(next: boolean) {
setFlipped(next);
target.set(next ? 180 : 0);
}
const hoverProps = trigger === "hover" ? { onPointerEnter: () => set(true), onPointerLeave: () => set(false), onFocus: () => set(true), onBlur: () => set(false) } : {};
const clickProps =
trigger === "click"
? {
role: "button",
"aria-pressed": flipped,
"aria-label": `${label}, ${flipped ? "showing back" : "showing front"}`,
onClick: () => set(!flipped),
onKeyDown: (event: KeyboardEvent) => {
if (event.key !== "Enter" && event.key !== " ") return;
event.preventDefault();
set(!flipped);
},
}
: {};
const face = "absolute inset-0 overflow-hidden rounded-3xl border border-white/10 [backface-visibility:hidden]";
if (reduceMotion) {
return (
<div tabIndex={0} {...hoverProps} {...clickProps} className={`relative h-72 w-56 cursor-pointer rounded-3xl outline-none focus-visible:ring-2 focus-visible:ring-[#B9C7FF] focus-visible:ring-offset-4 focus-visible:ring-offset-[#0C1010] ${className}`}>
<motion.div className={face} animate={{ opacity: flipped ? 0 : 1 }} inert={flipped}>
{front}
</motion.div>
<motion.div className={face} initial={false} animate={{ opacity: flipped ? 1 : 0 }} inert={!flipped}>
{back}
</motion.div>
</div>
);
}
return (
<div
tabIndex={0}
{...hoverProps}
{...clickProps}
className={`relative h-72 w-56 cursor-pointer rounded-3xl outline-none [perspective:1100px] focus-visible:ring-2 focus-visible:ring-[#B9C7FF] focus-visible:ring-offset-4 focus-visible:ring-offset-[#0C1010] ${className}`}
>
<motion.div className="relative size-full [transform-style:preserve-3d]" style={{ [axis]: angle, scale: lift }}>
<div className={`${face} shadow-[0_24px_50px_-20px_rgb(0_0_0/0.7)]`} inert={flipped}>
{front}
</div>
<div className={`${face} shadow-[0_24px_50px_-20px_rgb(0_0_0/0.7)]`} style={{ transform: `${axis}(180deg)` }} inert={!flipped}>
{back}
</div>
<motion.div
aria-hidden
className="pointer-events-none absolute inset-0 overflow-hidden rounded-3xl"
style={{ transform: "translateZ(1px)" }}
>
<motion.div className="absolute inset-y-0 w-1/2 bg-[linear-gradient(105deg,transparent,rgb(255_255_255/0.22),transparent)]" style={{ left: sheen }} />
</motion.div>
</motion.div>
</div>
);
}
| Prop | Type | Default | Description |
|---|---|---|---|
| front | ReactNode | — | The front face. |
| back | ReactNode | — | The back face. |
| trigger | "hover" | "click" | "hover" | Flip on hover and focus, or on click and stay flipped. |
| direction | "horizontal" | "vertical" | "horizontal" | Turn side to side, or top over bottom. |
| label | string | "Card" | Names the card for screen readers when it flips on click. |
How we audit: the WCAG 2.2 animation checklist and respecting reduced motion in React.
Yes. The file starts with "use client", so you can import it straight into a Server Component page or layout. It works in Vite as is, and in Astro as a React island.
Only the motion package, beside React and Tailwind CSS v4. There is no MotionKit package and no Tailwind config to add.
Yes. Run npx shadcn@latest add https://www.motionkitui.com/r/flip-card.json in any project with a components.json. It saves the file to components/motionkit and installs its dependencies.
With reduced motion on, the two faces cross-fade instead of turning.
A card with a soft glow that tracks the pointer across its surface.
A 3D card that tilts toward the pointer, with an optional moving glare.
A card that tilts toward the cursor while its layers float at different depths, so each moves at its own speed.
Ada Lovelace
Flip for more
Ten years designing motion systems for products people use every day. Thinks every interface deserves a little delight.
London · since 2016