Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Card

FreeNew

A surface with a header, an action slot, content and a footer. The interactive variant lifts on hover.

Installation

pnpm dlx shadcn@latest add @viewport/card

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above.

card-demo.tsx
import { Ellipsis } from "lucide-react";
import { Badge } from "@/components/viewport/badge";
import { Button } from "@/components/viewport/button";
import { Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/viewport/card";
import { ProgressBar } from "@/components/viewport/progress-bar";

export default function CardDemo() {
  return (
    <Card className="w-full max-w-sm">
      <CardHeader>
        <CardTitle>Northwind renewal</CardTitle>
        <CardDescription>Annual contract, 40 seats</CardDescription>
        <CardAction>
          <Badge tone="info" dot>
            Negotiation
          </Badge>
          <Button variant="ghost" size="icon" aria-label="More actions for Northwind renewal" className="size-8">
            <Ellipsis aria-hidden />
          </Button>
        </CardAction>
      </CardHeader>
      <CardContent className="flex flex-col gap-4">
        <div className="flex items-baseline justify-between">
          <span className="text-3xl font-semibold tabular-nums tracking-tight">$48,000</span>
          <span className="text-sm text-muted-foreground">closes Dec 18</span>
        </div>
        <ProgressBar value={70} label="Likelihood to close" showLabel size="sm" />
      </CardContent>
      <CardFooter className="justify-between">
        <span className="text-[13px] text-muted-foreground">Updated 2 hours ago</span>
        <Button variant="outline" size="sm">
          Open deal
        </Button>
      </CardFooter>
    </Card>
  );
}

Props

<Card>

PropTypeDefault
interactiveboolean

Lift slightly on hover, for a card that is itself a link or a button.

false

<CardTitle>

PropTypeDefault
as"h2" | "h3" | "h4"

The heading level, so the card fits the page outline.

—

Accessibility

  • The title's heading level is configurable, so the page outline stays correct.
  • An interactive card shows a focus ring when the link inside it is focused.
  • Server component with no client JavaScript.
  • Respects prefers-reduced-motion.