Card
Displays a card with header, content, and footer.
Login to your account
Enter your email below to login to your account
tsx
import { Button } from "@/components/ui/button"import { Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle,} from "@/components/ui/card"import { Input } from "@/components/ui/input"import { Label } from "@/components/ui/label"
export function CardDemo() { return ( <Card className="w-full max-w-sm"> <CardHeader> <CardTitle>Login to your account</CardTitle> <CardDescription> Enter your email below to login to your account </CardDescription> <CardAction> <Button variant="link">Sign Up</Button> </CardAction> </CardHeader> <CardContent> <form> <div className="flex flex-col gap-6"> <div className="grid gap-2"> <Label htmlFor="email">Email</Label> <Input id="email" type="email" placeholder="m@example.com" required /> </div> <div className="grid gap-2"> <div className="flex items-center"> <Label htmlFor="password">Password</Label> <a href="#" className="ml-auto inline-block text-sm underline-offset-4 hover:underline" > Forgot your password? </a> </div> <Input id="password" type="password" required /> </div> </div> </form> </CardContent> <CardFooter className="flex-col gap-2"> <Button type="submit" className="w-full"> Login </Button> <Button variant="outline" className="w-full"> Login with Google </Button> </CardFooter> </Card> )}
Installation
CLI
bash
npx fivui add card
Manual
Copy and paste the following code into your project:
tsx
import * as React from "react"
import { cn } from "@/lib/utils"
const Card = React.forwardRef< HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(({ className, ...props }, ref) => ( <div ref={ref} className={cn( "rounded-lg border bg-card text-card-foreground shadow-sm", className )} {...props} />))Card.displayName = "Card"
const CardHeader = React.forwardRef< HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(({ className, ...props }, ref) => ( <div ref={ref} className={cn("flex flex-col space-y-1.5 p-6", className)} {...props} />))CardHeader.displayName = "CardHeader"
const CardTitle = React.forwardRef< HTMLParagraphElement, React.HTMLAttributes<HTMLHeadingElement>>(({ className, ...props }, ref) => ( <h3 ref={ref} className={cn( "text-2xl font-semibold leading-none tracking-tight", className )} {...props} />))CardTitle.displayName = "CardTitle"
const CardDescription = React.forwardRef< HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement>>(({ className, ...props }, ref) => ( <p ref={ref} className={cn("text-sm text-muted-foreground", className)} {...props} />))CardDescription.displayName = "CardDescription"
const CardAction = React.forwardRef< HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(({ className, ...props }, ref) => ( <div ref={ref} className={cn("ml-auto", className)} {...props} />))CardAction.displayName = "CardAction"
const CardContent = React.forwardRef< HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(({ className, ...props }, ref) => ( <div ref={ref} className={cn("p-6 pt-0", className)} {...props} />))CardContent.displayName = "CardContent"
const CardFooter = React.forwardRef< HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(({ className, ...props }, ref) => ( <div ref={ref} className={cn("flex items-center p-6 pt-0", className)} {...props} />))CardFooter.displayName = "CardFooter"
export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardAction, CardContent }
Usage
tsx
import { Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle,} from "@/components/ui/card"
tsx
<Card> <CardHeader> <CardTitle>Card Title</CardTitle> <CardDescription>Card Description</CardDescription> <CardAction>Card Action</CardAction> </CardHeader> <CardContent> <p>Card Content</p> </CardContent> <CardFooter> <p>Card Footer</p> </CardFooter></Card>
Examples
Card with Form
Create project
Deploy your new project in one-click.
tsx
import { Button } from "@/components/ui/button"import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle,} from "@/components/ui/card"import { Input } from "@/components/ui/input"import { Label } from "@/components/ui/label"import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue,} from "@/components/ui/select"
export function CardWithFormDemo() { return ( <Card className="w-[350px]"> <CardHeader> <CardTitle>Create project</CardTitle> <CardDescription>Deploy your new project in one-click.</CardDescription> </CardHeader> <CardContent> <form> <div className="grid w-full items-center gap-4"> <div className="flex flex-col space-y-1.5"> <Label htmlFor="name">Name</Label> <Input id="name" placeholder="Name of your project" /> </div> <div className="flex flex-col space-y-1.5"> <Label htmlFor="framework">Framework</Label> <Select> <SelectTrigger> <SelectValue placeholder="Select a framework" /> </SelectTrigger> <SelectContent> <SelectItem value="next">Next.js</SelectItem> <SelectItem value="sveltekit">SvelteKit</SelectItem> <SelectItem value="astro">Astro</SelectItem> <SelectItem value="nuxt">Nuxt.js</SelectItem> </SelectContent> </Select> </div> </div> </form> </CardContent> <CardFooter className="flex justify-between"> <Button variant="outline">Cancel</Button> <Button>Deploy</Button> </CardFooter> </Card> )}
Card with Notifications
Notifications
You have 3 unread messages.
Push Notifications
Send notifications to device.
Email Notifications
Send notifications via email.
tsx
import { Button } from "@/components/ui/button"import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle,} from "@/components/ui/card"import { Checkbox } from "@/components/ui/checkbox"
export function CardWithNotificationDemo() { return ( <Card className="w-[380px]"> <CardHeader> <CardTitle>Notifications</CardTitle> <CardDescription>You have 3 unread messages.</CardDescription> </CardHeader> <CardContent className="grid gap-4"> <div className="flex items-center space-x-4 rounded-md border p-4"> <div className="flex-1 space-y-1"> <p className="text-sm font-medium leading-none"> Push Notifications </p> <p className="text-sm text-muted-foreground"> Send notifications to device. </p> </div> <Checkbox defaultChecked /> </div> <div className="flex items-center space-x-4 rounded-md border p-4"> <div className="flex-1 space-y-1"> <p className="text-sm font-medium leading-none"> Email Notifications </p> <p className="text-sm text-muted-foreground"> Send notifications via email. </p> </div> <Checkbox /> </div> </CardContent> <CardFooter> <Button className="w-full"> Update preferences </Button> </CardFooter> </Card> )}
API Reference
Card
Prop | Type | Default | Description |
---|---|---|---|
className | string | - | Additional CSS classes to apply to the card. |
CardHeader
Prop | Type | Default | Description |
---|---|---|---|
className | string | - | Additional CSS classes to apply to the card header. |
CardTitle
Prop | Type | Default | Description |
---|---|---|---|
className | string | - | Additional CSS classes to apply to the card title. |
CardDescription
Prop | Type | Default | Description |
---|---|---|---|
className | string | - | Additional CSS classes to apply to the card description. |
CardAction
Prop | Type | Default | Description |
---|---|---|---|
className | string | - | Additional CSS classes to apply to the card action area. |
CardContent
Prop | Type | Default | Description |
---|---|---|---|
className | string | - | Additional CSS classes to apply to the card content. |
CardFooter
Prop | Type | Default | Description |
---|---|---|---|
className | string | - | Additional CSS classes to apply to the card footer. |