# Flip Card

> 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.

Category: Cards · Free · Updated 2026-11-12 · Live demo: https://www.motionkitui.com/components/flip-card

## When to use it

Team bios, feature reveals, flashcards and quizzes, pricing details, and before/after or question/answer pairs.

## How it works

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.

## Installation

```bash
npx shadcn@latest add https://www.motionkitui.com/r/flip-card.json
```

Or copy `components/motionkit/flip-card.tsx` below. Requires react, motion and Tailwind CSS v4. Free for personal projects; commercial use needs MotionKit Plus (https://www.motionkitui.com/pricing).

## Props

| 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. |

## Accessibility

- **Keyboard: Pass.** Focusable. Hover cards flip on focus; click cards flip with Enter or Space. The hidden face is inert, so Tab never lands on content you can't see.
- **Screen readers: Pass.** Only the visible face is read. Click cards are buttons that say which side is showing.
- **Reduced motion: Pass.** With reduced motion on, the two faces cross-fade instead of turning.
- **Colour contrast: Pass.** The sample faces measure 4.9:1 or more for all text. Check your own content on the faces you pass in.

## Source

```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>
  );
}
```
