<!-- index: /slotted/llms.txt -->
# avatar

`data-ui="avatar"` · Image or initials that stand for a person.

## Minimal example

Example

```tsx
import { Avatar } from '@slotted/react/avatar';

export default function AvatarBasic() {
  return <Avatar name="Maria Chen" />;
}
```

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `name` | `string` | — | Avatar | The person or entity. It is the accessible name in every status, the source of the initials and the seed of the color. |
| `src` | `string` | — | Avatar | The picture. When absent, the avatar draws its fallback and requests nothing. |
| `initials` | `string` | — | Avatar | The letters to draw in place of those derived from the name. The box holds two letters, and xs holds one. |
| `tone` | `'auto' \| 'accent' \| 'secondary' \| 'info' \| 'success' \| 'warning' \| 'danger'` | auto | Avatar | The semantic color of the fallback. auto derives one of accent, secondary, success, warning or danger from the name; info applies only when set. |
| `idFor` | `string` | — | Avatar | A stable identifier to derive the color from, for a name that is not stable or that two people share. Defaults to name. |
| `variant` | `'soft' \| 'solid'` | soft | Avatar | How the color is painted: soft is tinted, solid is filled. |
| `surface` | `'tone' \| 'none' \| 'plate'` | tone | Avatar | The ground behind the avatar. tone paints the tone behind the fallback and nothing behind a loaded picture, none paints nothing, and plate paints a light plate in every color scheme, for a logo made for a white ground (--slotted-avatar-plate-surface). |
| `size` | `'xs' \| 'sm' \| 'md' \| 'lg' \| 'xl'` | md | Avatar | One of five steps. --slotted-avatar-size sets a size that no step holds. |
| `shape` | `'circle' \| 'square'` | circle | Avatar | circle is for a person; square is for a team, an organization or a bot. |
| `status` | `'idle' \| 'loading' \| 'loaded' \| 'error'` | — | Avatar | Where the picture is. A supplied value wins over the status derived from the img element. |
| `onStatusChange` | `(status) => void` | — | Avatar | Called with the derived status when the picture loads or fails. Not called for a status passed in. |
| `disabled` | `boolean` | false | Avatar | Marks a deactivated account, or an avatar inside a control that the page has turned off. |
| `decorative` | `boolean` | false | Avatar | Removes the avatar from the accessibility tree, for an avatar beside the name it belongs to. |
| `locale` | `string` | — | Avatar | BCP 47 tag that sets the case of the initials. Falls back to the defaults provider, then to the runtime locale. |
| `children` | `ReactNode` | — | Avatar | Content for the fallback in place of the initials and the glyph, such as a logo or an Icon. |
| `render` | `(props) => ReactNode` | — | Avatar | Renders the avatar into another element, such as an anchor for an avatar that opens a profile. |
| `renderImage` | `(props) => ReactNode` | — | Avatar | Renders the picture into the consumer’s own element, such as a Next.js Image, while the avatar keeps reporting the load. |
| `ref` | `Ref<HTMLElement>` | — | Avatar | Reaches the native element. The props type is the element’s own, extended. |
| `AvatarDefaultsProvider` | `{ size, shape, tone, variant, locale }` | — | a subtree | Sets the defaults for every avatar under it. An explicit prop wins. |

## Axes and defaults

| Axis | Values | Default |
| --- | --- | --- |
| `size` | `xs`, `sm`, `md`, `lg`, `xl` | `md` |
| `shape` | `circle`, `square` | `circle` |
| `tone` | `auto`, `accent`, `secondary`, `info`, `success`, `warning`, `danger` | `auto` |
| `variant` | `soft`, `solid` | `soft` |
| `surface` | `tone`, `none`, `plate` | `tone` |
| `status` | `idle`, `loading`, `loaded`, `error` | — |

## Rules

- The WAI-ARIA Authoring Practices have no avatar pattern. The guidance applied is the img role in WAI-ARIA 1.2, the W3C WAI alt decision tree, and WCAG 2.2 success criteria 1.1.1 Non-text Content, 1.4.11 Non-text Contrast and 2.5.8 Target Size (Minimum).
- The name is on the root as aria-label with role="img", and the picture takes an empty alt. The avatar announces the same name in all four statuses; naming the image instead would announce the initials before the photograph loads and the name after.
- An avatar with no name is aria-hidden, the rule that Icon takes. A present name sets role="img"; an absent name leaves nothing to announce.
- decorative covers a name written beside the avatar, where announcing it would read the person twice. The name still drives the initials and the color.
- The color derived from a name is an aid to scanning a list, not an identifier. The palette holds five colors, so collisions occur, and color alone is not a signal. The name identifies the person and is present in every status.
- An avatar is not focusable and not a command. render can make the root an anchor or a button; the avatar then draws the focus ring and the hover edge, and withholds both when disabled. The element that render returns keeps its own role and takes the name as aria-label; a generic element returned there passes role="img".
- An interactive avatar smaller than 24 by 24 CSS pixels grows a centered overlay to --slotted-target-min, which meets WCAG 2.2 2.5.8 at the two tighter densities without changing the layout. Inside a stack the overlay can reach under a neighbor; the raised member receives the pointer.
- The fallback glyph is the person Glyph in an aria-hidden Icon, not a character: no font reliably carries a silhouette, and a character would be read aloud.
- Under forced colors the avatar draws its edge in currentColor, because the theme maps every tone ground to one system color. The photograph is left unchanged.
- The picture crosses over the initials in --slotted-duration-short, which prefers-reduced-motion reduces to 1ms in the theme. Nothing loops.

