Card deck
A tactile stack that fans out, follows your hand, and deals the next card with a measured flick.
Used forTestimonialsOnboarding tipsCase studies and showcasesMobile-style content
Install with the shadcn CLI
Older shadcn CLI, or a network that blocks ui.shadcn.com? Install by URL: shadcn add https://hairlineui.com/r/card-deck.json. More
Templates
Need the whole page?
65 Next.js landing pages, each designed from scratch. Try any of them live; one is $39, all of them $159, and 8 are free.
Where it’s used
Testimonials
A stack of customer quotes that visitors flick through.
Onboarding tips
Short cards to deal through, one at a time.
Case studies and showcases
Let people browse a small collection hands-on on a landing page.
Mobile-style content
Flashcards, recipes or product picks in a stack you can swipe.
What it handles for you
A row of cards with arrow buttons is a carousel. A deck is something you hold. This gives a stack of your own cards that feel and behave like one.
It fans out
Hover or focus the front card and the cards behind open slightly, so people can see there is more.
It follows your hand
The front card tracks the pointer with a slight rotation while the next one rises.
It deals on a flick
Drag past about a quarter of the card’s width, or flick, and the card is dealt away from where you let go.
It springs back
An unfinished drag returns on a damped spring that keeps the speed of your release.
Your content in every card
renderCard draws anything. Links, buttons and inputs inside a card keep their own behaviour.
Works without dragging
Arrow keys and Previous and Next buttons browse the deck, and vertical touch scrolling still works.
Overview
A small collection you can hold. The cards sit in a shallow stack; hovering or focusing the front card gently fans the ones behind it. Drag sideways and the front card follows your hand with a slight rotation while the next comes forward. A committed drag or quick flick deals it away. Release early and a damped spring brings it home. The same collection works with arrow buttons and keyboard controls, and its cards can contain your own content.
States
- rest
- Up to four cards are visible, with 12px spacing and a 5.5% size difference between layers.
- fan
- Hover or keyboard focus opens the stack to 17px spacing and a slight alternating rotation.
- drag
- The front card follows the pointer without React updates on each frame. Every card has its own compositor layer, and the cards behind are moved directly as the next one rises in proportion to the drag, so nothing repaints mid-gesture.
- deal
- Cross 27% of the card’s width (at most 100px), or flick intentionally, to deal a card. The outgoing card continues from the release position.
- return
- An incomplete or cancelled drag returns along a sampled damped spring over 520ms, using the release velocity.
Usage
Depends on lucide-react, installed for you by the CLI along with the keyframes it needs.
Works with
A controlled collection
Render your own card contents; the deck owns the stack and gestures. The collection wraps in both directions.
Props
- items
- T[] where T extends { id: string }
- The collection in reading order. IDs must be unique.
- renderCard
- (item: T, state: { active: boolean; index: number }) => ReactNode
- Your card contents. Only the front card is interactive; rear cards and outgoing copies are inert.
- getLabel= item.id
- (item: T) => string
- Accessible name for each card.
- value / defaultValue
- string
- Controlled selected ID or initial selected ID. Defaults to the first card.
- onValueChange
- (id: string) => void
- Receives the next selected ID after a gesture or button action.
- height= 340
- number
- Card height in CSS pixels, at least 120. Leave space for your longest content.
- label= Card collection
- string
- Accessible label for the collection region.
- className
- string
- Additional classes on the root. Standard div attributes are forwarded.
Accessibility and motion
- Left and Right on the front card browse the collection. Previous and Next buttons offer equivalent pointer and touch controls.
- Only the front card is focusable. Back cards and the departing copy are inert and hidden from assistive technology.
- Links, buttons, form inputs and elements marked data-deck-no-drag keep their own interactions without starting a card drag.
- Vertical touch scrolling is preserved. Pointer cancellation returns the card, and a pause before release does not count as a flick.
- Reduced motion removes dragging transforms, fanning and animated exits. Gestures still select cards, with immediate state changes.
- The collection wraps. Empty collections render no controls; one-card collections disable browsing.
Requirements
React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.
The CLI also installs Number roll.
Source
Registry item: /r/card-deck.json


