> ## Documentation Index
> Fetch the complete documentation index at: https://prefab.prefect.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Card

> Contained surface for grouping related content and actions.

export const ComponentPreview = ({json, height, resizable, bare, hideJson, playground, children}) => {
  const hostRef = React.useRef(null);
  const handleRef = React.useRef(null);
  const cardRef = React.useRef(null);
  const containerRef = React.useRef(null);
  const [previewWidth, setPreviewWidth] = React.useState(null);
  const [isDragging, setIsDragging] = React.useState(false);
  const [playgroundHref, setPlaygroundHref] = React.useState(null);
  React.useEffect(function () {
    if (!playground) return;
    var isLocal = location.hostname === "localhost" || location.hostname === "127.0.0.1";
    var path = isLocal ? "/playground" : "/docs/playground";
    var url = new URL(path, window.location.href);
    url.hash = "code=" + playground;
    setPlaygroundHref(url.href);
  }, [playground]);
  var jsonStr = typeof json === "string" ? json : JSON.stringify(json, null, 2);
  React.useEffect(function () {
    if (cardRef.current) {
      var card = cardRef.current.closest(".group");
      if (card) card.classList.remove("group");
    }
    var host = hostRef.current;
    if (!host || !json) return;
    function mount() {
      if (!window.__prefab || !host) return;
      var dark = document.documentElement.classList.contains("dark");
      handleRef.current = window.__prefab.mountPreview(host, jsonStr, {
        dark: dark
      });
      if (bare && host.shadowRoot) {
        var m = host.shadowRoot.querySelector("[data-prefab-mount]");
        if (m) m.style.background = "transparent";
      }
    }
    if (window.__prefab) {
      mount();
    } else {
      if (!window.__prefabLoading) {
        if (!window.__prefabReady) {
          var s = document.createElement("script");
          s.src = "/renderer.js";
          document.head.appendChild(s);
        }
        window.__prefabLoading = new Promise(function (resolve) {
          function check() {
            if (window.__prefabReady) {
              window.__prefabReady.then(resolve);
            } else {
              setTimeout(check, 10);
            }
          }
          check();
        });
      }
      window.__prefabLoading.then(mount);
    }
    var observer = new MutationObserver(function () {
      var dark = document.documentElement.classList.contains("dark");
      if (handleRef.current) handleRef.current.setDark(dark);
    });
    observer.observe(document.documentElement, {
      attributes: true,
      attributeFilter: ["class"]
    });
    return function () {
      observer.disconnect();
      if (handleRef.current) {
        handleRef.current.unmount();
        handleRef.current = null;
      }
    };
  }, [json]);
  function startResize(e) {
    e.preventDefault();
    var startX = e.clientX;
    var startW = hostRef.current ? hostRef.current.offsetWidth : 0;
    var maxW = containerRef.current ? containerRef.current.offsetWidth - 10 : startW;
    setIsDragging(true);
    function onMove(ev) {
      var w = Math.max(260, Math.min(startW + (ev.clientX - startX), maxW));
      setPreviewWidth(w);
    }
    function onUp() {
      document.removeEventListener("mousemove", onMove);
      document.removeEventListener("mouseup", onUp);
      setIsDragging(false);
    }
    document.addEventListener("mousemove", onMove);
    document.addEventListener("mouseup", onUp);
  }
  if (bare) {
    return <div ref={hostRef} />;
  }
  if (resizable) {
    return <Card>
        <div ref={cardRef} />
        <div ref={containerRef} style={{
      display: "flex",
      position: "relative",
      overflow: "hidden"
    }}>
          <div ref={hostRef} style={{
      flex: previewWidth ? "none" : 1,
      width: previewWidth ? previewWidth + "px" : undefined,
      minWidth: 0
    }} />
          <div onMouseDown={startResize} style={{
      width: "14px",
      flexShrink: 0,
      cursor: "col-resize",
      background: isDragging ? "var(--border, #e5e7eb)" : "color-mix(in srgb, var(--border, #e5e7eb) 40%, transparent)",
      display: "flex",
      alignItems: "center",
      justifyContent: "center",
      transition: "background 0.15s",
      userSelect: "none"
    }}>
            <svg width="6" height="24" style={{
      opacity: 0.5
    }}>
              <circle cx="2" cy="4" r="1.2" fill="currentColor" />
              <circle cx="2" cy="9" r="1.2" fill="currentColor" />
              <circle cx="2" cy="14" r="1.2" fill="currentColor" />
              <circle cx="2" cy="19" r="1.2" fill="currentColor" />
              <circle cx="5" cy="4" r="1.2" fill="currentColor" />
              <circle cx="5" cy="9" r="1.2" fill="currentColor" />
              <circle cx="5" cy="14" r="1.2" fill="currentColor" />
              <circle cx="5" cy="19" r="1.2" fill="currentColor" />
            </svg>
          </div>
          <div style={{
      flex: previewWidth ? 1 : "0 0 24px",
      minWidth: "24px",
      background: "repeating-linear-gradient(-45deg, transparent, transparent 3px, var(--border, #e5e7eb) 3px, var(--border, #e5e7eb) 4px)",
      opacity: 0.4
    }} />
          {previewWidth && <div style={{
      position: "absolute",
      bottom: "8px",
      right: "8px",
      background: "var(--background, white)",
      border: "1px solid var(--border, #e5e7eb)",
      borderRadius: "4px",
      padding: "1px 6px",
      fontSize: "11px",
      fontFamily: "monospace",
      color: "var(--muted-foreground, #6b7280)",
      pointerEvents: "none"
    }}>
              {previewWidth}px
            </div>}
        </div>
        {playgroundHref && <div style={{
      display: "flex",
      justifyContent: "flex-end",
      padding: "4px 0 8px"
    }}>
            <a href={playgroundHref} target="_blank" rel="noopener noreferrer" style={{
      fontSize: "11px",
      opacity: 0.4,
      textDecoration: "none",
      textDecorationLine: "none",
      borderBottom: "none",
      boxShadow: "none",
      display: "inline-flex",
      alignItems: "center",
      gap: "3px",
      transition: "opacity 0.15s",
      fontWeight: 400
    }} onMouseOver={function (e) {
      e.currentTarget.style.opacity = "0.6";
    }} onMouseOut={function (e) {
      e.currentTarget.style.opacity = "0.4";
    }}>
              Edit in Playground
              <svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M15 3h6v6" /><path d="M10 14 21 3" /><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" /></svg>
            </a>
          </div>}
        <div style={{
      marginBottom: "-2rem"
    }}>{children}</div>
      </Card>;
  }
  return <Card>
      <div ref={cardRef} />
      <div ref={hostRef} />
      {playgroundHref && <div style={{
    display: "flex",
    justifyContent: "flex-end",
    padding: "4px 0 8px"
  }}>
          <a href={playgroundHref} target="_blank" rel="noopener noreferrer" style={{
    fontSize: "11px",
    opacity: 0.4,
    textDecoration: "none",
    textDecorationLine: "none",
    borderBottom: "none",
    boxShadow: "none",
    display: "inline-flex",
    alignItems: "center",
    gap: "3px",
    transition: "opacity 0.15s",
    fontWeight: 400
  }} onMouseOver={function (e) {
    e.currentTarget.style.opacity = "0.6";
  }} onMouseOut={function (e) {
    e.currentTarget.style.opacity = "0.4";
  }}>
            Edit in Playground
            <svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M15 3h6v6" /><path d="M10 14 21 3" /><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" /></svg>
          </a>
        </div>}
      <div style={{
    marginBottom: "-2rem"
  }}>{children}</div>
    </Card>;
};

