Skip to Content
Habi

Card

Presents one service, office or update, with a way to start or find out more.

DFA · Passport

Renew your passport

Book an appointment online, prepare your old passport, and pay the fee before you go to the consular office.

  • About 15 minutes
  • Online
  • ₱950.00

Installation

npm install class-variance-authority clsx tailwind-merge

Add the cn helper if you haven't already:

lib/utils.ts
import { clsx, type ClassValue } from "clsx";
import { extendTailwindMerge } from "tailwind-merge";

const twMerge = extendTailwindMerge({
  extend: {
    theme: {
      text: [
        "display",
        "heading-xl",
        "heading-lg",
        "heading-md",
        "heading-sm",
        "heading-xs",
        "body-lg",
        "body-md",
        "body-sm",
        "label",
        "helper",
        "button",
      ],
      "font-weight": ["regular"],
    },
  },
});

export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs));
}

Add the component:

components/ui/card.tsx
import type { ComponentProps } from "react";
import { cva, type VariantProps } from "class-variance-authority";

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

const cardVariants = cva(
  "group/card flex flex-col overflow-hidden rounded-sm border border-border-subtle-01 bg-layer-01 text-text-primary",
  {
    variants: {
      layout: {
        vertical: "",
        horizontal: "sm:flex-row",
      },
    },
    defaultVariants: {
      layout: "vertical",
    },
  },
);

type CardProps = ComponentProps<"div"> & VariantProps<typeof cardVariants>;

function Card({ className, layout, ...props }: CardProps) {
  return (
    <div
      data-slot="card"
      data-layout={layout ?? "vertical"}
      className={cn(cardVariants({ layout }), className)}
      {...props}
    />
  );
}

function CardImage({ className, ...props }: ComponentProps<"div">) {
  return (
    <div
      data-slot="card-image"
      className={cn(
        "relative h-50 w-full shrink-0 overflow-hidden bg-layer-accent-01 [&_img]:size-full [&_img]:object-cover",
        "sm:group-data-[layout=horizontal]/card:h-auto sm:group-data-[layout=horizontal]/card:min-h-50 sm:group-data-[layout=horizontal]/card:w-60",
        className,
      )}
      {...props}
    />
  );
}

function CardIcon({ className, ...props }: ComponentProps<"div">) {
  return (
    <div
      data-slot="card-icon"
      className={cn(
        "mx-6 mt-6 flex size-12 shrink-0 items-center justify-center rounded-md bg-highlight-default text-icon-interactive [&_svg]:size-6",
        "sm:group-data-[layout=horizontal]/card:mr-0",
        className,
      )}
      {...props}
    />
  );
}

function CardBody({ className, ...props }: ComponentProps<"div">) {
  return (
    <div
      data-slot="card-body"
      className={cn("flex min-w-0 flex-1 flex-col gap-6 p-6", className)}
      {...props}
    />
  );
}

function CardHeader({ className, ...props }: ComponentProps<"div">) {
  return (
    <div
      data-slot="card-header"
      className={cn("flex flex-col gap-2", className)}
      {...props}
    />
  );
}

function CardBadges({ className, ...props }: ComponentProps<"div">) {
  return (
    <div
      data-slot="card-badges"
      className={cn("flex flex-wrap gap-2", className)}
      {...props}
    />
  );
}

function CardEyebrow({ className, ...props }: ComponentProps<"p">) {
  return (
    <p
      data-slot="card-eyebrow"
      className={cn("text-label text-text-secondary", className)}
      {...props}
    />
  );
}

type CardTitleProps = ComponentProps<"h3"> & { level?: 2 | 3 | 4 | 5 | 6 };

function CardTitle({ className, level = 3, ...props }: CardTitleProps) {
  const Heading = `h${level}` as const;

  return (
    <Heading
      data-slot="card-title"
      className={cn("text-heading-sm text-text-primary", className)}
      {...props}
    />
  );
}

function CardDescription({ className, ...props }: ComponentProps<"p">) {
  return (
    <p
      data-slot="card-description"
      className={cn("text-body-md text-text-secondary", className)}
      {...props}
    />
  );
}

