# Avatar

> A person or team image with an initials fallback in a stable color per name.

Status: stable. Category: Data display.

```ts
import { Avatar, AvatarGroup } from '@glyphui/ui'
```

Exports: `Avatar`, `AvatarGroup`, `avatarStyles`.

## Notes

- The name is used for the image alt text and the initials, so it is required.

## Avatar props

| Prop | Type | Default | Description |
|---|---|---|---|
| `name` (required) | `string` |  | Used for the image alt text and the initials fallback. |
| `asChild` | `boolean` |  |  |
| `size` | `"sm" \| "md" \| "lg" \| "xs"` |  |  |
| `src` | `string` |  |  |

## Example: Sizes

```tsx
import { Avatar } from '@glyphui/ui'

export default function Example() {
  return (
    <div className="flex items-center gap-3">
      <Avatar name="Ada Lovelace" size="xs" />
      <Avatar name="Ada Lovelace" size="sm" />
      <Avatar name="Ada Lovelace" size="md" />
      <Avatar name="Ada Lovelace" size="lg" />
    </div>
  )
}
```

## Example: With an image

Falls back to initials while loading or if the image fails.

```tsx
import { Avatar } from '@glyphui/ui'

export default function Example() {
  return (
    <div className="flex items-center gap-3">
      <Avatar
        name="Grace Hopper"
        src="https://avatars.githubusercontent.com/u/9919?s=96"
        size="lg"
      />
      <Avatar name="Broken Image" src="https://example.invalid/missing.png" size="lg" />
    </div>
  )
}
```

## Example: Group

```tsx
import { Avatar, AvatarGroup, Text } from '@glyphui/ui'

const team = ['Ada Lovelace', 'Grace Hopper', 'Alan Kay', 'Radia Perlman', 'Ken Thompson']

export default function Example() {
  return (
    <div className="flex items-center gap-3">
      <AvatarGroup>
        {team.map((name) => (
          <Avatar key={name} name={name} />
        ))}
      </AvatarGroup>
      <Text size="small" tone="muted">
        5 people on Design
      </Text>
    </div>
  )
}
```

Live page: https://glyphui.xyz/components/avatar
