3D Card
Perspective card that turns toward the pointer while its layers lift to different depths.
- 1.6 KB gzipped
- Deps: motion/react
- Reduced-motion safe
- Base UI & Radix compatible
Installation
pnpm dlx shadcn@latest add https://velora.colorlib.com/r/3d-card.jsonAdds components/velora/3d-card.tsx, installs motion.
Examples
Product card
A shop tile whose product, title, price and add-to-cart button sit at different depths.
Props
Card3D
| Prop | Type | Default |
|---|---|---|
maxTiltMaximum rotation toward the pointer, in degrees | number | 10 |
perspectiveCSS perspective distance in px (smaller = stronger 3D) | number | 1000 |
cardClassNameClasses for the rotating surface (avoid overflow-hidden: it flattens the layers) | string | — |
children*Card content; wrap layers that should lift in Card3DItem | React.ReactNode | — |
Also accepts every <div> attribute, forwarded to the root element.
Card3DItem
| Prop | Type | Default |
|---|---|---|
depthHow far the item lifts toward the viewer, in px (translateZ) | number | 40 |
rotateXExtra rotation around the X axis at full lift, in degrees | number | 0 |
rotateYExtra rotation around the Y axis at full lift, in degrees | number | 0 |
rotateZExtra rotation around the Z axis at full lift, in degrees | number | 0 |
Also accepts every <div> attribute, forwarded to the root element.
Accessibility
- Reduced motion
- The card stays flat and its layers stay on the surface; pointer movement and focus change nothing.
- Keyboard
- The card is not focusable itself; when a link or button inside it gets keyboard focus, the layers rise to 40% of their depth without tilting.
- Screen readers
- A transparent wrapper; the children are read in source order.