Ir al contenido
Español
Tarjeta giratoria viene con Pro. La vista previa aparece al desbloquearlo.

Cómo funciona

The root only provides perspective; inside it, both faces share one grid cell and the inner wrapper rotates 180° while the back is pre-rotated and backface-visibility hides the far side. Only transform animates. The card is not one big button, because faces often hold buttons and links; an invisible real button (aria-pressed) under the card handles keyboard and screen readers. Add data-flip-toggle to a button in a face to flip from it.

Úsalo para

  • Membership cards and coupons: summary on the front, details or a QR code on the back.
  • Flashcards: question on the front, answer on the back.
  • Tight spaces where extra details should not need a dialog or a new page.

Busca otra opción cuando

  • Critical information such as prices or warnings: show it directly instead of hiding it on the back.
  • Dozens of flippable cards in a list: use expandable details or a drawer.
  • Faces of very different heights: the shorter one leaves a large gap; use an accordion.

Uso

import { FlipCard } from './FlipCard.jsx'

export function MemberCard({ member }) {
  return (
    <FlipCard
      style={{ width: 300 }}
      toggleLabel="Show member perks"
      front={
        <>
          <h3>{member.title}</h3>
          <p>Click for perks</p>
        </>
      }
      back={
        <>
          <h3>Member perks</h3>
          <p>Free size upgrade on your birthday.</p>
          {/* Buttons in a face work as usual; one with data-flip-toggle flips back */}
          <button data-flip-toggle>Got it</button>
        </>
      }
    />
  )
}

// Controlled: <FlipCard flipped={flipped} onFlippedChange={setFlipped} trigger="hover" direction="vertical" ... />

Propiedades

PropiedadTipoPor defectoQué hace
frontReactNode—Front face content.
backReactNode—Back face content. The frame height is that of the taller face.
flippedboolean—Controlled: whether the back is showing.
defaultFlippedbooleanfalseUncontrolled: initial state.
onFlippedChange(flipped: boolean) => void—Called when the flip state changes.
trigger'click' | 'hover''click'click flips on empty face space; hover flips while the pointer is over the card. Touch falls back to tap; keyboard focus also flips it.
direction'horizontal' | 'vertical''horizontal'Turn around the vertical axis (left-right) or the horizontal axis (up-down).
durationnumber560Flip time in ms. When omitted it follows --ds-duration-slower.
toggleLabelstring'Show back'Screen reader name of the flip control. Make it specific, such as “Show member perks”.
...restHTMLAttributes<HTMLDivElement>—Other attributes go to the root element: className, style (width and --ds-flip-* variables).

Accesibilidad

  • The flip control is a real <button aria-pressed>: Tab reaches it, Enter and Space flip it; name it with toggleLabel.
  • Buttons, links and inputs inside a face keep their own semantics, and clicking them does not flip.
  • The hidden face is inert and aria-hidden, so it cannot be tabbed to, read or clicked.
  • If focus is in the face being hidden, it moves to the flip control instead of being lost.
  • Reduced motion replaces the rotation with a cross-fade.

Movimiento

A 560ms turn with a slight overshoot (cubic-bezier(0.34, 1.22, 0.64, 1)), transform only; the card shrinks to 0.98 while pressed. With reduced motion, a 240ms opacity cross-fade.

Añádelo a tu proyecto

Los miembros Pro copian un prompt y su agente de programación instala el código, igual que con los gratuitos.

FlipCard.jsxflip-card.csstokens.cssREADME.md

Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

Tarjetas
Tarjeta con borde animado viene con Pro. La vista previa aparece al desbloquearlo.
Borde con haz de luz viene con Pro. La vista previa aparece al desbloquearlo.
Tarjeta con hoja de datos viene con Pro. La vista previa aparece al desbloquearlo.