# Metric Cards

> Bordered cards each holding one metric, a label, and a trend note. Use it to report KPIs in a structured layout on a homepage or product page.

A shadcn/ui block from the [@shadcn-ui-blocks](https://www.shadcn-ui-blocks.com) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/shadcn-ui-blocks/marketing-stats-metric-cards).

- Page, with a live preview: https://shadcn.exchange/r/shadcn-ui-blocks/marketing-stats-metric-cards
- Screenshot: https://abzjhwgwpdpz7ua5.public.blob.vercel-storage.com/shots/shadcn-ui-blocks/marketing-stats-metric-cards-light-083cf8cb2217adb4.png
- Registry item: https://www.shadcn-ui-blocks.com/r/marketing-stats-metric-cards.json
- Listed: 2026-10-13, source last changed 2026-10-13

## Install

```bash
npx shadcn@latest add https://www.shadcn-ui-blocks.com/r/marketing-stats-metric-cards.json
```

Run it in a project that has shadcn/ui set up. It adds the files below and installs what they depend on.

## Dependencies

- npm packages: `class-variance-authority`, `lucide-react`, `radix-ui`

## Files

### `components/blocks/marketing/stats/metric-cards.tsx`

```tsx
import { Badge } from '@/components/ui/badge';
import { Card, CardContent, CardFooter } from '@/components/ui/card';
import {
  Tooltip,
  TooltipContent,
  TooltipProvider,
  TooltipTrigger,
} from '@/components/ui/tooltip';
import { cn } from '@/lib/utils';
import {
  ArrowDownRight,
  ArrowUpRight,
  HelpCircle,
  InfoIcon,
} from 'lucide-react';

type Metric = {
  id: string;
  name: string;
  value: string;
  rawValue: number;
  change: number;
  trend: 'up' | 'down' | 'neutral';
  status: 'good' | 'warning' | 'critical';
  period: string;
  description: string;
};

export default function MetricCards() {
  // Sample data for metrics
  const metrics: Metric[] = [
    {
      id: 'revenue',
      name: 'Monthly Revenue',
      value: '$48,283',
      rawValue: 48283,
      change: 12.6,
      trend: 'up',
      status: 'good',
      period: 'vs. last month',
      description:
        'Total revenue generated during the current month from all products and services.',
    },
    {
      id: 'new-users',
      name: 'New Users',
      value: '2,741',
      rawValue: 2741,
      change: 8.3,
      trend: 'up',
      status: 'good',
      period: 'vs. last month',
      description: 'Number of new user registrations within the past 30 days.',
    },
    {
      id: 'conversion',
      name: 'Conversion Rate',
      value: '3.6%',
      rawValue: 3.6,
      change: -0.8,
      trend: 'down',
      status: 'warning',
      period: 'vs. last month',
      description:
        'Percentage of visitors who completed a desired action (signup, purchase, etc).',
    },
    {
      id: 'churn',
      name: 'Monthly Churn',
      value: '1.2%',
      rawValue: 1.2,
      change: -0.3,
      trend: 'down',
      status: 'good',
      period: 'vs. last month',
      description:
        'Percentage of subscribers who canceled their subscription this month.',
    },
    {
      id: 'cac',
      name: 'Customer Acq. Cost',
      value: '$48.32',
      rawValue: 48.32,
      change: 5.7,
      trend: 'up',
      status: 'warning',
      period: 'vs. last month',
      description:
        'Average cost to acquire a new customer, including marketing and sales expenses.',
    },
    {
      id: 'ltv',
      name: 'Customer LTV',
      value: '$452',
      rawValue: 452,
      change: 3.2,
      trend: 'up',
      status: 'good',
      period: 'vs. last month',
      description: 'Predicted lifetime value of an average customer.',
    },
    {
      id: 'active-users',
      name: 'Weekly Active Users',
      value: '14,583',
      rawValue: 14583,
      change: -2.1,
      trend: 'down',
      status: 'warning',
      period: 'vs. last week',
      description:
        'Number of unique users who performed an action in the past 7 days.',
    },
    {
      id: 'engagement',
      name: 'Avg. Engagement',
      value: '4.2 min',
      rawValue: 4.2,
      change: 11.7,
      trend: 'up',
      status: 'good',
      period: 'vs. last month',
      description:
        'Average time users spend actively engaging with the product per session.',
    },
    {
      id: 'support',
      name: 'Support Response',
      value: '42 min',
      rawValue: 42,
      change: 14.3,
      trend: 'up',
      status: 'critical',
      period: 'vs. last month',
      description:
        'Average time to first response for customer support tickets.',
    },
  ];

  // Helper function to get appropriate styles based on status
  const getStatusStyles = (status: Metric['status']) => {
    switch (status) {
      case 'good':
        return 'border-emerald-200 dark:border-emerald-950 bg-emerald-50 dark:bg-emerald-950/30';
      case 'warning':
        return 'border-amber-200 dark:border-amber-950 bg-amber-50 dark:bg-amber-950/30';
      case 'critical':
        return 'border-rose-200 dark:border-rose-950 bg-rose-50 dark:bg-rose-950/30';
      default:
        return '';
    }
  };

  // Helper function to get trend styles
  const getTrendStyles = (trend: Metric['trend']) => {
    switch (trend) {
      case 'up':
        return 'text-emerald-600 dark:text-emerald-400';
      case 'down':
        return 'text-rose-600 dark:text-rose-400';
      default:
        return 'text-muted-foreground';
    }
  };

  // Helper function to get trend icons
  const getTrendIcon = (trend: Metric['trend'], status: Metric['status']) => {
    // For metrics like "churn" where down is good
    const isInverseMetric = status === 'good' && trend === 'down';
    const isPositive =
      (trend === 'up' && status !== 'critical') || isInverseMetric;

    if (trend === 'up') {
      return (
        <ArrowUpRight
          className={cn(
            'h-4 w-4',
            isPositive ? 'text-emerald-500' : 'text-rose-500'
          )}
        />
      );
    } else if (trend === 'down') {
      return (
        <ArrowDownRight
          className={cn(
            'h-4 w-4',
            isPositive ? 'text-emerald-500' : 'text-rose-500'
          )}
        />
      );
    }
    return null;
  };

  // Calculate total percentages for the summary
  const getStatusSummary = () => {
    const total = metrics.length;
    const goodCount = metrics.filter((m) => m.status === 'good').length;
    const warningCount = metrics.filter((m) => m.status === 'warning').length;
    const criticalCount = metrics.filter((m) => m.status === 'critical').length;

    return {
      good: Math.round((goodCount / total) * 100),
      warning: Math.round((warningCount / total) * 100),
      critical: Math.round((criticalCount / total) * 100),
    };
  };

  const statusSummary = getStatusSummary();

  return (
    <TooltipProvider>
      <div className="container mx-auto px-4 py-24 md:px-6 lg:py-32 2xl:max-w-[1400px]">
        <div className="mx-auto max-w-5xl">
          <div className="mb-12 text-center">
            <Badge className="mb-2">Dashboard</Badge>
            <h2 className="text-3xl font-bold md:text-4xl">Business Metrics</h2>
            <p className="text-muted-foreground mx-auto mt-3 max-w-2xl">
              Real-time overview of our key performance indicators
            </p>
          </div>

          {/* Status Summary */}
          <div className="mb-8 grid grid-cols-3 gap-4">
            <div className="rounded-lg border border-emerald-200 bg-emerald-50 p-4 text-center dark:border-emerald-950 dark:bg-emerald-950/30">
              <div className="text-2xl font-bold text-emerald-600 dark:text-emerald-400">
                {statusSummary.good}%
              </div>
              <div className="text-muted-foreground text-sm">On Target</div>
            </div>
            <div className="rounded-lg border border-amber-200 bg-amber-50 p-4 text-center dark:border-amber-950 dark:bg-amber-950/30">
              <div className="text-2xl font-bold text-amber-600 dark:text-amber-400">
                {statusSummary.warning}%
              </div>
              <div className="text-muted-foreground text-sm">
                Needs Attention
              </div>
            </div>
            <div className="rounded-lg border border-rose-200 bg-rose-50 p-4 text-center dark:border-rose-950 dark:bg-rose-950/30">
              <div className="text-2xl font-bold text-rose-600 dark:text-rose-400">
                {statusSummary.critical}%
              </div>
              <div className="text-muted-foreground text-sm">Critical</div>
            </div>
          </div>

          {/* Metric Cards */}
          <div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
            {metrics.map((metric) => (
              <Card
                key={metric.id}
                className={cn(
                  'overflow-hidden border p-0',
                  getStatusStyles(metric.status)
                )}
              >
                <CardContent className="p-6">
                  <div className="mb-4 flex items-center justify-between">
                    <div className="flex items-center">
                      <h3 className="font-medium">{metric.name}</h3>
                      <Tooltip>
                        <TooltipTrigger asChild>
                          <button className="text-muted-foreground hover:text-foreground ml-1.5">
                            <HelpCircle className="h-3.5 w-3.5" />
                          </button>
                        </TooltipTrigger>
                        <TooltipContent>
                          <p className="max-w-xs text-sm">
                            {metric.description}
                          </p>
                        </TooltipContent>
                      </Tooltip>
                    </div>
                  </div>

                  <div className="flex items-baseline justify-between">
                    <div className="text-2xl font-bold">{metric.value}</div>
                    <div className="flex items-center">
                      <span
                        className={cn(
                          'text-sm font-medium',
                          getTrendStyles(metric.trend)
                        )}
                      >
                        {metric.change > 0 ? '+' : ''}
                        {metric.change}%
                      </span>
                      <span className="ml-1">
                        {getTrendIcon(metric.trend, metric.status)}
                      </span>
                    </div>
                  </div>

                  <div className="text-muted-foreground mt-1 text-xs">
                    {metric.period}
                  </div>
                </CardContent>
                <CardFooter
                  className={cn(
                    'bg-background/50 border-t px-6 !pt-3 !pb-3 text-xs',
                    metric.status === 'good'
                      ? 'border-emerald-200 dark:border-emerald-950/50'
                      : metric.status === 'warning'
                        ? 'border-amber-200 dark:border-amber-950/50'
                        : 'border-rose-200 dark:border-rose-950/50'
                  )}
                >
                  <div className="text-muted-foreground flex items-center">
                    <InfoIcon className="mr-1 h-3 w-3" />
                    {metric.status === 'good' && 'On target'}
                    {metric.status === 'warning' && 'Needs attention'}
                    {metric.status === 'critical' &&
                      'Critical - action required'}
                  </div>
                </CardFooter>
              </Card>
            ))}
          </div>
        </div>
      </div>
    </TooltipProvider>
  );
}
```

### `components/ui/badge.tsx`

```tsx
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { Slot } from "radix-ui"

import { cn } from "@/lib/utils"

const badgeVariants = cva(
  "group/badge inline-flex h-5 w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-4xl border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-all focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3!",
  {
    variants: {
      variant: {
        default: "bg-primary text-primary-foreground [a]:hover:bg-primary/80",
        secondary:
          "bg-secondary text-secondary-foreground [a]:hover:bg-secondary/80",
        destructive:
          "bg-destructive/10 text-destructive focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:focus-visible:ring-destructive/40 [a]:hover:bg-destructive/20",
        outline:
          "border-border text-foreground [a]:hover:bg-muted [a]:hover:text-muted-foreground",
        ghost:
          "hover:bg-muted hover:text-muted-foreground dark:hover:bg-muted/50",
        link: "text-primary underline-offset-4 hover:underline",
      },
    },
    defaultVariants: {
      variant: "default",
    },
  }
)

function Badge({
  className,
  variant = "default",
  asChild = false,
  ...props
}: React.ComponentProps<"span"> &
  VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
  const Comp = asChild ? Slot.Root : "span"

  return (
    <Comp
      data-slot="badge"
      data-variant={variant}
      className={cn(badgeVariants({ variant }), className)}
      {...props}
    />
  )
}

export { Badge, badgeVariants }
```

### `components/ui/card.tsx`

```tsx
import * as React from "react"

import { cn } from "@/lib/utils"

function Card({
  className,
  size = "default",
  ...props
}: React.ComponentProps<"div"> & { size?: "default" | "sm" }) {
  return (
    <div
      data-slot="card"
      data-size={size}
      className={cn(
        "group/card flex flex-col gap-6 overflow-hidden rounded-xl bg-card py-6 text-sm text-card-foreground shadow-xs ring-1 ring-foreground/10 has-[>img:first-child]:pt-0 data-[size=sm]:gap-4 data-[size=sm]:py-4 *:[img:first-child]:rounded-t-xl *:[img:last-child]:rounded-b-xl",
        className
      )}
      {...props}
    />
  )
}

function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="card-header"
      className={cn(
        "group/card-header @container/card-header grid auto-rows-min items-start gap-1 rounded-t-xl px-6 group-data-[size=sm]/card:px-4 has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto] [.border-b]:pb-6 group-data-[size=sm]/card:[.border-b]:pb-4",
        className
      )}
      {...props}
    />
  )
}

function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="card-title"
      className={cn(
        "font-heading text-base leading-normal font-medium group-data-[size=sm]/card:text-sm",
        className
      )}
      {...props}
    />
  )
}

function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="card-description"
      className={cn("text-sm text-muted-foreground", className)}
      {...props}
    />
  )
}

function CardAction({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="card-action"
      className={cn(
        "col-start-2 row-span-2 row-start-1 self-start justify-self-end",
        className
      )}
      {...props}
    />
  )
}

function CardContent({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="card-content"
      className={cn("px-6 group-data-[size=sm]/card:px-4", className)}
      {...props}
    />
  )
}

function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="card-footer"
      className={cn(
        "flex items-center rounded-b-xl px-6 group-data-[size=sm]/card:px-4 [.border-t]:pt-6 group-data-[size=sm]/card:[.border-t]:pt-4",
        className
      )}
      {...props}
    />
  )
}

export {
  Card,
  CardHeader,
  CardFooter,
  CardTitle,
  CardAction,
  CardDescription,
  CardContent,
}
```

### `components/ui/tooltip.tsx`

```tsx
"use client"

import * as React from "react"
import { Tooltip as TooltipPrimitive } from "radix-ui"

import { cn } from "@/lib/utils"

function TooltipProvider({
  delayDuration = 0,
  ...props
}: React.ComponentProps<typeof TooltipPrimitive.Provider>) {
  return (
    <TooltipPrimitive.Provider
      data-slot="tooltip-provider"
      delayDuration={delayDuration}
      {...props}
    />
  )
}

function Tooltip({
  ...props
}: React.ComponentProps<typeof TooltipPrimitive.Root>) {
  return <TooltipPrimitive.Root data-slot="tooltip" {...props} />
}

function TooltipTrigger({
  ...props
}: React.ComponentProps<typeof TooltipPrimitive.Trigger>) {
  return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />
}

function TooltipContent({
  className,
  sideOffset = 0,
  arrow = true,
  children,
  ...props
}: React.ComponentProps<typeof TooltipPrimitive.Content> & {
  /** Hide the pointer arrow (custom-surfaced tooltips, e.g. the app's dark
   *  menu-styled ones, where the bg-foreground diamond clashes). */
  arrow?: boolean
}) {
  return (
    <TooltipPrimitive.Portal>
      <TooltipPrimitive.Content
        data-slot="tooltip-content"
        sideOffset={sideOffset}
        className={cn(
          "z-50 inline-flex w-fit max-w-xs origin-(--radix-tooltip-content-transform-origin) items-center gap-1.5 rounded-md bg-foreground px-3 py-1.5 text-xs text-background has-data-[slot=kbd]:pr-1.5 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 **:data-[slot=kbd]:relative **:data-[slot=kbd]:isolate **:data-[slot=kbd]:z-50 **:data-[slot=kbd]:rounded-sm data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
          className
        )}
        {...props}
      >
        {children}
        {arrow && (
          <TooltipPrimitive.Arrow className="z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground" />
        )}
      </TooltipPrimitive.Content>
    </TooltipPrimitive.Portal>
  )
}

export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger }
```
