shadcn.io is an independent project built on shadcn/ui
On this page7 sections
3D Card turns a card toward the pointer and lifts the layers inside it off its surface, each to a depth you choose, so a title, a photo and a button part like the pages of a pop-up book. It's for the one card on a page that deserves a second look: a featured product, the plan you recommend, a launch announcement.
For cards people scan in a grid or read through, a still Card is calmer. To mark one place with a floating label, there's 3D Pin.
Installation
Anatomy

Usage
<script lang="ts">
import {
Card3D, Card3DBody, Card3DItem,
} from "@/components/ui/card-3d";
</script>
Card3D is the stage that follows the pointer, Card3DBody is the card that tilts, and each Card3DItem is a layer that rises by its translateZ while the card is hovered.
<Card3D>
<Card3DBody class="max-w-sm rounded-xl border bg-card p-6">
<Card3DItem class="font-semibold text-xl" translateZ={50}>
Make things float in air
</Card3DItem>
<Card3DItem class="mt-4 w-full" translateZ={100}>
<img alt="Mountains above the clouds" class="rounded-lg" src="/peaks.jpg" />
</Card3DItem>
</Card3DBody>
</Card3D>
Accessibility
Nothing in 3D Card has a role or takes focus. The stage, the card and its layers are plain elements, and the tilt is decoration a screen reader never hears about, so what gets announced is what you put inside: give each image its alt text and keep links and buttons as real elements. When keyboard focus moves to something inside the card, the layers rise as they do on hover, though the card only tilts under a pointer. A button clicked with the mouse doesn't hold them up once the pointer leaves. With reduced motion turned on, the card stays flat and the layers stay put.
Demos
Rotate
A product card for $249 headphones whose layers turn and slide as well as rise. The New badge turns with rotateZ, the label shifts sideways with translateX, and the photo tips back with rotateX while translateY lifts it. Each value is the layer's pose while the card is hovered, read as degrees or pixels when it's a number.
Tilt
Two small cards, Subtle and Strong, with tilt set to 5 and 20, and each shows its own angle. That's how far the card turns, in degrees, when the pointer reaches its edge, and it defaults to 10. Keep it low for a large card or a quiet page, and save a high value for a small card meant to feel playful.
Link
A travel post card whose title is a link, with the photo at a depth of 40 and the title at 60. The title's layer is the anchor itself, so the link carries its own depth with no wrapper around it. Tab to it and the layers rise, though the card stays level. Card3DItem takes an asChild snippet whose props the anchor spreads.
FAQ
How do I make a layer pop out of the 3D Card?
Wrap it in a Card3DItem and set translateZ, the distance it rises toward the viewer while the card is hovered. Values from 40 to 100 read well, and layers at different values part from each other, which is what sells the effect: the default demo puts its title at 50, the text under it at 60 and the photo at 100.
A number is in pixels, and a string such as "2rem" is used as written. translateX, translateY and the three rotate props move the layer too, as the Rotate demo shows. Every layer settles back flat once the pointer leaves, unless something inside the card has keyboard focus.
How do I make the 3D Card tilt more or less?
Set tilt on Card3D to the angle, in degrees, the card turns when the pointer reaches the edge of the stage. It defaults to 10, and the Tilt demo puts 5 beside 20.
How steep a given angle looks depends on the perspective, which is the perspective-[1000px] class on Card3D. Give Card3D a smaller one, such as perspective-[600px], for a more dramatic turn, or a larger one for a flatter look. The class you add replaces the default.
Why does my 3D Card start tilting before the pointer is over it?
The pointer is measured across Card3D, the stage, rather than across the card. The stage is a flex box that centers Card3DBody, and like any block it stretches to the width of its parent, so the card tilts and its layers rise as soon as the pointer enters that wider box. The default, Rotate and Link demos also give it w-full p-6, so the card turns while the pointer is still beside it.
To react only over the card, add w-fit to Card3D and leave out the padding, so the stage shrinks to the card. The Tilt demo's stages shrink the same way because they sit in a flex row. The card then reaches the full tilt at its own edges.
Can a 3D Card layer be a link or a button in Svelte?
Yes. Give Card3DItem an asChild snippet: it receives a props function, and spreading what it returns on your link or button hands over the layer's class, style and depth. The element keeps its own role, focus and events.
The Link demo does this with a post title. Wrapping a whole Button in a plain Card3DItem works as well, as the default demo's two buttons show, at the cost of one extra element around each.
Why does a 3D Card layer stay flat inside a wrapper?
Card3DBody keeps each of its direct children in 3D, so a layer inside one plain wrapper, like the default demo's row of buttons, still rises. A layer nested deeper needs every element between it and the body to keep 3D as well: add the transform-3d class to each wrapper on the way down.
A wrapper with overflow-hidden, a filter or an opacity under 1 flattens everything inside it, whatever its classes say, because the browser paints such an element as one flat image. Move that styling onto the layer itself, or onto an element inside it.
What does the 3D Card do with reduced motion or on a touch screen?
With reduced motion turned on, the card never tilts and its layers stay in place, because every transform sits behind Tailwind's motion-safe variant. The content reads the same, only flat.
A touch screen has no hover, so the layers don't rise under a finger. A touch tilts the card only until the finger lifts or the page starts to scroll, and then it eases back. Make sure everything the card says works while it lies flat, since that's how most phone visitors see it.
Does the 3D Card re-render on every pointer move?
No. The pointer handler writes two CSS variables, --card-3d-x and --card-3d-y, on the stage element and changes no Svelte state, so no component renders again as the pointer moves. Leaving the stage removes them.
The tilt and the layers are CSS transforms with a 200ms transition, which the browser animates without laying the page out again. Each move does read the stage's size with getBoundingClientRect, a cheap call while nothing else on the page is changing its layout.
When should I use a 3D Card instead of a regular Card?
Use the 3D Card for one or two cards that are the point of a section: a featured product, the recommended pricing tier, a launch post. The motion asks for attention, and a grid where every card turns under the pointer sets the whole page moving.
For lists, dashboards and anything people read in a row, use a plain Card. It holds the same content, and with nothing moving people can compare one card with the next.
API Reference
Card3D
<div> data-slot="card-3d"
tilt?number
How far the card turns toward the pointer at its edges, in degrees.
- Default
10
class?string
Merged with the part's classes.
Card3DBody
<div> data-slot="card-3d-body"
class?string
Merged with the part's classes.
--card-3d-tiltstringCard3DItem
<div> data-slot="card-3d-item"
rotateX?number | string
Its turn about the horizontal axis while the card is hovered: degrees as a number, or any CSS angle.
- Type
number | string- Default
0
rotateY?number | string
Its turn about the vertical axis while hovered. @default 0.
- Type
number | string- Default
0
rotateZ?number | string
Its turn in the card's plane while hovered. @default 0.
- Type
number | string- Default
0
translateX?number | string
How far it moves across while the card is hovered: pixels as a number, or any CSS length.
- Type
number | string- Default
0
translateY?number | string
How far it moves down while hovered. @default 0.
- Type
number | string- Default
0
translateZ?number | string
How far it rises toward the viewer while hovered: the depth that sets it apart from the card. 40 to 100 reads well.
- Type
number | string- Default
0
asChild?Snippet<[PropsFn]>
Render your own element: a snippet that gets the part's props to spread on it.
- Type
Snippet<[PropsFn]>
class?string
Merged with the part's classes.
--card-3d-itemstring