## Tokens

`--slotted-avatar-border-width`, `--slotted-avatar-disabled-image-filter`, `--slotted-avatar-elevation`, `--slotted-avatar-font-family`, `--slotted-avatar-font-weight`, `--slotted-avatar-glyph-size`, `--slotted-avatar-initials-size`, `--slotted-avatar-plate-color`, `--slotted-avatar-plate-surface`, `--slotted-avatar-radius`, `--slotted-avatar-ring-color`, `--slotted-avatar-ring-width`, `--slotted-avatar-size`, `--slotted-avatar-size-lg`, `--slotted-avatar-size-md`, `--slotted-avatar-size-sm`, `--slotted-avatar-size-xl`, `--slotted-avatar-size-xs`, `--slotted-avatar-state-layer-active`, `--slotted-avatar-state-layer-hover`, `--slotted-border-strong`, `--slotted-border-subtle`, `--slotted-border-width-thick`, `--slotted-border-width-thin`, `--slotted-control-font-family`, `--slotted-disabled-background`, `--slotted-disabled-border`, `--slotted-disabled-foreground`, `--slotted-duration-short`, `--slotted-easing-enter`, `--slotted-easing-exit`, `--slotted-easing-standard`, `--slotted-focus-ring-color`, `--slotted-focus-ring-offset`, `--slotted-focus-ring-width`, `--slotted-font-weight-medium`, `--slotted-radius-full`, `--slotted-surface`, `--slotted-target-min`, `--slotted-text-box-edge`, `--slotted-tone-accent-border`, `--slotted-tone-accent-on-solid`, `--slotted-tone-accent-solid`, `--slotted-tone-accent-surface`, `--slotted-tone-accent-text`, `--slotted-tone-danger-border`, `--slotted-tone-danger-on-solid`, `--slotted-tone-danger-solid`, `--slotted-tone-danger-surface`, `--slotted-tone-danger-text`, `--slotted-tone-info-border`, `--slotted-tone-info-on-solid`, `--slotted-tone-info-solid`, `--slotted-tone-info-surface`, `--slotted-tone-info-text`, `--slotted-tone-secondary-border`, `--slotted-tone-secondary-on-solid`, `--slotted-tone-secondary-solid-hover`, `--slotted-tone-secondary-surface`, `--slotted-tone-secondary-text`, `--slotted-tone-success-border`, `--slotted-tone-success-on-solid`, `--slotted-tone-success-solid`, `--slotted-tone-success-surface`, `--slotted-tone-success-text`, `--slotted-tone-warning-border`, `--slotted-tone-warning-on-solid`, `--slotted-tone-warning-solid`, `--slotted-tone-warning-surface`, `--slotted-tone-warning-text`

## Examples

### A name is enough

Excerpt — not a complete module

```tsx
<Avatar name="Ada Lovelace" />;
```

### A picture, and the initials until it arrives

Excerpt — not a complete module

```tsx
<Avatar name="Ada Lovelace" src={person.photograph} />;
```

### Beside the name it belongs to

Excerpt — not a complete module

```tsx
<Inline align="center" gap={3}>
  <Avatar decorative name={person.name} src={person.photograph} />
  <Stack gap={1}>
    <Text weight="medium">{person.name}</Text>
    <Text tone="muted">{person.role}</Text>
  </Stack>
</Inline>;
```

### Presence, composed with Badge

Excerpt — not a complete module

```tsx
<BadgeAnchor overlap="circle" placement="bottom-end">
  <Avatar name="Ada Lovelace" src={person.photograph} />
  <Badge shape="dot" size="sm" tone="success" variant="solid">
    <VisuallyHidden>Online</VisuallyHidden>
  </Badge>
</BadgeAnchor>;
```

### An avatar that opens a profile

Excerpt — not a complete module

```tsx
<Avatar
  name="Ada Lovelace"
  render={(props) => <a {...props} href={`/people/${person.id}`} />}
  src={person.photograph}
/>;
```

### The picture in the consumer’s own element

