# Avatar

> A person's picture, with initials or an icon when there is no image.

Use an avatar to show who did something or who an item belongs to. It shows the image when it loads, otherwise the person's initials, otherwise a person icon.

```tsx
import { Avatar } from "@aloxe/react";

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

## Installation

```bash
npm i @aloxe/react @aloxe/tokens
```

Then add the CSS imports from [Installation](/docs/getting-started/installation).

## Usage

```tsx
import { Avatar } from "@aloxe/react";

<Avatar name="Ada Lovelace" src={user.avatarUrl} />
```

`name` is the accessible name and the source of the initials: "Ada Lovelace" becomes AL.

## Examples

### Fallbacks

Initials show while the image loads or when it fails. Without a name, the avatar shows a person icon.

```tsx
import { Avatar } from "@aloxe/react";

export default function AvatarFallbacks() {
  return (
    <div className="flex flex-wrap items-center gap-3">
      {/* With a name: its initials, until src loads or when there is no image. */}
      <Avatar name="Alan Turing" size="lg" />
      {/* No name: a person icon, hidden from screen readers. */}
      <Avatar size="lg" />
    </div>
  );
}
```

### Next to a name

When the name is written next to the avatar, leave out `name` so screen readers don't read it twice. The avatar is then decorative.

```tsx
import { Avatar } from "@aloxe/react";

export default function AvatarWithName() {
  return (
    <div className="flex items-center gap-3">
      {/* The name is visible next to it, so the avatar itself stays decorative. */}
      <Avatar size="lg" />
      <div className="flex flex-col">
        <span className="aloxe-text-label-md text-ax-text">Margaret Hamilton</span>
        <span className="aloxe-text-body-sm text-ax-text-secondary">Engineering lead</span>
      </div>
    </div>
  );
}
```

## Accessibility

An avatar isn't focusable. To make it open a profile, wrap it in a link that has its own name.

- With `name`, the avatar is announced once as an image with that name, whatever it shows.
- Without `name`, it is hidden from screen readers.
- A hairline border keeps light photos visible on light surfaces.

## API reference

Every part accepts `className` and renders a `data-aloxe` attribute you can target in CSS, such as `[data-aloxe="avatar"]`.

**Avatar** (extends Base UI Avatar.Root)

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `name` | `string` |  |  | The person's name: the accessible name and the source of the initials. Omit it only when the name is visible next to the avatar. |
| `src` | `string` |  |  | Image URL. Initials, or a person icon, show until it loads or if it fails. |
| `size` | `"sm" \| "md" \| "lg" \| "xl"` | `"md"` |  | 24, 32, 40 or 48 px. |
| `className` | `string` |  |  | Merged with the default classes. |

## Figma

Matches the **Avatar** component. Figma `Size` (`Sm`, `Md`, `Lg`, `Xl`) maps to `size`. Figma `Type` (`Initials`, `Icon`) follows from `name` and `src`.

See [Figma](/docs/getting-started/figma) for where to get the file and how its names map to code.
