Skip to content

Type to search the docs, API, and blog.

↑↓ navigate↵ openesc close
  • Zazz 0.14 alpha

    API

    Card

    A surface that groups related content.

    Installation

    Source
    pnpm dlx zazz-ui add card
    npx zazz-ui add card
    yarn dlx zazz-ui add card
    bunx zazz-ui add card

    Run zazz-ui init first if the project has no zazz/ folder yet.

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Paint the right theme (background, form controls, scrollbars) before CSS loads -->
    <meta name="color-scheme" content="light dark">
    <!-- Zazz styles: base layers, then card in cascade order -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_layers.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_variables.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_shadows.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_breakpoints.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_reset.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_typography.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_view-transitions.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/primitives/card/card.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-sm.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-md.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-lg.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-xl.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-2xl.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-disabled.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-active.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-focus-visible.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-focus-within.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-hover.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-checked.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-current.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-open.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-stuck.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-starting.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-sm.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-md.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-lg.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-xl.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-2xl.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-disabled.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-active.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-focus-visible.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-focus-within.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-hover.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-checked.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-current.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-open.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-stuck.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-starting.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-flow.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-grid.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-spacing.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-margin.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-sizing.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-typography.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-color.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-effects.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-box.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-pseudo.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_defaults.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-sr.css">
    <!-- Import map: bare specifiers in Zazz scripts resolve to pinned, SRI-checked files -->
    <script type="importmap">
    {
      "imports": {
        "signal-polyfill": "https://cdn.jsdelivr.net/npm/signal-polyfill@0.2.2/dist/index.js"
      },
      "integrity": {
        "https://cdn.jsdelivr.net/npm/signal-polyfill@0.2.2/dist/index.js": "sha384-0OqM7OXGT6Oz1z98u/geiFn/FUyz4iWexkXHCvbIGXRRDXl6bp6IKc0j78AQ6DEK"
      }
    }
    </script>
    <!-- Polyfill: Interest Invokers (interestfor) — native in Chromium only -->
    <script type="module" src="https://cdn.jsdelivr.net/npm/invokers@2.2.2/dist/esm/production/interest.js" integrity="sha384-hR2BVNtsS7fIIMwOm+f7MY0JZfuByGhQQfevCBB6evFATKzBsTw0JzH/RxD94z2T" crossorigin="anonymous"></script>
    <!-- Zazz behavior: side-effect modules by tag; the rest via module imports -->
    <script type="module" src="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/dialog-lifecycle.js"></script>
    <!-- Theme: apply the persisted (or preferred) scheme before first paint -->
    <script>
      (() => {
        try {
          // A stored choice pins the scheme with data-theme; with no choice the
          // page follows the system scheme.
          const storedTheme = localStorage.getItem("theme");
          if (storedTheme === "dark" || storedTheme === "light") {
            document.documentElement.dataset.theme = storedTheme;
          }
        } catch {
          /* no storage access: follow the system scheme */
        }
      })();
    </script>

    A <head> that loads the base layers and card from jsDelivr, pinned to 0.14.2. To load the whole kit in two requests, see the CDN install.

    Anatomy

    Use <ui-card> when the card would otherwise be a div, and data-ui="card" when it has a better element of its own: <article data-ui="card"> for a post or a product, <form data-ui="card"> for a sign-in form.

    Mark its direct children with data-card-slot:

    • header: an image, a <figure>, or an <hgroup>. A header that is an img, picture, or video, a figure without a figcaption, or an element holding only an img, picture, or video bleeds over the card's padding to its rounded edge. The bleed follows --p (and --ui-card-p), not the per-side padding utilities like --pt or --px.
    • body: the card's main content.
    • footer: actions, a price, or an author.

    data-card-orientation="horizontal" puts the header in a start column spanning the card's rows, with the body above the footer in the end column, and needs a header slot. It applies once the card's nearest container is at least 40rem wide (the sm breakpoint) and stacks below that, so give the card's parent --container-type: inline-size to follow the parent's width instead of the page's (a data-ui="layout" child already is one). Set the column's width with --ui-card-header-w (default 40%; auto fits an avatar). A media header (an img or video, bare or alone in a figure or wrapper) fills the column's height and crops to it with object-fit: cover. data-card-orientation="vertical" names the default, stacked layout.

    Examples

    Default

    Elephants crossing a dusty riverbed

    Default

    Bare: no padding, radius, or surface, so media runs edge to edge.

    Elephants crossing a dusty riverbed

    Outline

    Padding, the radius, and a border. The header image bleeds to the card's edges.

    Elephants crossing a dusty riverbed

    Muted

    Padding, the radius, and the muted surface, for quieter groupings.

    Elephants crossing a dusty riverbed

    Floating

    Padding, the radius, the card surface, a border, and a small shadow.

    <div
      style="
        --display: grid;
        --template-cols: repeat(auto-fit, minmax(min(100%, max(14rem, 40%)), 1fr));
        --gap: 6;
        --w: 100%;
      "
    >
      <ui-card>
        <figure
          data-card-slot="header"
          style="
            --aspect: 3 / 2;
            --radius: var(--ui-card-radius);
            --overflow: hidden;
          "
        >
          <img
            width="600"
            height="400"
            loading="lazy"
            src="https://images.unsplash.com/photo-1564760055775-d63b17a55c44?auto=format&fit=crop&w=600&h=400&q=60"
            alt="Elephants crossing a dusty riverbed"
            style="
              --size: 100%;
              --object-fit: cover;
            "
          />
        </figure>
        <hgroup
          data-card-slot="body"
          style="
            --display: grid;
            --gap: 1;
          "
        >
          <h3 data-ui="text-lg">Default</h3>
          <p data-ui="text-sm" style="--text: var(--color-muted-foreground)">
            Bare: no padding, radius, or surface, so media runs edge to edge.
          </p>
        </hgroup>
        <footer data-card-slot="footer">
          <a href="#" data-ui="button" data-button-variant="outline">Read field notes</a>
        </footer>
      </ui-card>
      <ui-card data-card-variant="outline">
        <figure data-card-slot="header" style="--aspect: 3 / 2">
          <img
            width="600"
            height="400"
            loading="lazy"
            src="https://images.unsplash.com/photo-1564760055775-d63b17a55c44?auto=format&fit=crop&w=600&h=400&q=60"
            alt="Elephants crossing a dusty riverbed"
            style="
              --size: 100%;
              --object-fit: cover;
            "
          />
        </figure>
        <hgroup
          data-card-slot="body"
          style="
            --display: grid;
            --gap: 1;
          "
        >
          <h3 data-ui="text-lg">Outline</h3>
          <p data-ui="text-sm" style="--text: var(--color-muted-foreground)">
            Padding, the radius, and a border. The header image bleeds to the card's edges.
          </p>
        </hgroup>
        <footer data-card-slot="footer">
          <a href="#" data-ui="button" data-button-variant="outline">Read field notes</a>
        </footer>
      </ui-card>
      <ui-card data-card-variant="muted">
        <figure data-card-slot="header" style="--aspect: 3 / 2">
          <img
            width="600"
            height="400"
            loading="lazy"
            src="https://images.unsplash.com/photo-1564760055775-d63b17a55c44?auto=format&fit=crop&w=600&h=400&q=60"
            alt="Elephants crossing a dusty riverbed"
            style="
              --size: 100%;
              --object-fit: cover;
            "
          />
        </figure>
        <hgroup
          data-card-slot="body"
          style="
            --display: grid;
            --gap: 1;
          "
        >
          <h3 data-ui="text-lg">Muted</h3>
          <p data-ui="text-sm" style="--text: var(--color-muted-foreground)">
            Padding, the radius, and the muted surface, for quieter groupings.
          </p>
        </hgroup>
        <footer data-card-slot="footer">
          <a href="#" data-ui="button" data-button-variant="primary">Read field notes</a>
        </footer>
      </ui-card>
      <ui-card data-card-variant="floating">
        <figure data-card-slot="header" style="--aspect: 3 / 2">
          <img
            width="600"
            height="400"
            loading="lazy"
            src="https://images.unsplash.com/photo-1564760055775-d63b17a55c44?auto=format&fit=crop&w=600&h=400&q=60"
            alt="Elephants crossing a dusty riverbed"
            style="
              --size: 100%;
              --object-fit: cover;
            "
          />
        </figure>
        <hgroup
          data-card-slot="body"
          style="
            --display: grid;
            --gap: 1;
          "
        >
          <h3 data-ui="text-lg">Floating</h3>
          <p data-ui="text-sm" style="--text: var(--color-muted-foreground)">
            Padding, the radius, the card surface, a border, and a small shadow.
          </p>
        </hgroup>
        <footer data-card-slot="footer">
          <a href="#" data-ui="button" data-button-variant="primary">Read field notes</a>
        </footer>
      </ui-card>
    </div>
    /**
     * card.css: Card (ui-card | [data-ui~="card"])
     *
     * @layer      variables, components
     * @requires   _layers.css, _variables.css, _properties.css (--_*-resolved)
     * @uses       corner-shape — superellipse corners; unsupported browsers keep plain
     *             rounded corners
     * @uses       :has() — a header that holds only media bleeds to the card's edge;
     *             a horizontal card needs a header slot
     * @uses       @container (width >= 40rem) — a horizontal card lays out in two columns
     *             once its nearest container reaches sm, and stacks below that
     * @tokens     --ui-card-* (@layer variables; named after the utilities they back)
     * @presets    data-card-variant="outline" | "muted" | "floating"
     * @presets    data-card-orientation="vertical" | "horizontal"
     *
     * The card is a surface: a grid with a gap, the card colors, a radius, and
     * clipped overflow. The default card is bare (no padding, radius, or shadow), so
     * media can run edge to edge; each variant adds padding, the radius, and one
     * treatment. Every card keeps a 1px border, transparent unless a variant colors
     * it, so cards line up whatever their variant.
     *
     * Its parts are plain elements laid out with utilities, or the slots
     * data-card-slot="header" | "body" | "footer" on direct children. A header that
     * is an img/picture/video, a figure without a figcaption, or an element holding
     * only an img/picture/video bleeds: negative margins pull it over the card's
     * padding to the clipped, rounded edge. The bleed follows --p and --ui-card-p,
     * not the per-side padding utilities.
     *
     * data-card-orientation="horizontal" puts the header in a start column
     * (--ui-card-header-w, default 40%) spanning the rows, with the body above the footer in the
     * end column. It applies when the nearest container is at least sm (40rem) wide,
     * like the --*--sm utilities, and the card stacks below that; give the card's
     * parent --container-type: inline-size to follow the parent's width. Don't make
     * a horizontal card a container itself: its slots would query it, not the parent.
     * Vertical is the default; the attribute only names it.
     *
     * Every utility-backed declaration reads one chain, highest first:
     *   var(--_<utility>-resolved, var(--_card-<utility>, var(--ui-card-<utility>)))
     */
    
    @layer variables {
      :root {
        /* a bare card has no surface; the outline and floating variants paint --color-card */
        --ui-card-display: grid;
        --ui-card-place-content: start stretch;
        --ui-card-bg: transparent;
        --ui-card-text: var(--color-card-foreground);
        --ui-card-radius: var(--radius-lg);
        --ui-card-corner-shape: var(--radius-corner-shape);
        --ui-card-shadow: none;
    
        --ui-card-border-width: 1px;
        --ui-card-border-style: solid;
        --ui-card-border-color: transparent;
    
        /* dual-mode: a scale number or a length */
        --ui-card-gap: var(--space-sm);
        --ui-card-p: 0;
    
        /* horizontal: the header column's width */
        --ui-card-header-w: 40%;
      }
    }
    
    /* Variant privates: non-inheriting so a variant never cascades into a nested card. */
    @property --_card-bg {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-text {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-shadow {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-border-width {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-border-color {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-radius {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-p {
      syntax: "*";
      inherits: false;
    }
    
    /* The resolved padding, inherited so a media header can bleed over it. Every card
       sets its own, so it never carries into a nested card. */
    @property --_card-inset {
      syntax: "*";
      inherits: true;
    }
    
    @layer ui.components {
      :where(ui-card, [data-ui~="card"]) {
        display: var(--ui-card-display);
        place-content: var(--ui-card-place-content);
        grid-template-columns: minmax(0, 1fr);
        --_gap-len: var(--_gap-resolved, var(--ui-card-gap));
        --_gap-num: var(--_gap-resolved, var(--ui-card-gap));
        gap: calc(var(--_gap-len) + var(--_gap-num) * var(--spacing));
        --_p-len: var(--_p-resolved, var(--_card-p, var(--ui-card-p)));
        --_p-num: var(--_p-resolved, var(--_card-p, var(--ui-card-p)));
        --_card-inset: calc(var(--_p-len) + var(--_p-num) * var(--spacing));
        padding: var(--_card-inset);
        color: var(--_text-resolved, var(--_card-text, var(--ui-card-text)));
        background-color: var(--_bg-resolved, var(--_card-bg, var(--ui-card-bg)));
        border-width: var(
          --_border-width-resolved,
          var(--_card-border-width, var(--ui-card-border-width))
        );
        border-style: var(--_border-style-resolved, var(--ui-card-border-style));
        border-color: var(
          --_border-color-resolved,
          var(--_card-border-color, var(--ui-card-border-color))
        );
        --_radius-len: var(--_radius-resolved, var(--_card-radius, var(--ui-card-radius)));
        --_radius-num: var(--_radius-resolved, var(--_card-radius, var(--ui-card-radius)));
        border-radius: calc(
          var(--_radius-len) + var(--_radius-num) * var(--spacing) * var(--radius-multiplier)
        );
        corner-shape: var(--_corner-shape-resolved, var(--ui-card-corner-shape));
        box-shadow: var(--_shadow-resolved, var(--_card-shadow, var(--ui-card-shadow)));
        background-clip: var(--_bg-clip-resolved, border-box);
        overflow: clip;
        transition: var(--default-transition);
      }
    
      /* ===========================================================================
      CARD VARIANTS — data-card-variant writes the privates
      =========================================================================== */
    
      :where(ui-card:not([data-card-variant]), [data-ui~="card"]:not([data-card-variant])) {
        --_card-radius: 0;
      }
    
      :where(ui-card[data-card-variant="outline"], [data-ui~="card"][data-card-variant="outline"]) {
        --_card-p: var(--space-md);
        --_card-border-color: var(--color-border);
      }
    
      :where(ui-card[data-card-variant="muted"], [data-ui~="card"][data-card-variant="muted"]) {
        --_card-p: var(--space-md);
        --_card-bg: var(--color-muted);
        --_card-text: var(--color-foreground);
      }
    
      :where(ui-card[data-card-variant="floating"], [data-ui~="card"][data-card-variant="floating"]) {
        --_card-p: var(--space-md);
        --_card-bg: var(--color-card);
        --_card-border-color: var(--color-border);
        --_card-text: var(--color-card-foreground);
        --_card-shadow: var(--shadow-sm);
      }
    
      /* ===========================================================================
      CARD SLOTS — header, body, footer on direct children
      =========================================================================== */
    
      /* a media header bleeds over the card's padding to its clipped edge */
      :where(
        :is(ui-card, [data-ui~="card"])
          > [data-card-slot~="header"]:is(
            img,
            picture,
            video,
            figure:not(:has(> figcaption)),
            :has(> :is(img, picture, video):only-child)
          )
      ) {
        margin-inline: calc(var(--_card-inset) * -1);
        margin-block-start: calc(var(--_card-inset) * -1);
      }
    
      /* ===========================================================================
      CARD ORIENTATION — data-card-orientation; vertical is the default
      =========================================================================== */
    
      :where(
        ui-card[data-card-orientation="vertical"],
        [data-ui~="card"][data-card-orientation="vertical"]
      ) {
        grid-template-columns: minmax(0, 1fr);
      }
    
      @container (width >= 40rem) {
        :where(
          :is(
            ui-card[data-card-orientation="horizontal"],
            [data-ui~="card"][data-card-orientation="horizontal"]
          ):has(> [data-card-slot~="header"])
        ) {
          grid-template-columns: var(--ui-card-header-w) minmax(0, 1fr);
          grid-template-rows: 1fr auto;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"]):not(:has(> [data-card-slot~="footer"]))
        ) {
          grid-template-rows: 1fr;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"])
            > [data-card-slot~="header"]
        ) {
          grid-column: 1;
          grid-row: 1 / -1;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"])
            > [data-card-slot~="body"]
        ) {
          grid-column: 2;
          grid-row: 1;
          /* the row stretches to the header; keep the body's own rows at the top */
          align-content: start;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"])
            > [data-card-slot~="footer"]
        ) {
          grid-column: 2;
          grid-row: 2;
        }
    
        /* the media header bleeds on its three outer sides */
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]:is(
              img,
              picture,
              video,
              figure:not(:has(> figcaption)),
              :has(> :is(img, picture, video):only-child)
            )
        ) {
          margin-block: calc(var(--_card-inset) * -1);
          margin-inline-end: 0;
        }
    
        /* the media fills the column's height and crops to it. A bare img or video
           is sized to its grid area plus the bleed (WebKit won't stretch a replaced
           grid item), and the media inside a wrapper takes the wrapper's full box */
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]:is(img, video)
        ) {
          inline-size: calc(100% + var(--_card-inset));
          max-inline-size: none;
          block-size: calc(100% + 2 * var(--_card-inset));
          object-fit: cover;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]:is(
              picture,
              figure:not(:has(> figcaption)),
              :has(> :is(img, picture, video):only-child)
            )
            > :is(img, video, picture),
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]
            > picture
            > img
        ) {
          display: block;
          inline-size: 100%;
          block-size: 100%;
          object-fit: cover;
        }
      }
    }

    Horizontal

    Elephants crossing a dusty riverbed

    Horizontal

    The header takes the start column, with the body above the footer in the end column. Below a 40rem container, the card stacks.

    John Doe

    Lead tracker, Okavango survey. A header that isn't media keeps the card's padding, and --ui-card-header-w: auto sizes its column to the avatar.

    <div
      style="
        --display: grid;
        --gap: 6;
      "
    >
      <ui-card data-card-variant="outline" data-card-orientation="horizontal">
        <figure data-card-slot="header">
          <img
            width="600"
            height="400"
            loading="lazy"
            src="https://images.unsplash.com/photo-1564760055775-d63b17a55c44?auto=format&fit=crop&w=600&h=400&q=60"
            alt="Elephants crossing a dusty riverbed"
            style="
              --size: 100%;
              --object-fit: cover;
            "
          />
        </figure>
        <hgroup
          data-card-slot="body"
          style="
            --display: grid;
            --gap: 1;
          "
        >
          <h3 data-ui="text-lg">Horizontal</h3>
          <p data-ui="text-sm" style="--text: var(--color-muted-foreground)">
            The header takes the start column, with the body above the footer in the end column. Below a
            40rem container, the card stacks.
          </p>
        </hgroup>
        <footer data-card-slot="footer">
          <a href="#" data-ui="button" data-button-variant="outline">Read field notes</a>
        </footer>
      </ui-card>
      <ui-card
        data-card-variant="floating"
        data-card-orientation="horizontal"
        style="--ui-card-header-w: auto"
      >
        <div data-card-slot="header">
          <figure
            role="img"
            aria-label="John Doe"
            style="
              --display: grid-pile;
              --size: 12;
              --text: var(--color-primary-foreground);
              --bg: var(--color-primary);
              --radius: full;
              --overflow: clip;
            "
          >
            <span aria-hidden="true" style="--font-weight: strong">AO</span>
          </figure>
        </div>
        <hgroup
          data-card-slot="body"
          style="
            --display: grid;
            --gap: 1;
          "
        >
          <h3 data-ui="text-lg">John Doe</h3>
          <p data-ui="text-sm" style="--text: var(--color-muted-foreground)">
            Lead tracker, Okavango survey. A header that isn't media keeps the card's padding, and
            <code>--ui-card-header-w: auto</code> sizes its column to the avatar.
          </p>
        </hgroup>
        <footer
          data-card-slot="footer"
          style="
            --display: flex;
            --gap: 2;
          "
        >
          <button type="button" data-ui="button" data-button-variant="primary">Follow</button>
          <button type="button" data-ui="button" data-button-variant="ghost">Message</button>
        </footer>
      </ui-card>
    </div>
    /**
     * card.css: Card (ui-card | [data-ui~="card"])
     *
     * @layer      variables, components
     * @requires   _layers.css, _variables.css, _properties.css (--_*-resolved)
     * @uses       corner-shape — superellipse corners; unsupported browsers keep plain
     *             rounded corners
     * @uses       :has() — a header that holds only media bleeds to the card's edge;
     *             a horizontal card needs a header slot
     * @uses       @container (width >= 40rem) — a horizontal card lays out in two columns
     *             once its nearest container reaches sm, and stacks below that
     * @tokens     --ui-card-* (@layer variables; named after the utilities they back)
     * @presets    data-card-variant="outline" | "muted" | "floating"
     * @presets    data-card-orientation="vertical" | "horizontal"
     *
     * The card is a surface: a grid with a gap, the card colors, a radius, and
     * clipped overflow. The default card is bare (no padding, radius, or shadow), so
     * media can run edge to edge; each variant adds padding, the radius, and one
     * treatment. Every card keeps a 1px border, transparent unless a variant colors
     * it, so cards line up whatever their variant.
     *
     * Its parts are plain elements laid out with utilities, or the slots
     * data-card-slot="header" | "body" | "footer" on direct children. A header that
     * is an img/picture/video, a figure without a figcaption, or an element holding
     * only an img/picture/video bleeds: negative margins pull it over the card's
     * padding to the clipped, rounded edge. The bleed follows --p and --ui-card-p,
     * not the per-side padding utilities.
     *
     * data-card-orientation="horizontal" puts the header in a start column
     * (--ui-card-header-w, default 40%) spanning the rows, with the body above the footer in the
     * end column. It applies when the nearest container is at least sm (40rem) wide,
     * like the --*--sm utilities, and the card stacks below that; give the card's
     * parent --container-type: inline-size to follow the parent's width. Don't make
     * a horizontal card a container itself: its slots would query it, not the parent.
     * Vertical is the default; the attribute only names it.
     *
     * Every utility-backed declaration reads one chain, highest first:
     *   var(--_<utility>-resolved, var(--_card-<utility>, var(--ui-card-<utility>)))
     */
    
    @layer variables {
      :root {
        /* a bare card has no surface; the outline and floating variants paint --color-card */
        --ui-card-display: grid;
        --ui-card-place-content: start stretch;
        --ui-card-bg: transparent;
        --ui-card-text: var(--color-card-foreground);
        --ui-card-radius: var(--radius-lg);
        --ui-card-corner-shape: var(--radius-corner-shape);
        --ui-card-shadow: none;
    
        --ui-card-border-width: 1px;
        --ui-card-border-style: solid;
        --ui-card-border-color: transparent;
    
        /* dual-mode: a scale number or a length */
        --ui-card-gap: var(--space-sm);
        --ui-card-p: 0;
    
        /* horizontal: the header column's width */
        --ui-card-header-w: 40%;
      }
    }
    
    /* Variant privates: non-inheriting so a variant never cascades into a nested card. */
    @property --_card-bg {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-text {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-shadow {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-border-width {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-border-color {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-radius {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-p {
      syntax: "*";
      inherits: false;
    }
    
    /* The resolved padding, inherited so a media header can bleed over it. Every card
       sets its own, so it never carries into a nested card. */
    @property --_card-inset {
      syntax: "*";
      inherits: true;
    }
    
    @layer ui.components {
      :where(ui-card, [data-ui~="card"]) {
        display: var(--ui-card-display);
        place-content: var(--ui-card-place-content);
        grid-template-columns: minmax(0, 1fr);
        --_gap-len: var(--_gap-resolved, var(--ui-card-gap));
        --_gap-num: var(--_gap-resolved, var(--ui-card-gap));
        gap: calc(var(--_gap-len) + var(--_gap-num) * var(--spacing));
        --_p-len: var(--_p-resolved, var(--_card-p, var(--ui-card-p)));
        --_p-num: var(--_p-resolved, var(--_card-p, var(--ui-card-p)));
        --_card-inset: calc(var(--_p-len) + var(--_p-num) * var(--spacing));
        padding: var(--_card-inset);
        color: var(--_text-resolved, var(--_card-text, var(--ui-card-text)));
        background-color: var(--_bg-resolved, var(--_card-bg, var(--ui-card-bg)));
        border-width: var(
          --_border-width-resolved,
          var(--_card-border-width, var(--ui-card-border-width))
        );
        border-style: var(--_border-style-resolved, var(--ui-card-border-style));
        border-color: var(
          --_border-color-resolved,
          var(--_card-border-color, var(--ui-card-border-color))
        );
        --_radius-len: var(--_radius-resolved, var(--_card-radius, var(--ui-card-radius)));
        --_radius-num: var(--_radius-resolved, var(--_card-radius, var(--ui-card-radius)));
        border-radius: calc(
          var(--_radius-len) + var(--_radius-num) * var(--spacing) * var(--radius-multiplier)
        );
        corner-shape: var(--_corner-shape-resolved, var(--ui-card-corner-shape));
        box-shadow: var(--_shadow-resolved, var(--_card-shadow, var(--ui-card-shadow)));
        background-clip: var(--_bg-clip-resolved, border-box);
        overflow: clip;
        transition: var(--default-transition);
      }
    
      /* ===========================================================================
      CARD VARIANTS — data-card-variant writes the privates
      =========================================================================== */
    
      :where(ui-card:not([data-card-variant]), [data-ui~="card"]:not([data-card-variant])) {
        --_card-radius: 0;
      }
    
      :where(ui-card[data-card-variant="outline"], [data-ui~="card"][data-card-variant="outline"]) {
        --_card-p: var(--space-md);
        --_card-border-color: var(--color-border);
      }
    
      :where(ui-card[data-card-variant="muted"], [data-ui~="card"][data-card-variant="muted"]) {
        --_card-p: var(--space-md);
        --_card-bg: var(--color-muted);
        --_card-text: var(--color-foreground);
      }
    
      :where(ui-card[data-card-variant="floating"], [data-ui~="card"][data-card-variant="floating"]) {
        --_card-p: var(--space-md);
        --_card-bg: var(--color-card);
        --_card-border-color: var(--color-border);
        --_card-text: var(--color-card-foreground);
        --_card-shadow: var(--shadow-sm);
      }
    
      /* ===========================================================================
      CARD SLOTS — header, body, footer on direct children
      =========================================================================== */
    
      /* a media header bleeds over the card's padding to its clipped edge */
      :where(
        :is(ui-card, [data-ui~="card"])
          > [data-card-slot~="header"]:is(
            img,
            picture,
            video,
            figure:not(:has(> figcaption)),
            :has(> :is(img, picture, video):only-child)
          )
      ) {
        margin-inline: calc(var(--_card-inset) * -1);
        margin-block-start: calc(var(--_card-inset) * -1);
      }
    
      /* ===========================================================================
      CARD ORIENTATION — data-card-orientation; vertical is the default
      =========================================================================== */
    
      :where(
        ui-card[data-card-orientation="vertical"],
        [data-ui~="card"][data-card-orientation="vertical"]
      ) {
        grid-template-columns: minmax(0, 1fr);
      }
    
      @container (width >= 40rem) {
        :where(
          :is(
            ui-card[data-card-orientation="horizontal"],
            [data-ui~="card"][data-card-orientation="horizontal"]
          ):has(> [data-card-slot~="header"])
        ) {
          grid-template-columns: var(--ui-card-header-w) minmax(0, 1fr);
          grid-template-rows: 1fr auto;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"]):not(:has(> [data-card-slot~="footer"]))
        ) {
          grid-template-rows: 1fr;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"])
            > [data-card-slot~="header"]
        ) {
          grid-column: 1;
          grid-row: 1 / -1;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"])
            > [data-card-slot~="body"]
        ) {
          grid-column: 2;
          grid-row: 1;
          /* the row stretches to the header; keep the body's own rows at the top */
          align-content: start;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"])
            > [data-card-slot~="footer"]
        ) {
          grid-column: 2;
          grid-row: 2;
        }
    
        /* the media header bleeds on its three outer sides */
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]:is(
              img,
              picture,
              video,
              figure:not(:has(> figcaption)),
              :has(> :is(img, picture, video):only-child)
            )
        ) {
          margin-block: calc(var(--_card-inset) * -1);
          margin-inline-end: 0;
        }
    
        /* the media fills the column's height and crops to it. A bare img or video
           is sized to its grid area plus the bleed (WebKit won't stretch a replaced
           grid item), and the media inside a wrapper takes the wrapper's full box */
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]:is(img, video)
        ) {
          inline-size: calc(100% + var(--_card-inset));
          max-inline-size: none;
          block-size: calc(100% + 2 * var(--_card-inset));
          object-fit: cover;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]:is(
              picture,
              figure:not(:has(> figcaption)),
              :has(> :is(img, picture, video):only-child)
            )
            > :is(img, video, picture),
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]
            > picture
            > img
        ) {
          display: block;
          inline-size: 100%;
          block-size: 100%;
          object-fit: cover;
        }
      }
    }

    Product

    Over-ear headphones on a yellow background
    In stock Free shipping

    Field monitor headphones

    Closed-back, 40 hours of battery, and a fold-flat frame for the trail.

    $189

    <ui-card data-card-variant="outline" style="--max-w: 80">
      <figure
        data-card-slot="header"
        style="
          --aspect: 1;
          --bg: var(--color-muted);
        "
      >
        <img
          width="480"
          height="480"
          loading="lazy"
          src="https://images.unsplash.com/photo-1505740420928-5e560c06d30e?auto=format&fit=crop&w=480&h=480&q=60"
          alt="Over-ear headphones on a yellow background"
          style="
            --size: 100%;
            --object-fit: cover;
          "
        />
      </figure>
      <div
        data-card-slot="body"
        style="
          --display: grid;
          --gap: 2;
        "
      >
        <div
          style="
            --display: flex;
            --items: center;
            --gap: 2;
          "
        >
          <span data-ui="badge" data-badge-variant="success">In stock</span>
          <span data-ui="badge" data-badge-variant="muted">Free shipping</span>
        </div>
        <h3 data-ui="text-lg">Field monitor headphones</h3>
        <p data-ui="text-sm" style="--text: var(--color-muted-foreground)">
          Closed-back, 40 hours of battery, and a fold-flat frame for the trail.
        </p>
        <p data-ui="text-xl" style="--font-weight: strong">$189</p>
      </div>
      <footer
        data-card-slot="footer"
        style="
          --display: flex;
          --gap: 2;
        "
      >
        <button type="button" data-ui="button" data-button-variant="primary" style="--flex: 1">
          Add to cart
        </button>
        <button
          type="button"
          data-ui="button"
          data-button-variant="outline"
          data-button-size="icon"
          aria-label="Save to wishlist"
          aria-pressed="false"
        >
          <svg
            xmlns="http://www.w3.org/2000/svg"
            viewBox="0 0 24 24"
            fill="none"
            stroke="currentColor"
            stroke-width="2"
            stroke-linecap="round"
            stroke-linejoin="round"
            aria-hidden="true"
          >
            <path
              d="M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z"
            />
          </svg>
        </button>
      </footer>
    </ui-card>
    /**
     * card.css: Card (ui-card | [data-ui~="card"])
     *
     * @layer      variables, components
     * @requires   _layers.css, _variables.css, _properties.css (--_*-resolved)
     * @uses       corner-shape — superellipse corners; unsupported browsers keep plain
     *             rounded corners
     * @uses       :has() — a header that holds only media bleeds to the card's edge;
     *             a horizontal card needs a header slot
     * @uses       @container (width >= 40rem) — a horizontal card lays out in two columns
     *             once its nearest container reaches sm, and stacks below that
     * @tokens     --ui-card-* (@layer variables; named after the utilities they back)
     * @presets    data-card-variant="outline" | "muted" | "floating"
     * @presets    data-card-orientation="vertical" | "horizontal"
     *
     * The card is a surface: a grid with a gap, the card colors, a radius, and
     * clipped overflow. The default card is bare (no padding, radius, or shadow), so
     * media can run edge to edge; each variant adds padding, the radius, and one
     * treatment. Every card keeps a 1px border, transparent unless a variant colors
     * it, so cards line up whatever their variant.
     *
     * Its parts are plain elements laid out with utilities, or the slots
     * data-card-slot="header" | "body" | "footer" on direct children. A header that
     * is an img/picture/video, a figure without a figcaption, or an element holding
     * only an img/picture/video bleeds: negative margins pull it over the card's
     * padding to the clipped, rounded edge. The bleed follows --p and --ui-card-p,
     * not the per-side padding utilities.
     *
     * data-card-orientation="horizontal" puts the header in a start column
     * (--ui-card-header-w, default 40%) spanning the rows, with the body above the footer in the
     * end column. It applies when the nearest container is at least sm (40rem) wide,
     * like the --*--sm utilities, and the card stacks below that; give the card's
     * parent --container-type: inline-size to follow the parent's width. Don't make
     * a horizontal card a container itself: its slots would query it, not the parent.
     * Vertical is the default; the attribute only names it.
     *
     * Every utility-backed declaration reads one chain, highest first:
     *   var(--_<utility>-resolved, var(--_card-<utility>, var(--ui-card-<utility>)))
     */
    
    @layer variables {
      :root {
        /* a bare card has no surface; the outline and floating variants paint --color-card */
        --ui-card-display: grid;
        --ui-card-place-content: start stretch;
        --ui-card-bg: transparent;
        --ui-card-text: var(--color-card-foreground);
        --ui-card-radius: var(--radius-lg);
        --ui-card-corner-shape: var(--radius-corner-shape);
        --ui-card-shadow: none;
    
        --ui-card-border-width: 1px;
        --ui-card-border-style: solid;
        --ui-card-border-color: transparent;
    
        /* dual-mode: a scale number or a length */
        --ui-card-gap: var(--space-sm);
        --ui-card-p: 0;
    
        /* horizontal: the header column's width */
        --ui-card-header-w: 40%;
      }
    }
    
    /* Variant privates: non-inheriting so a variant never cascades into a nested card. */
    @property --_card-bg {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-text {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-shadow {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-border-width {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-border-color {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-radius {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-p {
      syntax: "*";
      inherits: false;
    }
    
    /* The resolved padding, inherited so a media header can bleed over it. Every card
       sets its own, so it never carries into a nested card. */
    @property --_card-inset {
      syntax: "*";
      inherits: true;
    }
    
    @layer ui.components {
      :where(ui-card, [data-ui~="card"]) {
        display: var(--ui-card-display);
        place-content: var(--ui-card-place-content);
        grid-template-columns: minmax(0, 1fr);
        --_gap-len: var(--_gap-resolved, var(--ui-card-gap));
        --_gap-num: var(--_gap-resolved, var(--ui-card-gap));
        gap: calc(var(--_gap-len) + var(--_gap-num) * var(--spacing));
        --_p-len: var(--_p-resolved, var(--_card-p, var(--ui-card-p)));
        --_p-num: var(--_p-resolved, var(--_card-p, var(--ui-card-p)));
        --_card-inset: calc(var(--_p-len) + var(--_p-num) * var(--spacing));
        padding: var(--_card-inset);
        color: var(--_text-resolved, var(--_card-text, var(--ui-card-text)));
        background-color: var(--_bg-resolved, var(--_card-bg, var(--ui-card-bg)));
        border-width: var(
          --_border-width-resolved,
          var(--_card-border-width, var(--ui-card-border-width))
        );
        border-style: var(--_border-style-resolved, var(--ui-card-border-style));
        border-color: var(
          --_border-color-resolved,
          var(--_card-border-color, var(--ui-card-border-color))
        );
        --_radius-len: var(--_radius-resolved, var(--_card-radius, var(--ui-card-radius)));
        --_radius-num: var(--_radius-resolved, var(--_card-radius, var(--ui-card-radius)));
        border-radius: calc(
          var(--_radius-len) + var(--_radius-num) * var(--spacing) * var(--radius-multiplier)
        );
        corner-shape: var(--_corner-shape-resolved, var(--ui-card-corner-shape));
        box-shadow: var(--_shadow-resolved, var(--_card-shadow, var(--ui-card-shadow)));
        background-clip: var(--_bg-clip-resolved, border-box);
        overflow: clip;
        transition: var(--default-transition);
      }
    
      /* ===========================================================================
      CARD VARIANTS — data-card-variant writes the privates
      =========================================================================== */
    
      :where(ui-card:not([data-card-variant]), [data-ui~="card"]:not([data-card-variant])) {
        --_card-radius: 0;
      }
    
      :where(ui-card[data-card-variant="outline"], [data-ui~="card"][data-card-variant="outline"]) {
        --_card-p: var(--space-md);
        --_card-border-color: var(--color-border);
      }
    
      :where(ui-card[data-card-variant="muted"], [data-ui~="card"][data-card-variant="muted"]) {
        --_card-p: var(--space-md);
        --_card-bg: var(--color-muted);
        --_card-text: var(--color-foreground);
      }
    
      :where(ui-card[data-card-variant="floating"], [data-ui~="card"][data-card-variant="floating"]) {
        --_card-p: var(--space-md);
        --_card-bg: var(--color-card);
        --_card-border-color: var(--color-border);
        --_card-text: var(--color-card-foreground);
        --_card-shadow: var(--shadow-sm);
      }
    
      /* ===========================================================================
      CARD SLOTS — header, body, footer on direct children
      =========================================================================== */
    
      /* a media header bleeds over the card's padding to its clipped edge */
      :where(
        :is(ui-card, [data-ui~="card"])
          > [data-card-slot~="header"]:is(
            img,
            picture,
            video,
            figure:not(:has(> figcaption)),
            :has(> :is(img, picture, video):only-child)
          )
      ) {
        margin-inline: calc(var(--_card-inset) * -1);
        margin-block-start: calc(var(--_card-inset) * -1);
      }
    
      /* ===========================================================================
      CARD ORIENTATION — data-card-orientation; vertical is the default
      =========================================================================== */
    
      :where(
        ui-card[data-card-orientation="vertical"],
        [data-ui~="card"][data-card-orientation="vertical"]
      ) {
        grid-template-columns: minmax(0, 1fr);
      }
    
      @container (width >= 40rem) {
        :where(
          :is(
            ui-card[data-card-orientation="horizontal"],
            [data-ui~="card"][data-card-orientation="horizontal"]
          ):has(> [data-card-slot~="header"])
        ) {
          grid-template-columns: var(--ui-card-header-w) minmax(0, 1fr);
          grid-template-rows: 1fr auto;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"]):not(:has(> [data-card-slot~="footer"]))
        ) {
          grid-template-rows: 1fr;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"])
            > [data-card-slot~="header"]
        ) {
          grid-column: 1;
          grid-row: 1 / -1;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"])
            > [data-card-slot~="body"]
        ) {
          grid-column: 2;
          grid-row: 1;
          /* the row stretches to the header; keep the body's own rows at the top */
          align-content: start;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"])
            > [data-card-slot~="footer"]
        ) {
          grid-column: 2;
          grid-row: 2;
        }
    
        /* the media header bleeds on its three outer sides */
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]:is(
              img,
              picture,
              video,
              figure:not(:has(> figcaption)),
              :has(> :is(img, picture, video):only-child)
            )
        ) {
          margin-block: calc(var(--_card-inset) * -1);
          margin-inline-end: 0;
        }
    
        /* the media fills the column's height and crops to it. A bare img or video
           is sized to its grid area plus the bleed (WebKit won't stretch a replaced
           grid item), and the media inside a wrapper takes the wrapper's full box */
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]:is(img, video)
        ) {
          inline-size: calc(100% + var(--_card-inset));
          max-inline-size: none;
          block-size: calc(100% + 2 * var(--_card-inset));
          object-fit: cover;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]:is(
              picture,
              figure:not(:has(> figcaption)),
              :has(> :is(img, picture, video):only-child)
            )
            > :is(img, video, picture),
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]
            > picture
            > img
        ) {
          display: block;
          inline-size: 100%;
          block-size: 100%;
          object-fit: cover;
        }
      }
    }

    Login

    Sign in

    Log sightings and sync your field notes.

    <form
      data-ui="card"
      data-card-variant="floating"
      aria-labelledby="card-login-title"
      style="
        --w: 100%;
        --max-w: 96;
      "
    >
      <hgroup
        data-card-slot="header"
        style="
          --display: grid;
          --gap: 1;
        "
      >
        <h3 id="card-login-title" data-ui="text-lg">Sign in</h3>
        <p data-ui="text-sm" style="--text: var(--color-muted-foreground)">
          Log sightings and sync your field notes.
        </p>
      </hgroup>
      <div
        data-card-slot="body"
        style="
          --display: grid;
          --gap: 4;
        "
      >
        <div data-ui="field">
          <label data-field-slot="label" for="card-login-email">Email</label>
          <input
            data-ui="input"
            id="card-login-email"
            name="card-login-email"
            type="email"
            required
            placeholder="you@example.com"
            autocomplete="email"
          />
        </div>
      </div>
      <footer
        data-card-slot="footer"
        style="
          --display: grid;
          --gap: 3;
          --text-align: center;
        "
      >
        <button type="submit" data-ui="button" data-button-variant="primary">Send a login code</button>
        <p data-ui="text-sm">
          New here?
          <a href="#" data-ui="text-link">Create an account</a>
        </p>
      </footer>
    </form>
    /**
     * card.css: Card (ui-card | [data-ui~="card"])
     *
     * @layer      variables, components
     * @requires   _layers.css, _variables.css, _properties.css (--_*-resolved)
     * @uses       corner-shape — superellipse corners; unsupported browsers keep plain
     *             rounded corners
     * @uses       :has() — a header that holds only media bleeds to the card's edge;
     *             a horizontal card needs a header slot
     * @uses       @container (width >= 40rem) — a horizontal card lays out in two columns
     *             once its nearest container reaches sm, and stacks below that
     * @tokens     --ui-card-* (@layer variables; named after the utilities they back)
     * @presets    data-card-variant="outline" | "muted" | "floating"
     * @presets    data-card-orientation="vertical" | "horizontal"
     *
     * The card is a surface: a grid with a gap, the card colors, a radius, and
     * clipped overflow. The default card is bare (no padding, radius, or shadow), so
     * media can run edge to edge; each variant adds padding, the radius, and one
     * treatment. Every card keeps a 1px border, transparent unless a variant colors
     * it, so cards line up whatever their variant.
     *
     * Its parts are plain elements laid out with utilities, or the slots
     * data-card-slot="header" | "body" | "footer" on direct children. A header that
     * is an img/picture/video, a figure without a figcaption, or an element holding
     * only an img/picture/video bleeds: negative margins pull it over the card's
     * padding to the clipped, rounded edge. The bleed follows --p and --ui-card-p,
     * not the per-side padding utilities.
     *
     * data-card-orientation="horizontal" puts the header in a start column
     * (--ui-card-header-w, default 40%) spanning the rows, with the body above the footer in the
     * end column. It applies when the nearest container is at least sm (40rem) wide,
     * like the --*--sm utilities, and the card stacks below that; give the card's
     * parent --container-type: inline-size to follow the parent's width. Don't make
     * a horizontal card a container itself: its slots would query it, not the parent.
     * Vertical is the default; the attribute only names it.
     *
     * Every utility-backed declaration reads one chain, highest first:
     *   var(--_<utility>-resolved, var(--_card-<utility>, var(--ui-card-<utility>)))
     */
    
    @layer variables {
      :root {
        /* a bare card has no surface; the outline and floating variants paint --color-card */
        --ui-card-display: grid;
        --ui-card-place-content: start stretch;
        --ui-card-bg: transparent;
        --ui-card-text: var(--color-card-foreground);
        --ui-card-radius: var(--radius-lg);
        --ui-card-corner-shape: var(--radius-corner-shape);
        --ui-card-shadow: none;
    
        --ui-card-border-width: 1px;
        --ui-card-border-style: solid;
        --ui-card-border-color: transparent;
    
        /* dual-mode: a scale number or a length */
        --ui-card-gap: var(--space-sm);
        --ui-card-p: 0;
    
        /* horizontal: the header column's width */
        --ui-card-header-w: 40%;
      }
    }
    
    /* Variant privates: non-inheriting so a variant never cascades into a nested card. */
    @property --_card-bg {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-text {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-shadow {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-border-width {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-border-color {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-radius {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-p {
      syntax: "*";
      inherits: false;
    }
    
    /* The resolved padding, inherited so a media header can bleed over it. Every card
       sets its own, so it never carries into a nested card. */
    @property --_card-inset {
      syntax: "*";
      inherits: true;
    }
    
    @layer ui.components {
      :where(ui-card, [data-ui~="card"]) {
        display: var(--ui-card-display);
        place-content: var(--ui-card-place-content);
        grid-template-columns: minmax(0, 1fr);
        --_gap-len: var(--_gap-resolved, var(--ui-card-gap));
        --_gap-num: var(--_gap-resolved, var(--ui-card-gap));
        gap: calc(var(--_gap-len) + var(--_gap-num) * var(--spacing));
        --_p-len: var(--_p-resolved, var(--_card-p, var(--ui-card-p)));
        --_p-num: var(--_p-resolved, var(--_card-p, var(--ui-card-p)));
        --_card-inset: calc(var(--_p-len) + var(--_p-num) * var(--spacing));
        padding: var(--_card-inset);
        color: var(--_text-resolved, var(--_card-text, var(--ui-card-text)));
        background-color: var(--_bg-resolved, var(--_card-bg, var(--ui-card-bg)));
        border-width: var(
          --_border-width-resolved,
          var(--_card-border-width, var(--ui-card-border-width))
        );
        border-style: var(--_border-style-resolved, var(--ui-card-border-style));
        border-color: var(
          --_border-color-resolved,
          var(--_card-border-color, var(--ui-card-border-color))
        );
        --_radius-len: var(--_radius-resolved, var(--_card-radius, var(--ui-card-radius)));
        --_radius-num: var(--_radius-resolved, var(--_card-radius, var(--ui-card-radius)));
        border-radius: calc(
          var(--_radius-len) + var(--_radius-num) * var(--spacing) * var(--radius-multiplier)
        );
        corner-shape: var(--_corner-shape-resolved, var(--ui-card-corner-shape));
        box-shadow: var(--_shadow-resolved, var(--_card-shadow, var(--ui-card-shadow)));
        background-clip: var(--_bg-clip-resolved, border-box);
        overflow: clip;
        transition: var(--default-transition);
      }
    
      /* ===========================================================================
      CARD VARIANTS — data-card-variant writes the privates
      =========================================================================== */
    
      :where(ui-card:not([data-card-variant]), [data-ui~="card"]:not([data-card-variant])) {
        --_card-radius: 0;
      }
    
      :where(ui-card[data-card-variant="outline"], [data-ui~="card"][data-card-variant="outline"]) {
        --_card-p: var(--space-md);
        --_card-border-color: var(--color-border);
      }
    
      :where(ui-card[data-card-variant="muted"], [data-ui~="card"][data-card-variant="muted"]) {
        --_card-p: var(--space-md);
        --_card-bg: var(--color-muted);
        --_card-text: var(--color-foreground);
      }
    
      :where(ui-card[data-card-variant="floating"], [data-ui~="card"][data-card-variant="floating"]) {
        --_card-p: var(--space-md);
        --_card-bg: var(--color-card);
        --_card-border-color: var(--color-border);
        --_card-text: var(--color-card-foreground);
        --_card-shadow: var(--shadow-sm);
      }
    
      /* ===========================================================================
      CARD SLOTS — header, body, footer on direct children
      =========================================================================== */
    
      /* a media header bleeds over the card's padding to its clipped edge */
      :where(
        :is(ui-card, [data-ui~="card"])
          > [data-card-slot~="header"]:is(
            img,
            picture,
            video,
            figure:not(:has(> figcaption)),
            :has(> :is(img, picture, video):only-child)
          )
      ) {
        margin-inline: calc(var(--_card-inset) * -1);
        margin-block-start: calc(var(--_card-inset) * -1);
      }
    
      /* ===========================================================================
      CARD ORIENTATION — data-card-orientation; vertical is the default
      =========================================================================== */
    
      :where(
        ui-card[data-card-orientation="vertical"],
        [data-ui~="card"][data-card-orientation="vertical"]
      ) {
        grid-template-columns: minmax(0, 1fr);
      }
    
      @container (width >= 40rem) {
        :where(
          :is(
            ui-card[data-card-orientation="horizontal"],
            [data-ui~="card"][data-card-orientation="horizontal"]
          ):has(> [data-card-slot~="header"])
        ) {
          grid-template-columns: var(--ui-card-header-w) minmax(0, 1fr);
          grid-template-rows: 1fr auto;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"]):not(:has(> [data-card-slot~="footer"]))
        ) {
          grid-template-rows: 1fr;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"])
            > [data-card-slot~="header"]
        ) {
          grid-column: 1;
          grid-row: 1 / -1;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"])
            > [data-card-slot~="body"]
        ) {
          grid-column: 2;
          grid-row: 1;
          /* the row stretches to the header; keep the body's own rows at the top */
          align-content: start;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"])
            > [data-card-slot~="footer"]
        ) {
          grid-column: 2;
          grid-row: 2;
        }
    
        /* the media header bleeds on its three outer sides */
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]:is(
              img,
              picture,
              video,
              figure:not(:has(> figcaption)),
              :has(> :is(img, picture, video):only-child)
            )
        ) {
          margin-block: calc(var(--_card-inset) * -1);
          margin-inline-end: 0;
        }
    
        /* the media fills the column's height and crops to it. A bare img or video
           is sized to its grid area plus the bleed (WebKit won't stretch a replaced
           grid item), and the media inside a wrapper takes the wrapper's full box */
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]:is(img, video)
        ) {
          inline-size: calc(100% + var(--_card-inset));
          max-inline-size: none;
          block-size: calc(100% + 2 * var(--_card-inset));
          object-fit: cover;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]:is(
              picture,
              figure:not(:has(> figcaption)),
              :has(> :is(img, picture, video):only-child)
            )
            > :is(img, video, picture),
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]
            > picture
            > img
        ) {
          display: block;
          inline-size: 100%;
          block-size: 100%;
          object-fit: cover;
        }
      }
    }

    Article

    Elephants crossing a dusty riverbed
    Research

    Migration patterns

    Satellite collars reveal ancient routes herds still follow each dry season across the floodplain.

    John Doe
    John Doe Founder, ACME Inc.
    <article data-ui="card" data-card-variant="floating" style="--max-w: 96">
      <figure data-card-slot="header" style="--aspect: 3 / 2">
        <img
          width="600"
          height="400"
          loading="lazy"
          src="https://images.unsplash.com/photo-1564760055775-d63b17a55c44?auto=format&fit=crop&w=600&h=400&q=60"
          alt="Elephants crossing a dusty riverbed"
          style="
            --size: 100%;
            --opacity: 1;
            --opacity--hover: 0.75;
            --scale: 1;
            --scale--hover: 1.02;
            --transition: var(--default-transition);
            --object-fit: cover;
          "
        />
      </figure>
      <div
        data-card-slot="body"
        style="
          --display: grid;
          --gap: 2;
        "
      >
        <div
          style="
            --display: flex;
            --items: center;
            --gap: 2;
          "
        >
          <span data-ui="badge" data-badge-variant="muted">Research</span>
        </div>
        <hgroup
          style="
            --display: grid;
            --gap: 2;
          "
        >
          <h3 data-ui="text-lg">
            <a href="#">Migration patterns</a>
          </h3>
          <p
            data-ui="text-sm"
            style="
              --line-clamp: 2;
              --text: var(--color-muted-foreground);
            "
          >
            Satellite collars reveal ancient routes herds still follow each dry season across the
            floodplain.
          </p>
        </hgroup>
      </div>
      <footer
        data-card-slot="footer"
        style="
          --display: flex;
          --items: center;
          --pt: 4;
          --gap: 2;
          --border-t: 1;
        "
      >
        <figure
          role="img"
          style="
            --display: grid-pile;
            --size: 11;
            --border-color: var(--color-border);
            --border-width: 1px;
            --radius: full;
            --overflow: clip;
          "
        >
          <img
            width="64"
            height="64"
            loading="lazy"
            src="https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?auto=format&fit=facearea&facepad=2&w=64&h=64&q=90"
            alt="John Doe"
            aria-hidden="true"
            style="
              --order: 9999;
              --size: 100%;
              --bg: transparent;
              --object-fit: cover;
            "
          />
          <figcaption
            style="
              --display: flex;
              --items: center;
              --justify: center;
              --order: -9999;
              --size: 100%;
              --font-weight: strong;
              --text: var(--color-primary-foreground);
              --bg: var(--color-primary);
            "
          >
            <span style="--sr: only">John Doe</span>
            <span aria-hidden="true">JD</span>
          </figcaption>
        </figure>
        <div style="--display: flex-col">
          <span data-ui="text-sm" style="--font-weight: strong">John Doe</span>
          <span data-ui="text-xs" style="--text: var(--color-muted-foreground)"
            >Founder, ACME Inc.</span
          >
        </div>
      </footer>
    </article>
    /**
     * card.css: Card (ui-card | [data-ui~="card"])
     *
     * @layer      variables, components
     * @requires   _layers.css, _variables.css, _properties.css (--_*-resolved)
     * @uses       corner-shape — superellipse corners; unsupported browsers keep plain
     *             rounded corners
     * @uses       :has() — a header that holds only media bleeds to the card's edge;
     *             a horizontal card needs a header slot
     * @uses       @container (width >= 40rem) — a horizontal card lays out in two columns
     *             once its nearest container reaches sm, and stacks below that
     * @tokens     --ui-card-* (@layer variables; named after the utilities they back)
     * @presets    data-card-variant="outline" | "muted" | "floating"
     * @presets    data-card-orientation="vertical" | "horizontal"
     *
     * The card is a surface: a grid with a gap, the card colors, a radius, and
     * clipped overflow. The default card is bare (no padding, radius, or shadow), so
     * media can run edge to edge; each variant adds padding, the radius, and one
     * treatment. Every card keeps a 1px border, transparent unless a variant colors
     * it, so cards line up whatever their variant.
     *
     * Its parts are plain elements laid out with utilities, or the slots
     * data-card-slot="header" | "body" | "footer" on direct children. A header that
     * is an img/picture/video, a figure without a figcaption, or an element holding
     * only an img/picture/video bleeds: negative margins pull it over the card's
     * padding to the clipped, rounded edge. The bleed follows --p and --ui-card-p,
     * not the per-side padding utilities.
     *
     * data-card-orientation="horizontal" puts the header in a start column
     * (--ui-card-header-w, default 40%) spanning the rows, with the body above the footer in the
     * end column. It applies when the nearest container is at least sm (40rem) wide,
     * like the --*--sm utilities, and the card stacks below that; give the card's
     * parent --container-type: inline-size to follow the parent's width. Don't make
     * a horizontal card a container itself: its slots would query it, not the parent.
     * Vertical is the default; the attribute only names it.
     *
     * Every utility-backed declaration reads one chain, highest first:
     *   var(--_<utility>-resolved, var(--_card-<utility>, var(--ui-card-<utility>)))
     */
    
    @layer variables {
      :root {
        /* a bare card has no surface; the outline and floating variants paint --color-card */
        --ui-card-display: grid;
        --ui-card-place-content: start stretch;
        --ui-card-bg: transparent;
        --ui-card-text: var(--color-card-foreground);
        --ui-card-radius: var(--radius-lg);
        --ui-card-corner-shape: var(--radius-corner-shape);
        --ui-card-shadow: none;
    
        --ui-card-border-width: 1px;
        --ui-card-border-style: solid;
        --ui-card-border-color: transparent;
    
        /* dual-mode: a scale number or a length */
        --ui-card-gap: var(--space-sm);
        --ui-card-p: 0;
    
        /* horizontal: the header column's width */
        --ui-card-header-w: 40%;
      }
    }
    
    /* Variant privates: non-inheriting so a variant never cascades into a nested card. */
    @property --_card-bg {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-text {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-shadow {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-border-width {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-border-color {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-radius {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-p {
      syntax: "*";
      inherits: false;
    }
    
    /* The resolved padding, inherited so a media header can bleed over it. Every card
       sets its own, so it never carries into a nested card. */
    @property --_card-inset {
      syntax: "*";
      inherits: true;
    }
    
    @layer ui.components {
      :where(ui-card, [data-ui~="card"]) {
        display: var(--ui-card-display);
        place-content: var(--ui-card-place-content);
        grid-template-columns: minmax(0, 1fr);
        --_gap-len: var(--_gap-resolved, var(--ui-card-gap));
        --_gap-num: var(--_gap-resolved, var(--ui-card-gap));
        gap: calc(var(--_gap-len) + var(--_gap-num) * var(--spacing));
        --_p-len: var(--_p-resolved, var(--_card-p, var(--ui-card-p)));
        --_p-num: var(--_p-resolved, var(--_card-p, var(--ui-card-p)));
        --_card-inset: calc(var(--_p-len) + var(--_p-num) * var(--spacing));
        padding: var(--_card-inset);
        color: var(--_text-resolved, var(--_card-text, var(--ui-card-text)));
        background-color: var(--_bg-resolved, var(--_card-bg, var(--ui-card-bg)));
        border-width: var(
          --_border-width-resolved,
          var(--_card-border-width, var(--ui-card-border-width))
        );
        border-style: var(--_border-style-resolved, var(--ui-card-border-style));
        border-color: var(
          --_border-color-resolved,
          var(--_card-border-color, var(--ui-card-border-color))
        );
        --_radius-len: var(--_radius-resolved, var(--_card-radius, var(--ui-card-radius)));
        --_radius-num: var(--_radius-resolved, var(--_card-radius, var(--ui-card-radius)));
        border-radius: calc(
          var(--_radius-len) + var(--_radius-num) * var(--spacing) * var(--radius-multiplier)
        );
        corner-shape: var(--_corner-shape-resolved, var(--ui-card-corner-shape));
        box-shadow: var(--_shadow-resolved, var(--_card-shadow, var(--ui-card-shadow)));
        background-clip: var(--_bg-clip-resolved, border-box);
        overflow: clip;
        transition: var(--default-transition);
      }
    
      /* ===========================================================================
      CARD VARIANTS — data-card-variant writes the privates
      =========================================================================== */
    
      :where(ui-card:not([data-card-variant]), [data-ui~="card"]:not([data-card-variant])) {
        --_card-radius: 0;
      }
    
      :where(ui-card[data-card-variant="outline"], [data-ui~="card"][data-card-variant="outline"]) {
        --_card-p: var(--space-md);
        --_card-border-color: var(--color-border);
      }
    
      :where(ui-card[data-card-variant="muted"], [data-ui~="card"][data-card-variant="muted"]) {
        --_card-p: var(--space-md);
        --_card-bg: var(--color-muted);
        --_card-text: var(--color-foreground);
      }
    
      :where(ui-card[data-card-variant="floating"], [data-ui~="card"][data-card-variant="floating"]) {
        --_card-p: var(--space-md);
        --_card-bg: var(--color-card);
        --_card-border-color: var(--color-border);
        --_card-text: var(--color-card-foreground);
        --_card-shadow: var(--shadow-sm);
      }
    
      /* ===========================================================================
      CARD SLOTS — header, body, footer on direct children
      =========================================================================== */
    
      /* a media header bleeds over the card's padding to its clipped edge */
      :where(
        :is(ui-card, [data-ui~="card"])
          > [data-card-slot~="header"]:is(
            img,
            picture,
            video,
            figure:not(:has(> figcaption)),
            :has(> :is(img, picture, video):only-child)
          )
      ) {
        margin-inline: calc(var(--_card-inset) * -1);
        margin-block-start: calc(var(--_card-inset) * -1);
      }
    
      /* ===========================================================================
      CARD ORIENTATION — data-card-orientation; vertical is the default
      =========================================================================== */
    
      :where(
        ui-card[data-card-orientation="vertical"],
        [data-ui~="card"][data-card-orientation="vertical"]
      ) {
        grid-template-columns: minmax(0, 1fr);
      }
    
      @container (width >= 40rem) {
        :where(
          :is(
            ui-card[data-card-orientation="horizontal"],
            [data-ui~="card"][data-card-orientation="horizontal"]
          ):has(> [data-card-slot~="header"])
        ) {
          grid-template-columns: var(--ui-card-header-w) minmax(0, 1fr);
          grid-template-rows: 1fr auto;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"]):not(:has(> [data-card-slot~="footer"]))
        ) {
          grid-template-rows: 1fr;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"])
            > [data-card-slot~="header"]
        ) {
          grid-column: 1;
          grid-row: 1 / -1;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"])
            > [data-card-slot~="body"]
        ) {
          grid-column: 2;
          grid-row: 1;
          /* the row stretches to the header; keep the body's own rows at the top */
          align-content: start;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"])
            > [data-card-slot~="footer"]
        ) {
          grid-column: 2;
          grid-row: 2;
        }
    
        /* the media header bleeds on its three outer sides */
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]:is(
              img,
              picture,
              video,
              figure:not(:has(> figcaption)),
              :has(> :is(img, picture, video):only-child)
            )
        ) {
          margin-block: calc(var(--_card-inset) * -1);
          margin-inline-end: 0;
        }
    
        /* the media fills the column's height and crops to it. A bare img or video
           is sized to its grid area plus the bleed (WebKit won't stretch a replaced
           grid item), and the media inside a wrapper takes the wrapper's full box */
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]:is(img, video)
        ) {
          inline-size: calc(100% + var(--_card-inset));
          max-inline-size: none;
          block-size: calc(100% + 2 * var(--_card-inset));
          object-fit: cover;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]:is(
              picture,
              figure:not(:has(> figcaption)),
              :has(> :is(img, picture, video):only-child)
            )
            > :is(img, video, picture),
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]
            > picture
            > img
        ) {
          display: block;
          inline-size: 100%;
          block-size: 100%;
          object-fit: cover;
        }
      }
    }

    Subgrid

    Elephants crossing a dusty riverbed
    Research

    Migration patterns

    Satellite collars reveal ancient routes herds still follow each dry season across the floodplain.

    Zebras grazing at dawn on the savanna
    Field notes

    How quickly zebras jump

    Striped coats and sudden bursts of speed help herds evade predators when the grasslands go quiet at dusk, long after the light fades from the plain.

    <div
      style="
        --display: grid;
        --template-cols: repeat(auto-fit, minmax(min(100%, max(14rem, 40%)), 1fr));
        --gap: 6;
        --w: 100%;
      "
    >
      <ui-card
        data-card-variant="outline"
        style="
          --row-span: 3;
          --template-rows: subgrid;
        "
      >
        <figure data-card-slot="header" style="--aspect: 3 / 2">
          <img
            width="600"
            height="400"
            loading="lazy"
            src="https://images.unsplash.com/photo-1564760055775-d63b17a55c44?auto=format&fit=crop&w=600&h=400&q=60"
            alt="Elephants crossing a dusty riverbed"
            style="
              --size: 100%;
              --object-fit: cover;
            "
          />
        </figure>
        <div
          data-card-slot="body"
          style="
            --display: grid;
            --place-content: start;
            --gap: 2;
          "
        >
          <div
            style="
              --display: flex;
              --items: center;
              --gap: 2;
            "
          >
            <span data-ui="badge" data-badge-variant="muted">Research</span>
          </div>
          <h3 data-ui="text-lg">Migration patterns</h3>
          <p data-ui="text-sm" style="--text: var(--color-muted-foreground)">
            Satellite collars reveal ancient routes herds still follow each dry season across the
            floodplain.
          </p>
        </div>
        <footer
          data-card-slot="footer"
          style="
            --pt: 4;
            --border-t: 1;
          "
        >
          <a
            href="#"
            data-ui="button"
            data-button-variant="link"
            style="
              --justify: end;
              --text-align: end;
            "
            >Read article &rarr;</a
          >
        </footer>
      </ui-card>
      <ui-card
        data-card-variant="outline"
        style="
          --row-span: 3;
          --template-rows: subgrid;
        "
      >
        <figure data-card-slot="header" style="--aspect: 3 / 2">
          <img
            width="600"
            height="400"
            loading="lazy"
            src="https://images.unsplash.com/photo-1500382017468-9049fed747ef?auto=format&fit=crop&w=600&h=400&q=60"
            alt="Zebras grazing at dawn on the savanna"
            style="
              --size: 100%;
              --object-fit: cover;
            "
          />
        </figure>
        <div
          data-card-slot="body"
          style="
            --display: grid;
            --place-content: start;
            --gap: 2;
          "
        >
          <div
            style="
              --display: flex;
              --items: center;
              --gap: 2;
            "
          >
            <span data-ui="badge" data-badge-variant="muted">Field notes</span>
          </div>
          <h3 data-ui="text-lg">How quickly zebras jump</h3>
          <p data-ui="text-sm" style="--text: var(--color-muted-foreground)">
            Striped coats and sudden bursts of speed help herds evade predators when the grasslands go
            quiet at dusk, long after the light fades from the plain.
          </p>
        </div>
        <footer
          data-card-slot="footer"
          style="
            --pt: 4;
            --border-t: 1;
          "
        >
          <a
            href="#"
            data-ui="button"
            data-button-variant="link"
            style="
              --justify: end;
              --text-align: end;
            "
            >Read article &rarr;</a
          >
        </footer>
      </ui-card>
    </div>
    /**
     * card.css: Card (ui-card | [data-ui~="card"])
     *
     * @layer      variables, components
     * @requires   _layers.css, _variables.css, _properties.css (--_*-resolved)
     * @uses       corner-shape — superellipse corners; unsupported browsers keep plain
     *             rounded corners
     * @uses       :has() — a header that holds only media bleeds to the card's edge;
     *             a horizontal card needs a header slot
     * @uses       @container (width >= 40rem) — a horizontal card lays out in two columns
     *             once its nearest container reaches sm, and stacks below that
     * @tokens     --ui-card-* (@layer variables; named after the utilities they back)
     * @presets    data-card-variant="outline" | "muted" | "floating"
     * @presets    data-card-orientation="vertical" | "horizontal"
     *
     * The card is a surface: a grid with a gap, the card colors, a radius, and
     * clipped overflow. The default card is bare (no padding, radius, or shadow), so
     * media can run edge to edge; each variant adds padding, the radius, and one
     * treatment. Every card keeps a 1px border, transparent unless a variant colors
     * it, so cards line up whatever their variant.
     *
     * Its parts are plain elements laid out with utilities, or the slots
     * data-card-slot="header" | "body" | "footer" on direct children. A header that
     * is an img/picture/video, a figure without a figcaption, or an element holding
     * only an img/picture/video bleeds: negative margins pull it over the card's
     * padding to the clipped, rounded edge. The bleed follows --p and --ui-card-p,
     * not the per-side padding utilities.
     *
     * data-card-orientation="horizontal" puts the header in a start column
     * (--ui-card-header-w, default 40%) spanning the rows, with the body above the footer in the
     * end column. It applies when the nearest container is at least sm (40rem) wide,
     * like the --*--sm utilities, and the card stacks below that; give the card's
     * parent --container-type: inline-size to follow the parent's width. Don't make
     * a horizontal card a container itself: its slots would query it, not the parent.
     * Vertical is the default; the attribute only names it.
     *
     * Every utility-backed declaration reads one chain, highest first:
     *   var(--_<utility>-resolved, var(--_card-<utility>, var(--ui-card-<utility>)))
     */
    
    @layer variables {
      :root {
        /* a bare card has no surface; the outline and floating variants paint --color-card */
        --ui-card-display: grid;
        --ui-card-place-content: start stretch;
        --ui-card-bg: transparent;
        --ui-card-text: var(--color-card-foreground);
        --ui-card-radius: var(--radius-lg);
        --ui-card-corner-shape: var(--radius-corner-shape);
        --ui-card-shadow: none;
    
        --ui-card-border-width: 1px;
        --ui-card-border-style: solid;
        --ui-card-border-color: transparent;
    
        /* dual-mode: a scale number or a length */
        --ui-card-gap: var(--space-sm);
        --ui-card-p: 0;
    
        /* horizontal: the header column's width */
        --ui-card-header-w: 40%;
      }
    }
    
    /* Variant privates: non-inheriting so a variant never cascades into a nested card. */
    @property --_card-bg {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-text {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-shadow {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-border-width {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-border-color {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-radius {
      syntax: "*";
      inherits: false;
    }
    
    @property --_card-p {
      syntax: "*";
      inherits: false;
    }
    
    /* The resolved padding, inherited so a media header can bleed over it. Every card
       sets its own, so it never carries into a nested card. */
    @property --_card-inset {
      syntax: "*";
      inherits: true;
    }
    
    @layer ui.components {
      :where(ui-card, [data-ui~="card"]) {
        display: var(--ui-card-display);
        place-content: var(--ui-card-place-content);
        grid-template-columns: minmax(0, 1fr);
        --_gap-len: var(--_gap-resolved, var(--ui-card-gap));
        --_gap-num: var(--_gap-resolved, var(--ui-card-gap));
        gap: calc(var(--_gap-len) + var(--_gap-num) * var(--spacing));
        --_p-len: var(--_p-resolved, var(--_card-p, var(--ui-card-p)));
        --_p-num: var(--_p-resolved, var(--_card-p, var(--ui-card-p)));
        --_card-inset: calc(var(--_p-len) + var(--_p-num) * var(--spacing));
        padding: var(--_card-inset);
        color: var(--_text-resolved, var(--_card-text, var(--ui-card-text)));
        background-color: var(--_bg-resolved, var(--_card-bg, var(--ui-card-bg)));
        border-width: var(
          --_border-width-resolved,
          var(--_card-border-width, var(--ui-card-border-width))
        );
        border-style: var(--_border-style-resolved, var(--ui-card-border-style));
        border-color: var(
          --_border-color-resolved,
          var(--_card-border-color, var(--ui-card-border-color))
        );
        --_radius-len: var(--_radius-resolved, var(--_card-radius, var(--ui-card-radius)));
        --_radius-num: var(--_radius-resolved, var(--_card-radius, var(--ui-card-radius)));
        border-radius: calc(
          var(--_radius-len) + var(--_radius-num) * var(--spacing) * var(--radius-multiplier)
        );
        corner-shape: var(--_corner-shape-resolved, var(--ui-card-corner-shape));
        box-shadow: var(--_shadow-resolved, var(--_card-shadow, var(--ui-card-shadow)));
        background-clip: var(--_bg-clip-resolved, border-box);
        overflow: clip;
        transition: var(--default-transition);
      }
    
      /* ===========================================================================
      CARD VARIANTS — data-card-variant writes the privates
      =========================================================================== */
    
      :where(ui-card:not([data-card-variant]), [data-ui~="card"]:not([data-card-variant])) {
        --_card-radius: 0;
      }
    
      :where(ui-card[data-card-variant="outline"], [data-ui~="card"][data-card-variant="outline"]) {
        --_card-p: var(--space-md);
        --_card-border-color: var(--color-border);
      }
    
      :where(ui-card[data-card-variant="muted"], [data-ui~="card"][data-card-variant="muted"]) {
        --_card-p: var(--space-md);
        --_card-bg: var(--color-muted);
        --_card-text: var(--color-foreground);
      }
    
      :where(ui-card[data-card-variant="floating"], [data-ui~="card"][data-card-variant="floating"]) {
        --_card-p: var(--space-md);
        --_card-bg: var(--color-card);
        --_card-border-color: var(--color-border);
        --_card-text: var(--color-card-foreground);
        --_card-shadow: var(--shadow-sm);
      }
    
      /* ===========================================================================
      CARD SLOTS — header, body, footer on direct children
      =========================================================================== */
    
      /* a media header bleeds over the card's padding to its clipped edge */
      :where(
        :is(ui-card, [data-ui~="card"])
          > [data-card-slot~="header"]:is(
            img,
            picture,
            video,
            figure:not(:has(> figcaption)),
            :has(> :is(img, picture, video):only-child)
          )
      ) {
        margin-inline: calc(var(--_card-inset) * -1);
        margin-block-start: calc(var(--_card-inset) * -1);
      }
    
      /* ===========================================================================
      CARD ORIENTATION — data-card-orientation; vertical is the default
      =========================================================================== */
    
      :where(
        ui-card[data-card-orientation="vertical"],
        [data-ui~="card"][data-card-orientation="vertical"]
      ) {
        grid-template-columns: minmax(0, 1fr);
      }
    
      @container (width >= 40rem) {
        :where(
          :is(
            ui-card[data-card-orientation="horizontal"],
            [data-ui~="card"][data-card-orientation="horizontal"]
          ):has(> [data-card-slot~="header"])
        ) {
          grid-template-columns: var(--ui-card-header-w) minmax(0, 1fr);
          grid-template-rows: 1fr auto;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"]):not(:has(> [data-card-slot~="footer"]))
        ) {
          grid-template-rows: 1fr;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"])
            > [data-card-slot~="header"]
        ) {
          grid-column: 1;
          grid-row: 1 / -1;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"])
            > [data-card-slot~="body"]
        ) {
          grid-column: 2;
          grid-row: 1;
          /* the row stretches to the header; keep the body's own rows at the top */
          align-content: start;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            ):has(> [data-card-slot~="header"])
            > [data-card-slot~="footer"]
        ) {
          grid-column: 2;
          grid-row: 2;
        }
    
        /* the media header bleeds on its three outer sides */
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]:is(
              img,
              picture,
              video,
              figure:not(:has(> figcaption)),
              :has(> :is(img, picture, video):only-child)
            )
        ) {
          margin-block: calc(var(--_card-inset) * -1);
          margin-inline-end: 0;
        }
    
        /* the media fills the column's height and crops to it. A bare img or video
           is sized to its grid area plus the bleed (WebKit won't stretch a replaced
           grid item), and the media inside a wrapper takes the wrapper's full box */
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]:is(img, video)
        ) {
          inline-size: calc(100% + var(--_card-inset));
          max-inline-size: none;
          block-size: calc(100% + 2 * var(--_card-inset));
          object-fit: cover;
        }
    
        :where(
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]:is(
              picture,
              figure:not(:has(> figcaption)),
              :has(> :is(img, picture, video):only-child)
            )
            > :is(img, video, picture),
          :is(
              ui-card[data-card-orientation="horizontal"],
              [data-ui~="card"][data-card-orientation="horizontal"]
            )
            > [data-card-slot~="header"]
            > picture
            > img
        ) {
          display: block;
          inline-size: 100%;
          block-size: 100%;
          object-fit: cover;
        }
      }
    }

    Attributes

    card attributes
    AttributeKindValuesNotes
    data-ui="card"Identityfree valueIdentity token in data-ui.
    <ui-card>Tag formfree valueTag form; styled and, when scripted, registered under this name.
    data-card-orientationPresethorizontal verticalPreset: a named bundle of values.
    data-card-variantPresetfloating muted outlinePreset: a named bundle of values.
    data-card-slotSlotbody footer headerSlot: a part inside the primitive.

    Hooks

    Set a hook on :root, on a subtree, or inline on one element. A state hook (--…--hover) themes that state only; the primitive keeps its other states.

    card hooks
    HookDefaultState
    --ui-card-bgtransparent—
    --ui-card-border-colortransparent—
    --ui-card-border-stylesolid—
    --ui-card-border-width1px—
    --ui-card-corner-shapevar(--radius-corner-shape)—
    --ui-card-displaygrid—
    --ui-card-gapvar(--space-sm)—
    --ui-card-header-w40%—
    --ui-card-p0—
    --ui-card-place-contentstart stretch—
    --ui-card-radiusvar(--radius-lg)—
    --ui-card-shadownone—
    --ui-card-textvar(--color-card-foreground)—

    API