Excerpt — not a complete module

```tsx
<Avatar
  name="Ada Lovelace"
  renderImage={(props) => <Image {...props} height={64} width={64} />}
  src={person.photograph}
/>;
```

### A square avatar, and a mark of its own

Excerpt — not a complete module

```tsx
<Avatar name="Acme Inc" shape="square" tone="accent" variant="solid">
  <Icon>
    <AcmeMark />
  </Icon>
</Avatar>;
```

### One decision for every avatar in the application

Excerpt — not a complete module

```tsx
<AvatarDefaultsProvider locale="pt-BR" size="sm">
  <App />
</AvatarDefaultsProvider>;
```

### decorative.tsx

Example

```tsx
import { Avatar } from '@slotted/react/avatar';
import { Inline } from '@slotted/react/inline';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

const PORTRAIT =
  "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' fill='%23c7d2fe'/%3E%3Ccircle cx='32' cy='25' r='11' fill='%234338ca'/%3E%3Cpath d='M10 64a22 22 0 0 1 44 0Z' fill='%234338ca'/%3E%3C/svg%3E";

export default function AvatarDecorative() {
  return (
    <Inline align="center" gap={3}>
      <Avatar decorative name="Maria Chen" size="lg" src={PORTRAIT} />
      <Stack gap={1}>
        <Text weight="medium">Maria Chen</Text>
        <Text size="sm" tone="muted">
          Warehouse supervisor
        </Text>
      </Stack>
    </Inline>
  );
}
```

### defaults.tsx

Example

```tsx
import { Avatar, AvatarDefaultsProvider } from '@slotted/react/avatar';
import { Inline } from '@slotted/react/inline';

export default function AvatarDefaults() {
  return (
    <AvatarDefaultsProvider shape="square" size="lg" variant="solid">
      <Inline align="center" gap={4}>
        <Avatar name="Night shift" />
        <Avatar name="Receiving" />
        <Avatar name="Maria Chen" shape="circle" size="sm" />
      </Inline>
    </AvatarDefaultsProvider>
  );
}
```

### fallback.tsx

Example

```tsx
import { Avatar } from '@slotted/react/avatar';
import { Glyph, Icon } from '@slotted/react/icon';
import { Inline } from '@slotted/react/inline';

export default function AvatarFallback() {
  return (
    <Inline align="center" gap={4}>
      <Avatar name="Maria Chen" size="lg" />
      <Avatar size="lg" />
      <Avatar name="Receiving dock" shape="square" size="lg" tone="info">
        <Icon>
          <Glyph name="inbox" />
        </Icon>
      </Avatar>
    </Inline>
  );
}
```

### identity.tsx

Example

```tsx
import { Avatar } from '@slotted/react/avatar';
import { Inline } from '@slotted/react/inline';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

export default function AvatarIdentity() {
  return (
    <Stack gap={4}>
      <Stack gap={2}>
        <Text size="sm" tone="muted">
          From the name
        </Text>
        <Inline gap={3}>
          <Avatar name="Maria Chen" />
          <Avatar name="Marta Okafor" />
          <Avatar name="Jonas Weber" />
          <Avatar name="Elena Rossi" />
        </Inline>
      </Stack>
      <Stack gap={2}>
        <Text size="sm" tone="muted">
          Same idFor, different names
        </Text>
        <Inline gap={3}>
          <Avatar idFor="emp-1042" name="Maria Chen" />
          <Avatar idFor="emp-1042" name="M. Chen" />
        </Inline>
      </Stack>
      <Stack gap={2}>
        <Text size="sm" tone="muted">
          Own initials
        </Text>
        <Inline gap={3}>
          <Avatar initials="D4" name="Dock 4 inbound" shape="square" />
        </Inline>
      </Stack>
    </Stack>
  );
}
```

### interactive.tsx

Example

```tsx
import { Avatar } from '@slotted/react/avatar';
import { Inline } from '@slotted/react/inline';

export default function AvatarInteractive() {
  return (
    <Inline align="center" gap={4}>
      <Avatar name="Maria Chen" render={(props) => <a {...props} href="#maria-chen" />} size="lg" />
      <Avatar
        name="Tomas Reyes"
        render={(props) => <button {...props} type="button" />}
        size="lg"
      />
      <Avatar
        name="Priya Raman"
        render={(props) => <a {...props} href="#priya-raman" />}
        size="xs"
      />
      <Avatar
        disabled
        name="Samuel Okafor"
        render={(props) => <button {...props} disabled type="button" />}
        size="lg"
      />
    </Inline>
  );
}
```

### picture.tsx

Example

