<!--
  GENERATED FILE - do not edit by hand.
  Source of truth: src/components/mds-avatar-stack-item/usage/ in the magma monorepo.
-->

# mds-avatar-stack-item - examples

> The API of this component: [`AGENTS.md`](AGENTS.md).

Correct and idiomatic ways to use the `<mds-avatar-stack-item>` component, ordered from most common to most specialized. The examples assume a working knowledge of the shared component rules in [`agents/conventions.md`](../../../../agents/conventions.md).

#### Basic Stack with Initials

The most common form: place one item per participant inside [`mds-avatar-stack`](../mds-avatar-stack/AGENTS.md). Use `initials` for users without a photo; the stack applies uniform sizing and overlap automatically.

```html
<mds-avatar-stack>
  <mds-avatar-stack-item initials="mr"></mds-avatar-stack-item>
  <mds-avatar-stack-item initials="ac"></mds-avatar-stack-item>
  <mds-avatar-stack-item initials="er"></mds-avatar-stack-item>
</mds-avatar-stack>
```

#### Stack with Photos

Use `src` when a real user photo is available. While `src` is set, `initials` is not displayed: an image that cannot be loaded is replaced by the generic person glyph. Items without `src` show their `initials`, and the tone/variant placeholder when neither is provided.

```html
<mds-avatar-stack>
  <mds-avatar-stack-item src="/avatars/mario-rossi.jpg" initials="mr"></mds-avatar-stack-item>
  <mds-avatar-stack-item src="/avatars/anna-conti.jpg" initials="ac"></mds-avatar-stack-item>
  <mds-avatar-stack-item initials="er"></mds-avatar-stack-item>
</mds-avatar-stack>
```

#### Tone and Variant for Placeholder Color

When no image or initials are provided, `tone` and `variant` determine the placeholder background. Use distinct variant values to keep users visually distinguishable. `tone` defaults to `weak`; use `strong` for higher contrast.

```html
<mds-avatar-stack>
  <mds-avatar-stack-item variant="blue" tone="weak"></mds-avatar-stack-item>
  <mds-avatar-stack-item variant="green" tone="weak"></mds-avatar-stack-item>
  <mds-avatar-stack-item variant="orchid" tone="strong"></mds-avatar-stack-item>
</mds-avatar-stack>
```

#### Overflow Counter via Parent `total`

Set `total` on the parent to let it append the overflow badge automatically. The badge value is `total` minus the number of slotted items - do not set `count` on the items yourself for this use case.

```html
<mds-avatar-stack total="12">
  <mds-avatar-stack-item initials="mr"></mds-avatar-stack-item>
  <mds-avatar-stack-item initials="ac"></mds-avatar-stack-item>
  <mds-avatar-stack-item initials="er"></mds-avatar-stack-item>
</mds-avatar-stack>
```

#### Manual Overflow Badge via `count`

Use `count` directly on a trailing item only when you are building the overflow indicator yourself and the parent does not own the total. This is rarely needed outside of fully custom stacks.

```html
<mds-avatar-stack>
  <mds-avatar-stack-item initials="mr"></mds-avatar-stack-item>
  <mds-avatar-stack-item initials="ac"></mds-avatar-stack-item>
  <mds-avatar-stack-item count="8"></mds-avatar-stack-item>
</mds-avatar-stack>
```

#### Size Controlled by the Parent

Size is not set per item - it is set once on the parent with `size` (`sm`, `md`, `lg`). All items in the stack scale together.

```html
<!-- Small stack: dense lists, table cells -->
<mds-avatar-stack size="sm">
  <mds-avatar-stack-item initials="mr"></mds-avatar-stack-item>
  <mds-avatar-stack-item initials="ac"></mds-avatar-stack-item>
</mds-avatar-stack>

<!-- Large stack: profile overviews, hero sections -->
<mds-avatar-stack size="lg">
  <mds-avatar-stack-item initials="er"></mds-avatar-stack-item>
  <mds-avatar-stack-item initials="mt"></mds-avatar-stack-item>
</mds-avatar-stack>
```

#### Styling Customization

Style individual items through their public `--mds-avatar-stack-item-*` CSS custom properties, or control the whole stack at once via the parent's public `--mds-avatar-stack-background` (the item ring color inherits from it). Use semantic color roles with `rgb(var(--magma-<role>))` so dark mode keeps working.

```css
/* Override the separator ring color for the whole stack */
.collab-panel mds-avatar-stack {
  --mds-avatar-stack-background: rgb(var(--magma-surface-raised));
}

/* Override the separator ring color of a single item */
.collab-panel mds-avatar-stack-item.highlight {
  --mds-avatar-stack-item-background: rgb(var(--magma-accent-emphasis));
}
```