function CardMeta({ className, ...props }: ComponentProps<"ul">) {
  return (
    <ul
      data-slot="card-meta"
      className={cn(
        "flex flex-wrap gap-x-4 gap-y-2 text-body-sm text-text-secondary",
        className,
      )}
      {...props}
    />
  );
}

function CardMetaItem({ className, ...props }: ComponentProps<"li">) {
  return (
    <li
      data-slot="card-meta-item"
      className={cn(
        "inline-flex items-center gap-2 [&_svg]:size-5 [&_svg]:shrink-0 [&_svg]:text-icon-secondary",
        className,
      )}
      {...props}
    />
  );
}

function CardActions({ className, ...props }: ComponentProps<"div">) {
  return (
    <div
      data-slot="card-actions"
      className={cn("flex flex-wrap items-center gap-x-6 gap-y-4", className)}
      {...props}
    />
  );
}

export {
  Card,
  CardActions,
  CardBadges,
  CardBody,
  CardDescription,
  CardEyebrow,
  CardHeader,
  CardIcon,
  CardImage,
  CardMeta,
  CardMetaItem,
  CardTitle,
  cardVariants,
  type CardProps,
  type CardTitleProps,
};

Cards usually contain a Badge, Button or Link, so install those too.

Usage

Use only the parts you need, in this order:

import {
  Card,
  CardActions,
  CardBadges,
  CardBody,
  CardDescription,
  CardEyebrow,
  CardHeader,
  CardIcon,
  CardImage,
  CardMeta,
  CardMetaItem,
  CardTitle,
} from "@/components/ui/card";

<Card>
  <CardImage /> {/* or <CardIcon /> */}
  <CardBody>
    <CardHeader>
      <CardBadges />
      <CardEyebrow />
      <CardTitle />
      <CardDescription />
    </CardHeader>
    <CardMeta>
      <CardMetaItem />
    </CardMeta>
    <CardActions />
  </CardBody>
</Card>;

Examples

With an icon

Use an icon for services. Pick an outline icon from @heroicons/react/24/outline.

PSA · PhilSys

Register for a National ID

Book a registration slot, then bring one supporting document to your appointment.

  • About 30 minutes
  • In person

With an image

Use an image for news and places. If the image only decorates the card, give it an empty alt="".

New

New consular office opens in Davao

Book passport appointments closer to home from April.

  • 15 March 2026

Horizontal

Use the horizontal layout for lists. On screens narrower than 640px it stacks like a vertical card.

DFA · Passport

Renew your passport

Book an appointment online, prepare your old passport, and pay the fee before you go to the consular office.

  • About 15 minutes
  • Online

Writing for cards

  • One card, one task: each card is one thing people can start or read.
  • Title as a verb for services: "Renew your passport", not "Passport renewal".
  • Meta says time, channel and cost: "About 15 minutes", "Online", "₱950.00".
  • Unique link text: if several cards say "Learn more", add hidden text so each link makes sense on its own.

Props

Card

PropTypeDefaultDescription
layout"vertical" | "horizontal""vertical"Vertical for grids, horizontal for lists. Horizontal cards stack on small screens.

CardTitle

PropTypeDefaultDescription
level2 | 3 | 4 | 5 | 63The heading level. Pick the one that fits the page's heading structure.

Every part also accepts the props of the HTML element it renders: div, p, a heading, ul or li.

Accessibility

  • Headings: each card title is a heading, so screen reader users can jump from card to card. Set level so it follows the page's headings: under an h2 section, use the default h3.
  • Link text: say where each link goes. When cards repeat the same words, like "Learn more", add sr-only text after the visible words: "Learn more about renewing your passport".
  • Meta is a list, so screen readers say how many facts there are. Its icons are decorative: the text carries the meaning.
  • Images: use alt="" when the image is decorative, and describe it when it shows something the text doesn't.
  • Focus order follows reading order: title, then actions. Don't make the whole card one big link around other links.

On this page