# Avatar Stack

> Overlapping avatars that fan out on hover: each lifts to show its name, presence dots show who's around, and a +N chip lists the rest.

Category: Layout · Free · Updated 2026-11-10 · Live demo: https://www.motionkitui.com/components/avatar-stack

## When to use it

Team and collaborator lists, "who's viewing" indicators, shared documents and boards, social proof and community sections.

## How it works

Avatars sit in a row with a negative margin, so each tucks under the one before, and later faces sit lower in the stack. Hovering or focusing the group springs every margin to a small gap so the faces fan out; the one under the pointer or focus lifts above the rest and shows its name. People without a photo get their initials on a colour picked from their name, so each keeps the same colour. Everyone past the limit collapses into a +N chip that lists them.

## Installation

```bash
npx shadcn@latest add https://www.motionkitui.com/r/avatar-stack.json
```

Or copy `components/motionkit/avatar-stack.tsx` below. Requires react, motion and Tailwind CSS v4. Free for personal projects; commercial use needs MotionKit Plus (https://www.motionkitui.com/pricing).

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `people` | `Person[]` |  | Each person's name, with an optional photo and status (online, away or offline). |
| `max` | `number` | `5` | Faces shown before the rest collapse into +N. |
| `size` | `number` | `40` | Diameter of each avatar in pixels. |
| `overlap` | `number` | `0.3` | How much each avatar tucks under the one before, as a share of its size. |
| `colors` | `string[]` |  | Background colours for initials, picked by name so each person keeps theirs. |

## Accessibility

- **Keyboard: Pass.** Each face and the +N chip can be focused with Tab, which fans the stack out and shows that person's name.
- **Screen readers: Pass.** The list is labelled with everyone's names; each face is read as its name and status, and the chip as "and 3 more" with their names.
- **Reduced motion: Pass.** With reduced motion on, the stack spreads and names appear without springing.
- **Colour contrast: Pass.** Initials on every default colour measure 4.5:1 or more; if you pass your own colours, keep dark text readable on them.

## Source

```tsx
"use client";

import { useState } from "react";
import { AnimatePresence, motion, useReducedMotion } from "motion/react";

export type Person = {
  name: string;
  /** A photo. Without one, their initials show on a colour picked from their name. */
  src?: string;
  status?: "online" | "away" | "offline";
};

type AvatarStackProps = {
  people: Person[];
  /** How many faces show before the rest collapse into a "+N". */
  max?: number;
  /** Diameter of each avatar in pixels. */
  size?: number;
  /** How much each avatar tucks under the one before it, as a share of its size. */
  overlap?: number;
  /** Background colours for initials, chosen by name so each person keeps theirs. */
  colors?: string[];
  className?: string;
};

const statusColor = { online: "#7FD1AE", away: "#E9B872", offline: "#5E7271" } as const;
const statusText = { online: "online", away: "away", offline: "offline" } as const;
const palette = ["#5FAEB4", "#A56D5B", "#7D9E9D", "#B9C7FF", "#D6A7CE", "#E9B872"];

const initials = (name: string) =>
  name
    .split(/\s+/)
    .filter(Boolean)
    .slice(0, 2)
    .map((part) => part[0]!.toUpperCase())
    .join("");

const pick = (name: string, colors: string[]) => colors[[...name].reduce((sum, char) => sum + char.charCodeAt(0), 0) % colors.length];

/**
 * Overlapping avatars for teams, collaborators and "who's here". Hover or focus the stack and the faces fan out;
 * each one lifts and shows its name, presence dots show who's around, and a "+N" chip lists the rest.
 */
export function AvatarStack({ people, max = 5, size = 40, overlap = 0.3, colors = palette, className = "" }: AvatarStackProps) {
  const reduceMotion = useReducedMotion();
  const [open, setOpen] = useState(false);
  const [focused, setFocused] = useState<number | null>(null);
  const shown = people.slice(0, max);
  const rest = people.slice(max);
  const tuck = -size * overlap;
  const spring = reduceMotion ? { duration: 0 } : ({ type: "spring", stiffness: 420, damping: 30 } as const);
  const summary = `${people.length} ${people.length === 1 ? "person" : "people"}: ${people.map((person) => person.name).join(", ")}`;

  return (
    <ul
      aria-label={summary}
      onPointerEnter={() => setOpen(true)}
      onPointerLeave={() => {
        setOpen(false);
        setFocused(null);
      }}
      onFocus={() => setOpen(true)}
      onBlur={(event) => {
        if (!event.currentTarget.contains(event.relatedTarget as Node | null)) {
          setOpen(false);
          setFocused(null);
        }
      }}
      className={`flex items-center ${className}`}
    >
      {shown.map((person, index) => (
        <motion.li
          key={`${person.name}-${index}`}
          className="relative"
          style={{ zIndex: focused === index ? 50 : shown.length - index }}
          initial={false}
          animate={{ marginLeft: index === 0 ? 0 : open ? 6 : tuck, y: focused === index ? -4 : 0 }}
          transition={spring}
          onPointerEnter={() => setFocused(index)}
        >
          <span
            tabIndex={0}
            role="img"
            aria-label={`${person.name}${person.status ? `, ${statusText[person.status]}` : ""}`}
            onFocus={() => setFocused(index)}
            className="relative grid place-items-center rounded-full font-medium text-[#0C1010] outline-none ring-2 ring-[#141B1B] focus-visible:ring-[#B9C7FF]"
            style={{ width: size, height: size, fontSize: size * 0.36, backgroundColor: person.src ? "#1D2727" : pick(person.name, colors) }}
          >
            {person.src ? (
              // eslint-disable-next-line @next/next/no-img-element -- any URL, at any size
              <img src={person.src} alt="" className="size-full rounded-full object-cover" />
            ) : (
              <span aria-hidden>{initials(person.name)}</span>
            )}
            {person.status && (
              <span aria-hidden className="absolute bottom-0 right-0 rounded-full ring-2 ring-[#141B1B]" style={{ width: size * 0.26, height: size * 0.26, backgroundColor: statusColor[person.status] }} />
            )}
          </span>
          <AnimatePresence>
            {focused === index && (
              <motion.span
                aria-hidden
                initial={{ opacity: 0, y: 4, scale: 0.96 }}
                animate={{ opacity: 1, y: 0, scale: 1 }}
                exit={{ opacity: 0, y: 4, scale: 0.96 }}
                transition={{ duration: reduceMotion ? 0 : 0.15 }}
                className="pointer-events-none absolute bottom-full left-1/2 mb-2 -translate-x-1/2 whitespace-nowrap rounded-lg border border-white/10 bg-[#0C1010]/95 px-2.5 py-1 text-xs text-[#F6F1E8] shadow-lg"
              >
                {person.name}
                {person.status && <span className="ml-1.5 text-[#94A9A7]">{statusText[person.status]}</span>}
              </motion.span>
            )}
          </AnimatePresence>
        </motion.li>
      ))}

      {rest.length > 0 && (
        <motion.li className="relative" style={{ zIndex: focused === -1 ? 50 : 0 }} initial={false} animate={{ marginLeft: open ? 6 : tuck }} transition={spring} onPointerEnter={() => setFocused(-1)}>
          <span
            tabIndex={0}
            role="img"
            aria-label={`and ${rest.length} more: ${rest.map((person) => person.name).join(", ")}`}
            onFocus={() => setFocused(-1)}
            className="grid place-items-center rounded-full bg-[#1D2727] font-medium tabular-nums text-[#DCE3E2] outline-none ring-2 ring-[#141B1B] focus-visible:ring-[#B9C7FF]"
            style={{ width: size, height: size, fontSize: size * 0.32 }}
          >
            +{rest.length}
          </span>
          <AnimatePresence>
            {focused === -1 && (
              <motion.ul
                aria-hidden
                initial={{ opacity: 0, y: 4, scale: 0.96 }}
                animate={{ opacity: 1, y: 0, scale: 1 }}
                exit={{ opacity: 0, y: 4, scale: 0.96 }}
                transition={{ duration: reduceMotion ? 0 : 0.15 }}
                className="pointer-events-none absolute bottom-full left-1/2 mb-2 max-h-48 w-44 -translate-x-1/2 overflow-hidden rounded-xl border border-white/10 bg-[#0C1010]/95 p-1.5 text-xs text-[#F6F1E8] shadow-lg"
              >
                {rest.slice(0, 8).map((person) => (
                  <li key={person.name} className="flex items-center gap-2 rounded-md px-2 py-1">
                    <span className="size-1.5 rounded-full" style={{ backgroundColor: person.status ? statusColor[person.status] : "#5E7271" }} />
                    {person.name}
                  </li>
                ))}
                {rest.length > 8 && <li className="px-2 py-1 text-[#94A9A7]">and {rest.length - 8} more</li>}
              </motion.ul>
            )}
          </AnimatePresence>
        </motion.li>
      )}
    </ul>
  );
}
```
