Keyframery

Card

Card parts cascade in, interactive cards lift on hover and sink while pressed, by pointer or by Space and Enter, and an optional light follows the pointer.

See it as an AI agent does.

Resize preview. Focus the handle and use the left or right arrow keys. Hold Shift for larger steps.— px
Customize1 controls
Animation speed1×

Installation

npx shadcn@latest add @keyframery/card

This adds components/keyframery/card.tsx and its primitive to your project, and installs UI SDK, along with agent-content, which it builds on. The motion tokens are added to your global CSS the first time you install a component.

Usage

import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/keyframery/card"

export default function Usage() {
  return (
    <Card>
      <CardHeader>
        <CardTitle>Title</CardTitle>
        <CardDescription>Description</CardDescription>
      </CardHeader>
      <CardContent>Content</CardContent>
      <CardFooter>Footer</CardFooter>
    </Card>
  )
}

Anatomy

How the parts fit together:

Card
├── CardHeader
│   ├── CardTitle
│   └── CardDescription
├── CardContent
└── CardFooter

Examples

Basic

A header with a title, a description and an optional CardAction in the corner.

Interactive

interactive makes the whole card pressable: it lifts on hover and sinks on press. spotlight adds a soft light that follows the pointer.

Motion

MoveWhat you see
CascadeThe card fades up, then its header, content and footer arrive in order.
SpringAn interactive card lifts 2px on hover and its shadow grows.
PressIt sinks while the pointer holds it down, or while Space or Enter is held on it, and pops back on release.
FadeAn optional soft light follows the pointer.

Timing and springiness follow the motion style you set. To change how fast this card moves, pass speed:

<Card speed="fast">
  …
</Card>

"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.

Theming

Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.

VariableWhat it changesDefault
--card-faceCard surface--card
--card-inkCard text--card-foreground
--card-mutedDescription text--muted-foreground
--card-radiusCard corners16px
--card-paddingCard and section padding1.25rem
--card-gapSection gap1.25rem
--card-lightPointer spotlight washcurrentColor 13%, transparent

API reference

Every part takes className and children, along with the props of the element it renders. The parts are rendered by UI SDK, so they also take render, to draw your own element, and a function of their state for className and style.

Card

Renders a <div>, and takes its props too.

Prop

Type

Other parts

These take the props of the element they render, and nothing else:

  • CardHeader: a <div>
  • CardTitle: a <div>
  • CardDescription: a <div>
  • CardContent: a <div>
  • CardFooter: a <div>
  • CardAction: a <div>

Keyboard

KeyWhat it does
Space or EnterOn an interactive card you made focusable (with tabIndex and a role), sinks the card while the key is held, unless your own onKeyDown calls preventDefault(). What the press does is yours, in onClick or onKeyDown.

Accessibility

Roles, keyboard and focus are declared on the component's UI SDK primitive, and state is announced through the matching ARIA attributes. More in Accessibility.

Built on UI SDK's core

UI SDK doesn't ship a card, so this one is defined with its core: one definePrimitive in components/keyframery/core/card-core.ts, with no React in it. UI SDK's adapters can render that same definition in Vue, Svelte, Solid and web components. To keep your own styling and take only the motion, import from @/components/keyframery/primitives/card.

Questions

How does the animated Card for UI SDK move?

Cascade: The card fades up, then its header, content and footer arrive in order. Spring: An interactive card lifts 2px on hover and its shadow grows. Press: It sinks while the pointer holds it down, or while Space or Enter is held on it, and pops back on release. Fade: An optional soft light follows the pointer.

Do I need Motion or Framer Motion for the animated Card?

No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.

UI SDK has no card. How is this one built on UI SDK?

Its behaviour is one definition written with UI SDK's core (definePrimitive), in components/keyframery/core/card-core.ts. Its parts are rendered by UI SDK's adapter, so they take render, state-based class names and data-slot, like every UI SDK component.

What happens to the Card when someone turns on reduced motion?

Nothing moves. State changes happen at once, or with a short fade.

All components

On this page