# Card

A container for related content, such as a form, a list, or a summary. Give it a header, a body, and a footer, and the card handles the spacing, dividers, and corners between them.

```tsx
import { Button, Card, Input, Text, Textarea } from '@fluxui-dev/react';
import { EllipsisHorizontalIcon } from '@fluxui-dev/react/icons';

<Card body="inset" variant="soft" size="lg">
    <Card.Header>
        <Card.Heading>Profile</Card.Heading>
        <Card.Subheading>This is how others will see you</Card.Subheading>

        <Card.Actions>
            <Button size="sm" variant="ghost" icon={EllipsisHorizontalIcon} aria-label="More options" />
        </Card.Actions>
    </Card.Header>

    <Card.Body className="space-y-6">
        <Input label="Name" defaultValue="Olivia Martin" />
        <Textarea label="Bio" rows={2} placeholder="A few words about yourself" />
    </Card.Body>

    <Card.Footer>
        <Text>Last saved 2 minutes ago</Text>

        <Card.Actions>
            <Button variant="ghost">Cancel</Button>
            <Button variant="primary">Save</Button>
        </Card.Actions>
    </Card.Footer>
</Card>
```

## Simple card

Parts are optional. Put anything straight inside a card and it's padded evenly, like a div with a border.

```tsx
import { Button, Card, Heading, Text } from '@fluxui-dev/react';

<Card>
    <Heading size="lg">Are you sure?</Heading>

    <Text className="mt-2 mb-4">
        Your post will be deleted permanently.<br />
        This action cannot be undone.
    </Text>

    <Button variant="danger">Delete</Button>
</Card>
```

## Variants

Use the `variant` prop to change the card's surface. The default surface has a shadow in light mode and elevation in dark mode. The outline surface has neither. Tinted variants adapt to the color behind them.

```tsx
<Card>
    <Heading>default</Heading>
    <Text className="mt-1">Raised, for primary content.</Text>
</Card>

<Card variant="muted">...</Card>
<Card variant="soft">...</Card>
<Card variant="outline">...</Card>
<Card variant="filled">...</Card>
```

## Sizes

Use the `size` prop to scale the card's padding, corners, and the space between its parts. Cards are `md` by default.

```tsx
<Card size="xs" body="separated">
    <Card.Header>
        <Card.Heading>xs</Card.Heading>

        <Card.Actions>
            <Button size="sm">Edit</Button>
        </Card.Actions>
    </Card.Header>

    <Card.Body>
        <Text>Compact, for dense lists and sidebars.</Text>
    </Card.Body>
</Card>

<Card size="sm" body="separated">...</Card>
<Card size="md" body="separated">...</Card>
<Card size="lg" body="separated">...</Card>
```

## Body treatments

Wrap a card's main content in `Card.Body`, optionally with a `Card.Header` above it and a `Card.Footer` below. The `body` prop decides how they're set apart. Buttons in `Card.Actions` line up with the edge for you.

### Seamless

The default. Everything shares one surface, separated only by space.

```tsx
import { Switch } from '@fluxui-dev/react';

<Card body="seamless">
    <Card.Header>
        <Card.Heading>Notifications</Card.Heading>
        <Card.Subheading>Choose what you hear about</Card.Subheading>
    </Card.Header>

    <Card.Body className="space-y-4">
        <Switch label="Product updates" defaultChecked />
        <Switch label="Weekly digest" />
        <Switch label="Security alerts" defaultChecked />
    </Card.Body>
</Card>
```

### Inset

Set the body in its own panel, a little in from the card's edges. On a tinted card the panel is raised; on a white one it's a recessed well.

```tsx
<Card body="inset" variant="soft">
    ...
</Card>
```

### Flush

Like inset, but the panel runs all the way to the card's sides.

```tsx
<Card body="flush" variant="soft">
    ...
</Card>
```

### Divided

Separate the header and footer from the body with lines. Add `divider="inset"` to stop the lines at the content's edges instead of running them across the card.

```tsx
<Card body="divided">
    ...
</Card>

<Card body="divided" divider="inset">
    ...
</Card>
```

### Separated

Set the header and footer apart as tinted bands around the body.

```tsx
<Card body="separated">
    ...
</Card>
```

## Bleed

Run content out to the card's edges, so it reaches the nearest visible edge instead of sitting inside the padding.

### Images

Wrap media in `Card.Bleed`. It always reaches the sides, reaches the top or bottom when it's the first or last thing in the body, and rounds only the corners it touches.

```tsx
<Card body="inset">
    <Card.Body>
        <Card.Bleed>
            <img src="/img/forest.png" alt="A misty forest path" className="block aspect-video w-full object-cover" />
        </Card.Bleed>
    </Card.Body>

    <Card.Footer>
        <Card.Heading>Morning hike</Card.Heading>
        <Card.Subheading>Sept 12</Card.Subheading>

        <Card.Actions>
            <Button size="sm" variant="ghost" icon={EllipsisHorizontalIcon} aria-label="More options" />
        </Card.Actions>
    </Card.Footer>
</Card>
```

## Outside a card

Headers and footers work on their own too, like a section heading above a card. Set their `size` to match the card beside them.

