# Flip Card

> Click to flip it over in 3D and see the back.

- Category: Cards
- Tier: Free (MIT)
- Page: https://bowls.dev/components/flip-card
- Requires: React 18+, Tailwind CSS 4, motion

## Install

Copy the source below into `components/bowls/flip-card.tsx`, then install its dependencies:

```bash
npm i motion
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `front` | `ReactNode` | — | Front face. |
| `back` | `ReactNode` | — | Back face. |
| `label` | `string` | — | Accessible name for the card. |

## Usage

```tsx
"use client";

import { FlipCard } from "@/components/bowls/flip-card";

export default function Demo() {
  return (
    <div className="flex h-full w-full items-center justify-center">
      <FlipCard
        label="Recipe card"
        className="h-[180px] w-[150px]"
        front={
          <span className="flex h-full w-full flex-col justify-between rounded-2xl bg-[#ff5c39] p-4 text-left text-white shadow-[0_16px_30px_-10px_rgba(255,92,57,.6)]">
            <span className="font-mono text-[11px] opacity-80">Nº 07</span>
            <span className="text-xl leading-tight font-bold">Tap to
              <br />
              flip me</span>
          </span>
        }
        back={
          <span className="flex h-full w-full flex-col justify-between rounded-2xl bg-[#3b82f6] p-4 text-left text-white shadow-[0_16px_30px_-10px_rgba(59,130,246,.6)]">
            <span className="font-mono text-[11px] opacity-80">the back</span>
            <span className="text-xl leading-tight font-bold">Hello
              <br />
              there.</span>
          </span>
        }
      />
    </div>
  );
}
```

## Source

`components/bowls/flip-card.tsx`

```tsx
"use client";

import { motion } from "motion/react";
import { useState, type ReactNode } from "react";

export type FlipCardProps = {
  front: ReactNode;
  back: ReactNode;
  /** Accessible name for the card's button. */
  label: string;
  className?: string;
};

/** Click (or press Enter / Space) to flip the card over in 3D. */
export function FlipCard({ front, back, label, className }: FlipCardProps) {
  const [flipped, setFlipped] = useState(false);
  const face = "absolute inset-0 [backface-visibility:hidden]";

  return (
    <button
      type="button"
      aria-pressed={flipped}
      aria-label={`${label}: ${flipped ? "showing back" : "showing front"}`}
      onClick={() => setFlipped((f) => !f)}
      className={`relative block [perspective:900px] ${className ?? ""}`}
    >
      <motion.span
        className="relative block h-full w-full [transform-style:preserve-3d]"
        animate={{ rotateY: flipped ? 180 : 0 }}
        transition={{ type: "spring", stiffness: 180, damping: 18 }}
      >
        <span className={face}>{front}</span>
        <span className={`${face} [transform:rotateY(180deg)]`}>{back}</span>
      </motion.span>
    </button>
  );
}
```
