Overview
Flip Card stacks a front and back face in a preserve-3d grid, so the card is always as tall as its taller side. A single toggle button with aria-pressed sits beneath both faces: clicking anywhere flips the card, while links and buttons inside a face still work. The face turned away is marked inert, so keyboard focus and screen readers only ever reach the visible side. Optional hover flipping, both axes, and a cross-fade for reduced motion.
01Installation
Method 01 · Registry
CLI verifiedUses the shadcn CLI in a project initialised with shadcn init. Installs the file to components/ui/flip-card.tsx and adds its dependencies.
npx shadcn@latest add https://wancraft.my/r/flip-card.jsonMethod 02 · Copy and paste
- 1. No extra dependencies — React and Tailwind CSS only.
- 2. Copy the source from the Code tab into
components/ui/flip-card.tsx. - 3. Import it and adjust props.
- Dependencies
- None
- Peer
- react ≥ 18, tailwindcss ≥ 4
- Added
- 1 Oct 2026
- Updated
- —
02Usage
The default configuration. Change properties above to generate a tailored example in the Usage tab.
import { FlipCard } from "@/components/ui/flip-card";
export function FlipCardExample() {
return (
<FlipCard
className="h-72 w-60"
front={<div className="p-6 text-lg font-medium">Studio plan</div>}
back={<div className="p-6 text-sm">Unlimited projects, priority support.</div>}
/>
);
}03Props
| Prop | Type | Default | Description |
|---|---|---|---|
| front | ReactNode | — | Front face content (required). |
| back | ReactNode | — | Back face content (required). |
| axis | "y" | "x" | "y" | Rotation axis. |
| duration | number | 700 | Flip duration in ms. |
| perspective | number | 1200 | CSS perspective in px. |
| flipOnHover | boolean | false | Also flip while a mouse hovers (touch and keyboard still toggle). |
| hint | boolean | true | Show a small decorative flip affordance on each face. |
| rounded | number | 20 | Corner radius in px. |
| flipped / defaultFlipped | boolean | — / false | Controlled or initial state (true shows the back). |
| onFlippedChange | (flipped: boolean) => void | — | Called whenever the card flips. |
| label | string | "Show back side" | Accessible name of the toggle button. |
| frontClassName / backClassName | string | — | Classes for each surface (background, border, text colour). Passing one replaces that face's default styling (light front, inverted back). |
04Features
- 01Click anywhere, Enter or Space to flip; optional hover flipping for mouse users
- 02Y or X axis, adjustable perspective and duration
- 03Grid stacking keeps the card as tall as its taller face
- 04Interactive content inside faces keeps working above the toggle
- 05Controlled or uncontrolled API
05Accessibility
- A real <button> with aria-pressed toggles the card; its pressed state means the back is showing.
- The face turned away gets the inert attribute (and aria-hidden), removing it from tab order and the accessibility tree.
- Tab order: the toggle first, then the visible face's own controls.
- Visible focus outline around the whole card when the toggle has keyboard focus.
- With prefers-reduced-motion the faces cross-fade in place instead of rotating.
06Limitations
- The toggle's name is constant (use the label prop to describe what the back contains).