```tsx
import { Badge, Button, Card, Heading, Separator, Text } from '@fluxui-dev/react';

<Card.Header>
    <Card.Heading size="lg">Security</Card.Heading>

    <Card.Actions>
        <Button size="sm" variant="outline">Activity log</Button>
    </Card.Actions>
</Card.Header>

<Card>
    <div className="flex items-center justify-between gap-4">
        <div>
            <Heading>Password</Heading>
            <Text className="mt-1">Last changed 3 months ago</Text>
        </div>

        <Button size="sm">Change</Button>
    </div>

    <Separator variant="subtle" className="my-4" />

    <div className="flex items-center justify-between gap-4">
        <div>
            <Heading>Two-factor authentication</Heading>
            <Text className="mt-1">A code from your authenticator app</Text>
        </div>

        <Badge size="sm" color="green">On</Badge>
    </div>
</Card>
```

## Inside a body

Inside a body, a header or footer becomes a sub-section of it, bare whatever the card's body treatment. Use them to break a body into titled groups.

```tsx
import { CreditCardIcon } from '@fluxui-dev/react/icons';

<Card body="inset" variant="soft">
    <Card.Header>
        <Card.Heading>Billing</Card.Heading>
        <Card.Subheading>Manage your plan and payments</Card.Subheading>
    </Card.Header>

    <Card.Body>
        <Card.Header>
            <Card.Heading>Pro plan</Card.Heading>
            <Card.Subheading>$24 per month, renews Oct 12</Card.Subheading>

            <Card.Actions>
                <Button size="sm">Change plan</Button>
            </Card.Actions>
        </Card.Header>

        <div className="flex justify-between">
            <Text>Seats used</Text>
            <Text variant="strong">8 of 10</Text>
        </div>

        <Separator variant="subtle" className="my-6" />

        <Card.Header>
            <Card.Heading>Payment method</Card.Heading>

            <Card.Actions>
                <Button size="sm" variant="ghost">Update</Button>
            </Card.Actions>
        </Card.Header>

        <div className="flex items-center gap-3">
            <CreditCardIcon variant="outline" className="text-zinc-400" />
            <Text>Visa ending in 4242 · Expires 08/28</Text>
        </div>
    </Card.Body>

    <Card.Footer>
        <Text>Invoices are emailed to billing@acme.com</Text>
    </Card.Footer>
</Card>
```

## Link card

Wrap a small card in a link for compact, clickable content like announcements or shortcuts.

```tsx
import { ArrowUpRightIcon } from '@fluxui-dev/react/icons';

<a href="#" aria-label="Latest on our blog">
    <Card size="xs" className="hover:bg-zinc-50 dark:hover:bg-zinc-700">
        <Heading className="flex items-center gap-2">Latest on our blog <ArrowUpRightIcon className="ml-auto text-zinc-400" variant="micro" /></Heading>
        <Text className="mt-2">Stay up to date with our latest insights, tutorials, and product updates.</Text>
    </Card>
</a>
```

## Reference

### Card

**Prop:**

- `body` - How the header, body, and footer are set apart. Options: `seamless` (default), `inset`, `flush`, `divided`, `separated`.
- `variant` - Visual treatment of the card's surface. Options: `default`, `muted`, `soft`, `outline`, `filled`. Default: `default`, with a shadow in light mode and elevation in dark mode. `outline` keeps the border without the shadow or dark-mode elevation.
- `size` - Scales the card's padding, corners, and spacing. Options: `xs`, `sm`, `md` (default), `lg`.
- `divider` - With `body="divided"`, set to `inset` to stop the dividers at the content's edges.
- `highlight` - A faint highlight along the inside of the card's top edge, in light mode. Default: `true`. Pass `highlight={false}` to turn it off.
- `children` - The card's parts, or any content to pad evenly.

**CSS:**

- `className` - Additional CSS classes applied to the card.

**Attribute:**

- `data-flux-card` - Applied to the root element for styling and identification.

### Card.Header

**Prop:**

- `size` - When used outside a card, matches the size of the card it sits beside. Inside a card, the card's size applies.
- `children` - A `Card.Heading`, an optional `Card.Subheading`, and optional `Card.Actions`.

### Card.Heading

**Prop:**

- `size` - Options: `base` (default), `lg`, `xl`, `2xl`.
- `level` - The heading level to render, such as `2` for an `h2`.

### Card.Subheading

**Prop:**

- `children` - Supporting text, tucked under the heading before it. Accepts every `Text` prop, such as `size` and `variant`.

### Card.Actions

**Prop:**

- `children` - Buttons or other controls. In a header they center on the heading and tuck into the corner rather than making the header taller. Placed after the heading they sit at the end; placed before it, at the start.

### Card.Body

**Prop:**

- `children` - The card's main content. Can also hold its own header and footer, which then act as a sub-section.

### Card.Footer

**Prop:**

- `size` - When used outside a card, matches the size of the card it sits beside.
- `children` - Supporting text and optional `Card.Actions`.

### Card.Bleed

**Prop:**

- `children` - Media to run out to the card's edges, such as an image.

**CSS Variable:**

- `--flux-bleed-x` - How far content reaches sideways to the nearest visible edge. Also available as `--flux-bleed`. Set automatically by cards.
- `--flux-bleed-top / --flux-bleed-bottom` - How far content at the start or end of a body reaches up or down.
- `--flux-bleed-top-radius / --flux-bleed-bottom-radius` - The radius of the corners that bleeding content reaches.
