# Avatar stack

Overlapping profile chips fan out and lift on hover or focus.

## Usage

Use for a small team or group of collaborators. Replace the illustrative people with real users and connect onSelect to a profile view when appropriate. For large groups, show a count instead of crowding the row.

Save the JSX and CSS Module in the same folder in a React project with CSS Modules support. Controlled components need parent state and change handlers.

## JSX

```jsx
"use client";
import styles from "./AvatarStack.module.css";
import { useState } from "react";
const people = [
  {
    name: "Dianne",
    initials: "DI",
    color: "#d9cbe6",
    role: "Design direction",
  },
  { name: "Alex", initials: "AL", color: "#cbd8c0", role: "Product design" },
  { name: "Sam", initials: "SA", color: "#edcdb7", role: "Engineering" },
  { name: "Jo", initials: "JO", color: "#c9dfe8", role: "Research" },
];
export default function AvatarStack({ members = people, onSelect }) {
  const [selected, setSelected] = useState(null);
  return (
    <div className={styles.root}>
      <p className={styles.label}>Good work is a team sport.</p>
      <div className={styles.stack}>
        {members.map((person, index) => (
          <button
            key={person.name}
            type="button"
            aria-label={`View ${person.name}`}
            aria-pressed={selected === person.name}
            style={{ "--avatar": person.color, "--order": index }}
            onClick={() => {
              setSelected(person.name);
              onSelect?.(person);
            }}
          >
            <span className={styles.name}>{person.name}</span>
            <span aria-hidden="true">{person.initials}</span>
          </button>
        ))}
      </div>
      <p className={styles.selected} role="status">
        {selected
          ? `${selected} · ${members.find((person) => person.name === selected)?.role}`
          : `${members.length} people, one shared direction.`}
      </p>
    </div>
  );
}

```

## CSS

```css
.root {
  width: 100%;
  text-align: center;
  padding: 20px 0;
}
.label {
  font-size: 13px;
  margin: 0 0 35px;
  color: var(--tdp-muted, #6b625b);
}
.stack {
  display: flex;
  justify-content: center;
  padding: 0 14px;
}
.stack button {
  width: 58px;
  height: 58px;
  flex: none;
  border: 3px solid var(--tdp-surface, #fffdfa);
  border-radius: 50%;
  background: var(--avatar);
  color: #302e2b;
  margin-left: -12px;
  position: relative;
  box-shadow: 0 3px 7px #3c2d2110;
  transition:
    transform 0.3s,
    margin 0.3s,
    box-shadow 0.3s;
  font-size: 14px;
  font-weight: 500;
}
.stack button:first-child {
  margin-left: 0;
}
.stack:is(:hover, :focus-within) button {
  margin-left: 3px;
}
.stack button:is(:hover, :focus-visible) {
  transform: translateY(-10px) scale(1.08);
  z-index: 2;
  box-shadow: 0 12px 20px #3c2d2120;
}
.stack button[aria-pressed="true"] {
  outline: 2px solid var(--tdp-primary, #1f3934);
  outline-offset: 2px;
}
.name {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%);
  background: #302e2b;
  color: #fff;
  padding: 4px 8px;
  border-radius: 5px;
  font: 11px system-ui;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.stack button:is(:hover, :focus-visible) .name {
  opacity: 1;
}
.selected {
  margin: 26px 0 0;
  font-size: 12px;
  min-height: 20px;
  color: var(--tdp-muted, #6b625b);
}
.root {
  font-family: var(--tdp-font, "DM Sans", system-ui, sans-serif);
  color: var(--tdp-text, #302e2b);
  max-width: 100%;
  box-sizing: border-box;
}
.root * {
  box-sizing: border-box;
}
.root :is(button, input, a):focus-visible,
.root:focus-visible {
  outline: 3px solid var(--tdp-focus, #7851a9);
  outline-offset: 4px;
}
.root button {
  font: inherit;
  cursor: pointer;
}
.root button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}
.root button,
.root a {
  touch-action: manipulation;
}
@media (prefers-reduced-motion: reduce) {
  .root,
  .root *,
  .root::before,
  .root::after {
    animation: none !important;
    transition: none !important;
    transform: none !important;
    translate: none !important;
    rotate: none !important;
    scale: none !important;
    scroll-behavior: auto !important;
  }
}
@media (max-width: 400px) {
  .stack {
    padding: 0;
  }
  .stack button {
    width: 48px;
    height: 48px;
  }
}

```

## Props

- members (array): Unique name, initials, color, and role for each member.
- onSelect (function): Receives the selected member.

## Accessibility

Every profile is a named button. Hover names also appear on focus, and selection is announced. Initials are decorative because the button already has the full name.

Check accessibility again after customizing the component.

[Browse all components](/resources/components/)

Canonical: https://designproject.io/resources/components/avatar-stack/

## Keep learning

- [How to create a UI color palette, step by step](https://designproject.io/resources/guides/create-ui-color-palette/)
- [Product design glossary: 44 terms explained](https://designproject.io/resources/glossary/)
- [How to choose font pairings for a product interface](https://designproject.io/resources/guides/choose-font-pairings/)
