Skip to content
WANCRAFT

B.07Cards & Containers

Flip Card

An accessible two-sided card that flips on click, Enter or Space — with the hidden face made inert.

ReactCSSTailwindintermediate

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 verified

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

Method 02 · Copy and paste

  1. 1. No extra dependencies — React and Tailwind CSS only.
  2. 2. Copy the source from the Code tab into components/ui/flip-card.tsx.
  3. 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.

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

PropTypeDefaultDescription
frontReactNode—Front face content (required).
backReactNode—Back face content (required).
axis"y" | "x""y"Rotation axis.
durationnumber700Flip duration in ms.
perspectivenumber1200CSS perspective in px.
flipOnHoverbooleanfalseAlso flip while a mouse hovers (touch and keyboard still toggle).
hintbooleantrueShow a small decorative flip affordance on each face.
roundednumber20Corner radius in px.
flipped / defaultFlippedboolean— / falseControlled or initial state (true shows the back).
onFlippedChange(flipped: boolean) => void—Called whenever the card flips.
labelstring"Show back side"Accessible name of the toggle button.
frontClassName / backClassNamestring—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
motion · tweeninput · clickinput · keyboardinput · hover

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