---
description: Cards for grouping content, badges for short labels, and avatars for
  people and teams
output-file: surfaces.html
title: surfaces

---
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

[`Card`](surfaces.md#card) wraps content in a bordered section styled with the shared colour, spacing, and radius tokens. [`Badge`](surfaces.md#badge) renders an inline text label for a category, count, or status. [`Avatar`](surfaces.md#avatar) renders a circular image or initials for a person or team.

```python
from fasthtml.common import Article, Header, Footer, Small, to_xml
from answerui.layout import Grid
from answerui.controls import Btn
from answerui.demo import demo
from urllib.parse import quote
```

## Card

Add the `card` attribute to any element for a `--color-surface` background, a 1px `--color-border`, `--space` padding, `--radius` corners, and a `--raised` shadow. `[card]` uses no bevels so cards do not look clickable. `Card(...)` returns a `<section card>` element and uses no JavaScript.

`[card]` sets no child layout. Pass `stack=True` for a vertical stack, or nest another layout inside the card.

---

### Card

```python
def Card(
    *c, **attrs
):
```

*A bordered section with no prescribed layout*

Inner padding comes from `[card]`. Add `stack=True` for spacing between children, and use a surrounding layout such as [`Grid`](layout.md#grid) or [`Stack`](layout.md#stack) to space cards apart.

```python
Card.demo()
```

### Composition

You can use any HTML structure inside a card without dedicated header, body, or footer constructors. Below, [`Grid`](layout.md#grid) arranges two cards side by side when the container is wide enough. The second card is an `Article` with `card=True` and `stack=True` directly, using `stack=True` on its `Header` and `cluster=True` on its `Footer`.

```python
demo(Grid(
    _card_example(),
    Article(
        Header(H3('Field notes'), Small('Updated today'), stack=True, cls='gap-1'),
        P('Observations and ideas from the team, ready for the next meeting.'),
        Footer(Btn('Open project'), Btn('Archive', variant='secondary'), cluster=True),
        card=True, stack=True)))
```

### Customisation

Overriding `--radius` or `--space` changes card corners and padding across a region. To restyle all cards without affecting other components, add a rule such as `[card] { padding: var(--space1); }` in `@layer app`. For a single card, pass utility classes such as `cls='gap-2 p-2'` (or inline `style` for custom values):

```python
to_xml(Card(P('A compact note'), P('Another line'), stack=True, cls='gap-2 p-2'))
```

```output
'<section card stack class="gap-2 p-2">\n  <p>A compact note</p>\n  <p>Another line</p>\n</section>\n'
```

You can combine `card=True` with any layout constructor, such as `Grid(..., card=True)`, without adding a wrapper `div`. Plain `article`, `section`, and `div` elements without `card` have no card border or background.

## Badge

[`Badge`](surfaces.md#badge) renders an inline `<span>` with a soft `--v-3` background and `--v2` text rather than the solid, raised fill used on buttons. Pass `ui_tone` (such as `'success'`, `'warning'`, `'danger'`, or `'info'`) to change its hue, or `variant='secondary'` for neutral `--color-surface` and `--color-text` styling with a 1px inset `--color-border`.

---

### Badge

```python
def Badge(
    *c, variant=None, **attrs
):
```

*A small text label, optionally coloured with `ui_tone`*

Badges use `em` padding (`.125em .5em`) at `--text-1` size so padding scales with the text. Put the meaning in the badge text and use colour only to reinforce it. `[badge]` is display-only, with no interaction or ARIA live-region role.

```python
Badge.demo()
```

Badges have no outer margin. Below, [`Cluster`](layout.md#cluster) places a badge beside the heading while `Card(..., stack=True)` spaces the rows apart. Pass counts as ordinary text children rather than CSS-generated content:

```python
demo(Card(
    Cluster(H3('Field notes'), Badge('Shared'), cls='gap-2'),
    P('Observations and ideas from the team.'),
    Cluster(Span('Unread notes'), Badge(3, variant='secondary'), cls='gap-2'), stack=True))
```

## Avatar

[`Avatar`](surfaces.md#avatar) takes a `name` and an optional image URL in `src`. With `src`, it renders an `<img>` with `alt=name`. Without `src`, it renders a `<span role="img">` showing the first and last initials (or `?` if `name` is empty) with `aria-label` set to `name` (or `'Unknown'`). Both forms share the same circular frame controlled by `--avatar-size` (default `2.5rem`), with initials sized to 40% of `--avatar-size`.

---

### Avatar

```python
def Avatar(
    name, src=None, **attrs
):
```

*A circular image or initials identifying a person or team*

```python
Avatar.demo()
```

```python
def _picture(name): return f'https://api.dicebear.com/10.x/miniavs/svg?seed={quote(name)}&backgroundColor=ffe3ea'
demo(Cluster(Avatar('Ada Lovelace', src=_picture('Ada Lovelace'), aria_hidden='true'),
    Stack(Span('Ada Lovelace'), Small('Workspace owner'), cls='gap-1')))
```

To make an avatar clickable, place it as the only child of a [`Btn`](controls.md#btn). The `[btn]:has(> [avatar]:only-child)` rule sets `1px` padding, `border-radius: var(--radius-full)`, `--face: var(--color-surface)`, and `--color-border` on the button without overriding the avatar's colours. When the button is disabled, the avatar has `opacity: .5`.

```python
demo(Cluster(Btn(Avatar('Ada Lovelace')), Btn(Avatar('Grace Hopper', src=_picture('Grace Hopper'))),
    Btn(Avatar('Alan Turing', src=_picture('Alan Turing')), disabled=True)))
```

## Inset

[`Inset`](surfaces.md#inset) renders a left-bordered panel (`[inset]`) for conditional form fields (such as `Checkbox(reveals=...)` targets or Svelte `{#if}` panels) and callout notes. Pass `ui_tone` to tint the rail.

---

### Inset

```python
def Inset(
    *c, **attrs
):
```

*A left-bordered panel for conditional form fields or inset callout text*

```python
Inset.demo()
```

## Disclosure and Accordion

[`Disclosure`](surfaces.md#disclosure) wraps native `<details disclosure>` with `<summary>` and a padded body `<div>`. Group multiple [`Disclosure`](surfaces.md#disclosure) elements inside [`Accordion`](surfaces.md#accordion) (using the same `name` attribute for exclusive open).

---

### Accordion

```python
def Accordion(
    *c, **attrs
):
```

*A stacked group of [`Disclosure`](surfaces.md#disclosure) elements*

---

### Disclosure

```python
def Disclosure(
    summary, *c, **attrs
):
```

*A native collapsible `<details>` disclosure with `<summary>`*

```python
Accordion.demo()
```
