<!--
  GENERATED FILE - do not edit by hand.
  Source of truth: src/components/mds-avatar/ in the magma monorepo (usage/*.md and the
  component's JSDoc). Regenerated on every stencil build (scripts/component-docs.ts).
-->

# mds-avatar

> `@maggioli-design-system/magma` 2.15.0. Shadow DOM: style it only through the public CSS custom properties and the parts below.

The `<mds-avatar>` web component renders a compact, circular representation of a user or entity in the Magma Design System. It resolves a single visual from whichever input is provided - a profile image, textual initials, a numeric overflow count, or an icon - and falls back to a generic person glyph when nothing usable is supplied.

#### Semantic Behavior

- **Content resolution**: Exactly one visual is shown at a time, picked in one order: `count`, then the `src` image, then `initials`, then `icon`, then the generic person fallback. A source hides the ones after it, so `initials` or `icon` next to `src` are the fallbacks of the image.
- **Deterministic identity color**: When `initials` is set, the component derives the color from its characters, so the same person always maps to the same color and stays distinguishable from others. Any explicit `variant` is ignored in this case; `count` derives no color and keeps the `variant`.
- **Image load fallback**: If the `src` image fails to load, the avatar shows the next source in the order: `initials`, then `icon`, then the generic person fallback icon. A new `src` is tried again.
- **Auto-fitting initials**: Initials and count text scale to fit the avatar, so they stay legible across every size.
- **Initials display**: The first two characters of `initials` are displayed as they are, uppercased, so pass the initials (`MR`), not the full name. Non-alphanumeric characters are stripped only to compute the color.

#### Properties & Visual Configurations

The shared `variant` / `tone` ladders are defined in [`agents/variants.md`](../../../../agents/variants.md). Note that `tone` is limited to the minimal set (`'strong'` / `'weak'`), and any explicit `variant` is ignored whenever `initials` is present, since identity color takes precedence.

#### Other behavioral props

- **`src`** is the path to a profile image; prefer it when a real photo is available. Only `count` hides it; `initials` and `icon` set as well show when the image fails to load.
- **`initials`** carries the textual stand-in for a user when no image exists; it drives the deterministic identity color.
- **`count`** renders a `+N` overflow badge and is intended for stacked/grouped avatar scenarios rather than individual users.
- **`icon`** is an SVG filename slug from the Magma icon library, used when the avatar represents a non-personal entity rather than a human.

## Read next

- [`examples.md`](examples.md) - correct usage, from the most common case
- [`mistakes.md`](mistakes.md) - the wrong forms, each with the right one
- [Storybook](https://magma-design-system.github.io/magma/storybook/?path=/docs/ui-avatar--docs) - the live examples, in the published Storybook of `main`
- [`conventions.md`](../../../../agents/conventions.md), [`variants.md`](../../../../agents/variants.md), [`mistakes.md`](../../../../agents/mistakes.md) - the rules shared by every component

## Props

| Prop | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `count` | `count` | `number \| undefined` | - | The user's inizials displayed if there's no image available, initials will override tone and variant senttings to keep user recognizable from others |
| `icon` | `icon` | `string \| undefined` | - | Specifies the path to the icon |
| `initials` | `initials` | `string \| undefined` | - | The user's inizials displayed if there's no image available, initials will override tone and variant senttings to keep user recognizable from others |
| `src` | `src` | `string \| undefined` | - | Specifies the path to the image |
| `tone` | `tone` | `"strong" \| "weak" \| undefined` | - | Specifies the color tone of the component |
| `variant` | `variant` | `"amaranth" \| "aqua" \| "blue" \| "error" \| "green" \| "info" \| "lime" \| "orange" \| "orchid" \| "primary" \| "purple" \| "red" \| "sky" \| "success" \| "violet" \| "warning" \| "yellow" \| undefined` | - | Specifies the color variant of the component |

## Parts

| Part | Description |
| --- | --- |
| `icon` | The selected icon of the avatar |
| `media` | The media displayed |
| `wrapper` | The wrapper which contains media displayed |

## CSS custom properties

| Property | Description |
| --- | --- |
| `--mds-avatar-background-color` | The background-color of the component |
| `--mds-avatar-color` | The color of the placeholder icon |
| `--mds-avatar-radius` | The border-radius of the element |

Only these are public. Its other 2 are internal: they may change in any release, do not set them.

## Dependencies

Uses: `mds-img`, `mds-icon`.
Used by: `mds-avatar-stack-item`, `mds-entity`, `mds-push-notification-item`.
