Components
card

card

Displays a card with header, content, and footer.

Create project
Deploy your new project in one-click.

Create a new project and deploy it to the cloud in seconds. No credit card required.

How it works

Install the following dependencies:

pnpm add framer-motion

Create a new file @/components/ui/card.tsx and paste the following code into your project.

The below component uses the Button component from the @/components/ui/button.tsx file. Make sure to have that file in your project as well.

card.tsx

import * as React from "react";
import { HTMLMotionProps, motion } from "motion/react";
 
import { cn } from "@/lib/utils";
 
const _Card = React.forwardRef<HTMLDivElement, HTMLMotionProps<"div">>(
    ({ className, ...props }, ref) => (
        <motion.div
            ref={ref}
            initial={{
                opacity: 0,
                y: -20,
            }}
            animate={{
                opacity: 1,
                y: 0,
                transition: {
                    duration: 0.3,
                },
            }}
            className={cn(
                "rounded-xl border bg-card text-card-foreground shadow",
                className,
            )}
            {...props}
        />
    ),
);
 
_Card.displayName = "Card";
 
const _CardHeader = React.forwardRef<HTMLDivElement, HTMLMotionProps<"div">>(
    ({ className, ...props }, ref) => (
        <motion.div
            ref={ref}
            className={cn("flex flex-col space-y-1.5 p-6", className)}
            {...props}
        />
    ),
);
 
_CardHeader.displayName = "CardHeader";
 
const _CardTitle = React.forwardRef<HTMLDivElement, HTMLMotionProps<"div">>(
    ({ className, ...props }, ref) => (
        <motion.div
            ref={ref}
            className={cn(
                "font-ins font-semibold leading-none tracking-tight",
                className,
            )}
            {...props}
        />
    ),
);
 
_CardTitle.displayName = "CardTitle";
 
const _CardDescription = React.forwardRef<
    HTMLDivElement,
    HTMLMotionProps<"div">
>(({ className, ...props }, ref) => (
    <motion.div
        ref={ref}
        className={cn("text-sm text-muted-foreground", className)}
        {...props}
    />
));
 
_CardDescription.displayName = "CardDescription";
 
const _CardContent = React.forwardRef<HTMLDivElement, HTMLMotionProps<"div">>(
    ({ className, ...props }, ref) => (
        <motion.div
            ref={ref}
            className={cn("p-6 pt-0", className)}
            {...props}
        />
    ),
);
 
_CardContent.displayName = "CardContent";
 
const _CardFooter = React.forwardRef<HTMLDivElement, HTMLMotionProps<"div">>(
    ({ className, ...props }, ref) => (
        <motion.div
            ref={ref}
            className={cn("flex items-center p-6 pt-0", className)}
            {...props}
        />
    ),
);
 
_CardFooter.displayName = "CardFooter";
 
const Card = motion.create(_Card);
const CardHeader = motion.create(_CardHeader);
const CardTitle = motion.create(_CardTitle);
const CardDescription = motion.create(_CardDescription);
const CardContent = motion.create(_CardContent);
const CardFooter = motion.create(_CardFooter);
 
export {
    Card,
    CardHeader,
    CardFooter,
    CardTitle,
    CardDescription,
    CardContent,
};

Use the component in your app

import React from "react";
 
import { Button } from "@/components/ui/button";
import {
    Card,
    CardContent,
    CardDescription,
    CardFooter,
    CardHeader,
    CardTitle,
} from "@/components/ui/card";
 
const CardDemo = () => {
    return (
        <div className="mx-auto max-w-md">
            <Card>
                <CardHeader>
                    <CardTitle>Create project</CardTitle>
                    <CardDescription>
                        Deploy your new project in one-click.
                    </CardDescription>
                </CardHeader>
                <CardContent>
                    <p className="text-sm">
                        Create a new project and deploy it to the cloud in
                        seconds. No credit card required.
                    </p>
                </CardContent>
                <CardFooter className="flex justify-end space-x-4">
                    <Button variant="outline">Cancel</Button>
                    <Button>Deploy</Button>
                </CardFooter>
            </Card>
        </div>
    );
};
 
export default CardDemo;