Cards group related content into a bordered, shadowed container. They're composed from sub-components — `CardHeader`, `CardContent`, and `CardFooter` — that handle spacing and layout so you can focus on content.

## Basic Usage

<ComponentPreview json={{"view":{"type":"Card","children":[{"type":"CardHeader","children":[{"type":"CardTitle","content":"Create project"},{"type":"CardDescription","content":"Deploy your new project in one-click."}]},{"type":"CardContent","children":[{"content":"Your project will be created with default settings.","type":"P"}]},{"type":"CardFooter","children":[{"type":"Button","label":"Cancel","variant":"outline","size":"default","disabled":false},{"type":"Button","label":"Deploy","variant":"default","size":"default","disabled":false}]}]}}} playground="ZnJvbSBwcmVmYWJfdWkuY29tcG9uZW50cyBpbXBvcnQgKAogICAgQ2FyZCwKICAgIENhcmRIZWFkZXIsCiAgICBDYXJkVGl0bGUsCiAgICBDYXJkRGVzY3JpcHRpb24sCiAgICBDYXJkQ29udGVudCwKICAgIENhcmRGb290ZXIsCiAgICBCdXR0b24sCiAgICBQLAopCgp3aXRoIENhcmQoKToKICAgIHdpdGggQ2FyZEhlYWRlcigpOgogICAgICAgIENhcmRUaXRsZSgiQ3JlYXRlIHByb2plY3QiKQogICAgICAgIENhcmREZXNjcmlwdGlvbigiRGVwbG95IHlvdXIgbmV3IHByb2plY3QgaW4gb25lLWNsaWNrLiIpCiAgICB3aXRoIENhcmRDb250ZW50KCk6CiAgICAgICAgUCgiWW91ciBwcm9qZWN0IHdpbGwgYmUgY3JlYXRlZCB3aXRoIGRlZmF1bHQgc2V0dGluZ3MuIikKICAgIHdpdGggQ2FyZEZvb3RlcigpOgogICAgICAgIEJ1dHRvbigiQ2FuY2VsIiwgdmFyaWFudD0ib3V0bGluZSIpCiAgICAgICAgQnV0dG9uKCJEZXBsb3kiKQo">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    from prefab_ui.components import (
        Card,
        CardHeader,
        CardTitle,
        CardDescription,
        CardContent,
        CardFooter,
        Button,
        P,
    )

    with Card():
        with CardHeader():
            CardTitle("Create project")
            CardDescription("Deploy your new project in one-click.")
        with CardContent():
            P("Your project will be created with default settings.")
        with CardFooter():
            Button("Cancel", variant="outline")
            Button("Deploy")
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "type": "Card",
        "children": [
          {
            "type": "CardHeader",
            "children": [
              {"type": "CardTitle", "content": "Create project"},
              {"type": "CardDescription", "content": "Deploy your new project in one-click."}
            ]
          },
          {
            "type": "CardContent",
            "children": [
              {"content": "Your project will be created with default settings.", "type": "P"}
            ]
          },
          {
            "type": "CardFooter",
            "children": [
              {
                "type": "Button",
                "label": "Cancel",
                "variant": "outline",
                "size": "default",
                "disabled": false
              },
              {
                "type": "Button",
                "label": "Deploy",
                "variant": "default",
                "size": "default",
                "disabled": false
              }
            ]
          }
        ]
      }
    }
    ```
  </CodeGroup>
</ComponentPreview>

## Structure

Cards follow a header → content → footer pattern. Each section is optional — use only what you need.

`CardHeader` is a grid that pairs a `CardTitle` with an optional `CardDescription`. `CardContent` provides horizontal padding for your main content. `CardFooter` renders as a flex row, naturally aligning action buttons side by side.

<ComponentPreview json={{"view":{"type":"Card","children":[{"type":"CardHeader","children":[{"type":"CardTitle","content":"Account Settings"},{"type":"CardDescription","content":"Manage your account preferences and security."}]},{"type":"CardContent","children":[{"content":"Update your display name, email, and notification preferences from this panel.","type":"P"},{"content":"Changes take effect immediately.","type":"Muted"}]},{"type":"CardFooter","children":[{"type":"Button","label":"Save changes","variant":"default","size":"default","disabled":false}]}]}}} playground="ZnJvbSBwcmVmYWJfdWkuY29tcG9uZW50cyBpbXBvcnQgKAogICAgQ2FyZCwKICAgIENhcmRIZWFkZXIsCiAgICBDYXJkVGl0bGUsCiAgICBDYXJkRGVzY3JpcHRpb24sCiAgICBDYXJkQ29udGVudCwKICAgIENhcmRGb290ZXIsCiAgICBCdXR0b24sCiAgICBQLAogICAgTXV0ZWQsCikKCndpdGggQ2FyZCgpOgogICAgd2l0aCBDYXJkSGVhZGVyKCk6CiAgICAgICAgQ2FyZFRpdGxlKCJBY2NvdW50IFNldHRpbmdzIikKICAgICAgICBDYXJkRGVzY3JpcHRpb24oIk1hbmFnZSB5b3VyIGFjY291bnQgcHJlZmVyZW5jZXMgYW5kIHNlY3VyaXR5LiIpCiAgICB3aXRoIENhcmRDb250ZW50KCk6CiAgICAgICAgUCgiVXBkYXRlIHlvdXIgZGlzcGxheSBuYW1lLCBlbWFpbCwgYW5kIG5vdGlmaWNhdGlvbiBwcmVmZXJlbmNlcyBmcm9tIHRoaXMgcGFuZWwuIikKICAgICAgICBNdXRlZCgiQ2hhbmdlcyB0YWtlIGVmZmVjdCBpbW1lZGlhdGVseS4iKQogICAgd2l0aCBDYXJkRm9vdGVyKCk6CiAgICAgICAgQnV0dG9uKCJTYXZlIGNoYW5nZXMiKQo">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    from prefab_ui.components import (
        Card,
        CardHeader,
        CardTitle,
        CardDescription,
        CardContent,
        CardFooter,
        Button,
        P,
        Muted,
    )

    with Card():
        with CardHeader():
            CardTitle("Account Settings")
            CardDescription("Manage your account preferences and security.")
        with CardContent():
            P("Update your display name, email, and notification preferences from this panel.")
            Muted("Changes take effect immediately.")
        with CardFooter():
            Button("Save changes")
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "type": "Card",
        "children": [
          {
            "type": "CardHeader",
            "children": [
              {"type": "CardTitle", "content": "Account Settings"},
              {
                "type": "CardDescription",
                "content": "Manage your account preferences and security."
              }
            ]
          },
          {
            "type": "CardContent",
            "children": [
              {
                "content": "Update your display name, email, and notification preferences from this panel.",
                "type": "P"
              },
              {"content": "Changes take effect immediately.", "type": "Muted"}
            ]
          },
          {
            "type": "CardFooter",
            "children": [
              {
                "type": "Button",
                "label": "Save changes",
                "variant": "default",
                "size": "default",
                "disabled": false
              }
            ]
          }
        ]
      }
    }
    ```
  </CodeGroup>