```tsx
import { useState } from 'react';
import { Avatar } from '@slotted/react/avatar';
import type { AvatarStatus } from '@slotted/react/avatar';
import { Button } from '@slotted/react/button';
import { Inline } from '@slotted/react/inline';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

const PORTRAIT =
  "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' fill='%23c7d2fe'/%3E%3Ccircle cx='32' cy='25' r='11' fill='%234338ca'/%3E%3Cpath d='M10 64a22 22 0 0 1 44 0Z' fill='%234338ca'/%3E%3C/svg%3E";
const UNREADABLE = 'data:image/png;base64,AAAA';

export default function AvatarPicture() {
  const [failed, setFailed] = useState(false);
  const [status, setStatus] = useState<AvatarStatus>('loading');

  return (
    <Stack gap={4}>
      <Avatar
        name="Maria Chen"
        onStatusChange={setStatus}
        size="xl"
        src={failed ? UNREADABLE : PORTRAIT}
      />
      <Text size="sm" tone="muted">
        Status: {status}
      </Text>
      <Inline>
        <Button onClick={() => setFailed(!failed)} tone="secondary" variant="outline">
          {failed ? 'Restore the picture' : 'Fail the request'}
        </Button>
      </Inline>
    </Stack>
  );
}
```

### shapes.tsx

Example

```tsx
import { Avatar } from '@slotted/react/avatar';
import { Inline } from '@slotted/react/inline';

export default function AvatarShapes() {
  return (
    <Inline align="center" gap={4}>
      <Avatar name="Maria Chen" shape="circle" size="lg" />
      <Avatar name="Night shift" shape="square" size="lg" />
      <Avatar name="Northwind Logistics" shape="square" size="lg" />
      <Avatar name="Replenishment bot" shape="square" size="lg" />
    </Inline>
  );
}
```

### sizes.tsx

Example

```tsx
import { Avatar } from '@slotted/react/avatar';
import { Inline } from '@slotted/react/inline';

export default function AvatarSizes() {
  return (
    <Inline align="center" gap={4}>
      <Avatar name="Maria Chen" size="xs" />
      <Avatar name="Maria Chen" size="sm" />
      <Avatar name="Maria Chen" size="md" />
      <Avatar name="Maria Chen" size="lg" />
      <Avatar name="Maria Chen" size="xl" />
    </Inline>
  );
}
```

### status.tsx

Example

```tsx
import { Avatar } from '@slotted/react/avatar';
import { Inline } from '@slotted/react/inline';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

const PORTRAIT =
  "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' fill='%23c7d2fe'/%3E%3Ccircle cx='32' cy='25' r='11' fill='%234338ca'/%3E%3Cpath d='M10 64a22 22 0 0 1 44 0Z' fill='%234338ca'/%3E%3C/svg%3E";

const STATUSES = ['idle', 'loading', 'loaded', 'error'] as const;

export default function AvatarStatusExample() {
  return (
    <Inline gap={6}>
      {STATUSES.map((status) => (
        <Stack gap={2} key={status}>
          <Avatar name="Maria Chen" size="lg" src={PORTRAIT} status={status} />
          <Text size="sm" tone="muted">
            {status}
          </Text>
        </Stack>
      ))}
    </Inline>
  );
}
```

### surface.tsx

Example

```tsx
import { Avatar } from '@slotted/react/avatar';
import type { AvatarSurface } from '@slotted/react/avatar';
import { Inline } from '@slotted/react/inline';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

const LOGO =
  "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Cpath d='M8 52V12h8l32 28V12h8v40h-8L16 24v28Z' fill='%23111827'/%3E%3C/svg%3E";
const SURFACES: AvatarSurface[] = ['tone', 'none', 'plate'];

export default function AvatarSurfaceExample() {
  return (
    <Inline gap={6}>
      {SURFACES.map((surface) => (
        <Stack gap={2} key={surface}>
          <Avatar name="Nordic Freight" shape="square" size="lg" src={LOGO} surface={surface} />
          <Text size="sm" tone="muted">
            {surface}
          </Text>
        </Stack>
      ))}
    </Inline>
  );
}
```

### tones.tsx

Example

```tsx
import { Avatar } from '@slotted/react/avatar';
import type { AvatarTone, AvatarVariant } from '@slotted/react/avatar';
import { Inline } from '@slotted/react/inline';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

const TONES: AvatarTone[] = ['accent', 'secondary', 'info', 'success', 'warning', 'danger'];
const VARIANTS: AvatarVariant[] = ['soft', 'solid'];

export default function AvatarTones() {
  return (
    <Stack gap={4}>
      {VARIANTS.map((variant) => (
        <Stack gap={2} key={variant}>
          <Text size="sm" tone="muted">
            {variant}
          </Text>
          <Inline gap={3}>
            {TONES.map((tone) => (
              <Avatar key={tone} name="Maria Chen" tone={tone} variant={variant} />
            ))}
          </Inline>
        </Stack>
      ))}
    </Stack>
  );
}
```