</ComponentPreview>

## Simple Cards

For lightweight use cases, you can skip the sub-components entirely and use `css_class` to add padding:

<ComponentPreview json={{"view":{"cssClass":"p-6","type":"Card","children":[{"content":"Quick Stats","type":"H3"},{"content":"42 active connections, 3 pending requests.","type":"P"}]}}} playground="ZnJvbSBwcmVmYWJfdWkuY29tcG9uZW50cyBpbXBvcnQgKAogICAgQ2FyZCwKICAgIEgzLAogICAgUCwKKQoKd2l0aCBDYXJkKGNzc19jbGFzcz0icC02Iik6CiAgICBIMygiUXVpY2sgU3RhdHMiKQogICAgUCgiNDIgYWN0aXZlIGNvbm5lY3Rpb25zLCAzIHBlbmRpbmcgcmVxdWVzdHMuIikK">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    from prefab_ui.components import (
        Card,
        H3,
        P,
    )

    with Card(css_class="p-6"):
        H3("Quick Stats")
        P("42 active connections, 3 pending requests.")
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "cssClass": "p-6",
        "type": "Card",
        "children": [
          {"content": "Quick Stats", "type": "H3"},
          {"content": "42 active connections, 3 pending requests.", "type": "P"}
        ]
      }
    }
    ```
  </CodeGroup>
</ComponentPreview>

## Card Grid

Cards work naturally with `Grid` for dashboard-style layouts:

<ComponentPreview json={{"view":{"cssClass":"gap-4 grid-cols-3","type":"Grid","children":[{"type":"Card","children":[{"type":"CardHeader","children":[{"type":"CardDescription","content":"Revenue"},{"type":"CardTitle","content":"$12,450"}]}]},{"type":"Card","children":[{"type":"CardHeader","children":[{"type":"CardDescription","content":"Users"},{"type":"CardTitle","content":"1,234"}]}]},{"type":"Card","children":[{"type":"CardHeader","children":[{"type":"CardDescription","content":"Uptime"},{"type":"CardTitle","content":"99.9%"}]}]}]}}} playground="ZnJvbSBwcmVmYWJfdWkuY29tcG9uZW50cyBpbXBvcnQgKAogICAgQ2FyZCwKICAgIENhcmRIZWFkZXIsCiAgICBDYXJkVGl0bGUsCiAgICBDYXJkRGVzY3JpcHRpb24sCiAgICBHcmlkLAopCgp3aXRoIEdyaWQoY29sdW1ucz0zLCBnYXA9NCk6CiAgICBmb3IgdGl0bGUsIGRlc2MgaW4gWwogICAgICAgICgiUmV2ZW51ZSIsICIkMTIsNDUwIiksCiAgICAgICAgKCJVc2VycyIsICIxLDIzNCIpLAogICAgICAgICgiVXB0aW1lIiwgIjk5LjklIiksCiAgICBdOgogICAgICAgIHdpdGggQ2FyZCgpOgogICAgICAgICAgICB3aXRoIENhcmRIZWFkZXIoKToKICAgICAgICAgICAgICAgIENhcmREZXNjcmlwdGlvbih0aXRsZSkKICAgICAgICAgICAgICAgIENhcmRUaXRsZShkZXNjKQo">
  <CodeGroup>
    ```python Python icon="python" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    from prefab_ui.components import (
        Card,
        CardHeader,
        CardTitle,
        CardDescription,
        Grid,
    )

    with Grid(columns=3, gap=4):
        for title, desc in [
            ("Revenue", "$12,450"),
            ("Users", "1,234"),
            ("Uptime", "99.9%"),
        ]:
            with Card():
                with CardHeader():
                    CardDescription(title)
                    CardTitle(desc)
    ```

    ```json Protocol icon="brackets-curly" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    {
      "view": {
        "cssClass": "gap-4 grid-cols-3",
        "type": "Grid",
        "children": [
          {
            "type": "Card",
            "children": [
              {
                "type": "CardHeader",
                "children": [
                  {"type": "CardDescription", "content": "Revenue"},
                  {"type": "CardTitle", "content": "$12,450"}
                ]
              }
            ]
          },
          {
            "type": "Card",
            "children": [
              {
                "type": "CardHeader",
                "children": [
                  {"type": "CardDescription", "content": "Users"},
                  {"type": "CardTitle", "content": "1,234"}
                ]
              }
            ]
          },
          {
            "type": "Card",
            "children": [
              {
                "type": "CardHeader",
                "children": [
                  {"type": "CardDescription", "content": "Uptime"},
                  {"type": "CardTitle", "content": "99.9%"}
                ]
              }
            ]
          }
        ]
      }
    }
    ```
  </CodeGroup>
</ComponentPreview>

## API Reference

<Card icon="code" title="Card Parameters">
  <ParamField body="css_class" type="str | None" default="None">
    Additional Tailwind CSS classes. The card renders as a `div` with border, shadow, and rounded corners.
  </ParamField>
</Card>

<Card icon="code" title="CardHeader Parameters">
  <ParamField body="css_class" type="str | None" default="None">
    Additional Tailwind CSS classes. Renders as a grid with automatic spacing for title and description.
  </ParamField>
</Card>

<Card icon="code" title="CardTitle Parameters">
  <ParamField body="content" type="str | None" default="None">
    Title text. Can be passed as a positional argument. Alternatively, use child components instead of a string.
  </ParamField>

  <ParamField body="css_class" type="str | None" default="None">
    Additional Tailwind CSS classes.
  </ParamField>
</Card>

<Card icon="code" title="CardDescription Parameters">
  <ParamField body="content" type="str | None" default="None">
    Description text. Can be passed as a positional argument. Alternatively, use child components.
  </ParamField>

  <ParamField body="css_class" type="str | None" default="None">
    Additional Tailwind CSS classes.
  </ParamField>
</Card>

<Card icon="code" title="CardContent Parameters">
  <ParamField body="css_class" type="str | None" default="None">
    Additional Tailwind CSS classes. Provides horizontal padding (`px-4`) for the main body area.
  </ParamField>
</Card>

<Card icon="code" title="CardFooter Parameters">
  <ParamField body="css_class" type="str | None" default="None">
    Additional Tailwind CSS classes. Renders as a flex row for action buttons.
  </ParamField>
</Card>

## Protocol Reference

```json Card theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
{
  "type": "Card",
  "id?": "string",
  "onMount?": "any",
  "children?": "[Component]",
  "let?": "object",
  "cssClass?": "string"
}
```

```json CardHeader theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
{
  "type": "CardHeader",
  "id?": "string",
  "onMount?": "any",
  "children?": "[Component]",
  "let?": "object",
  "cssClass?": "string"
}
```

```json CardTitle theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
{
  "type": "CardTitle",
  "id?": "string",
  "onMount?": "any",
  "children?": "[Component]",
  "let?": "object",
  "content?": "string",
  "cssClass?": "string"
}
```

```json CardDescription theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
{
  "type": "CardDescription",
  "id?": "string",
  "onMount?": "any",
  "children?": "[Component]",
  "let?": "object",
  "content?": "string",
  "cssClass?": "string"
}
```

```json CardContent theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
{
  "type": "CardContent",
  "id?": "string",
  "onMount?": "any",
  "children?": "[Component]",
  "let?": "object",
  "cssClass?": "string"
}
```

```json CardFooter theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
{
  "type": "CardFooter",
  "id?": "string",
  "onMount?": "any",
  "children?": "[Component]",
  "let?": "object",
  "cssClass?": "string"
}
```

For the complete protocol schema, see [Card](/protocol/card), [CardHeader](/protocol/card-header), [CardTitle](/protocol/card-title), [CardDescription](/protocol/card-description), [CardContent](/protocol/card-content), [CardFooter](/protocol/card-footer).
