Avatar stack
Overlapping teammate avatars that fan apart on hover with name tooltips, a live presence ring, and a +N chip that opens the full list.
"use client";
import { useState, type CSSProperties } from "react";
import "./avatar-stack.css";
type Person = { name: string; role: string; tone: string; online?: boolean };
const PEOPLE: Person[] = [
{ name: "Maya Chen", role: "Design", tone: "#ff5a1f", online: true },
{ name: "Leo Park", role: "Engineering", tone: "#2b35ff", online: true },
{ name: "Ana Silva", role: "Product", tone: "#0e0e10" },
{ name: "Sam Ortiz", role: "Engineering", tone: "#d7ff3a", online: true },
{ name: "Noor Haddad", role: "Research", tone: "#a8896b" },
{ name: "Kai Müller", role: "Marketing", tone: "#5f7060" },
{ name: "Ivy Laurent", role: "Design", tone: "#c4612f", online: true },
];
const VISIBLE = 4;
const initials = (n: string) =>
n
.split(" ")
.map((p) => p[0])
.join("");
const darkText = (tone: string) =>
["#ff5a1f", "#d7ff3a", "#a8896b"].includes(tone);
/**
* AvatarStack
* - Overlap with negative margins; on hover/focus the margins open up (a CSS transition, so it springs).
* - The +N chip toggles a small list of everyone, with presence dots.
*/
export function AvatarStack({ theme = "light" }: { theme?: "light" | "dark" }) {
const [fanned, setFanned] = useState(false);
const [list, setList] = useState(false);
const extra = PEOPLE.length - VISIBLE;
const online = PEOPLE.filter((p) => p.online).length;
return (
<div className="gu-avs" data-theme={theme}>
<div className="gu-avs__row">
<ul
className="gu-avs__stack"
data-fanned={fanned ? "" : undefined}
onClick={() => setFanned((f) => !f)}
aria-label="People on this file"
>
{PEOPLE.slice(0, VISIBLE).map((p, i) => (
<li
key={p.name}
style={{ "--i": i, "--tone": p.tone } as CSSProperties}
>
<button
type="button"
className="gu-avs__av"
data-dark-text={darkText(p.tone) ? "" : undefined}
aria-label={`${p.name}, ${p.role}${p.online ? ", online" : ""}`}
>
{initials(p.name)}
{p.online && <i aria-hidden="true" />}
</button>
<span className="gu-avs__tip" aria-hidden="true">
{p.name}
</span>
</li>
))}
<li style={{ "--i": VISIBLE } as CSSProperties}>
<button
type="button"
className="gu-avs__more"
aria-expanded={list}
aria-controls="gu-avs-list"
onClick={(e) => {
e.stopPropagation();
setList((l) => !l);
}}
>
+{extra}
<span className="gu-sr"> more people</span>
</button>
</li>
</ul>
<p className="gu-avs__meta">
<b>{online} online</b> · {PEOPLE.length} on this file
</p>
</div>
{list && (
<ul className="gu-avs__list" id="gu-avs-list">
{PEOPLE.map((p) => (
<li key={p.name}>
<span
className="gu-avs__mini"
style={{ "--tone": p.tone } as CSSProperties}
data-dark-text={darkText(p.tone) ? "" : undefined}
aria-hidden="true"
>
{initials(p.name)}
</span>
<span>
<b>{p.name}</b>
<small>{p.role}</small>
</span>
<em data-online={p.online ? "" : undefined}>
{p.online ? "Online" : "Away"}
</em>
</li>
))}
</ul>
)}
</div>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Avatar stack
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
A collaborator avatar stack for a file header: four overlapping initial avatars plus a "+3" chip. Hovering, focusing or tapping fans them apart with a spring and shows name tooltips; green dots mark who is online; +3 opens a list of everyone.
## Layout and look
- 48px circles with a 3px background-colored ring, overlapping by 14px; brand-color backgrounds with Cream initials (Ink initials on orange and lime).
- Online dot: 14px green circle with a ring, bottom-right.
- +N chip: card background with a hairline inner ring; Ink when its list is open.
- Meta: "4 online" in green, "· 7 on this file" muted.
- Tooltips: small Ink pills above each avatar.
- List: 320px card, radius 20px, rows of 52px with a 34px avatar, name, role and "Online/Away".
## Behavior and motion
1. Overlap via margin-left −14px; fanned state margin-left 6px with a springy cubic-bezier(0.34, 1.56, 0.64, 1) over 450ms.
2. Avatars lift 4px and scale 1.06 on hover; tooltips rise 4px and fade.
3. The list slides down 6px when opened.
## Accessibility
- Each avatar is a button labelled "Maya Chen, Design, online"; +N has aria-expanded and "more people" text.
- prefers-reduced-motion: no springs.
## Props
theme. Edit PEOPLE and VISIBLE.
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### AvatarStack.tsx
```tsx
"use client";
import { useState, type CSSProperties } from "react";
import "./avatar-stack.css";
type Person = { name: string; role: string; tone: string; online?: boolean };
const PEOPLE: Person[] = [
{ name: "Maya Chen", role: "Design", tone: "#ff5a1f", online: true },
{ name: "Leo Park", role: "Engineering", tone: "#2b35ff", online: true },
{ name: "Ana Silva", role: "Product", tone: "#0e0e10" },
{ name: "Sam Ortiz", role: "Engineering", tone: "#d7ff3a", online: true },
{ name: "Noor Haddad", role: "Research", tone: "#a8896b" },
{ name: "Kai Müller", role: "Marketing", tone: "#5f7060" },
{ name: "Ivy Laurent", role: "Design", tone: "#c4612f", online: true },
];
const VISIBLE = 4;
const initials = (n: string) =>
n
.split(" ")
.map((p) => p[0])
.join("");
const darkText = (tone: string) =>
["#ff5a1f", "#d7ff3a", "#a8896b"].includes(tone);
/**
* AvatarStack
* - Overlap with negative margins; on hover/focus the margins open up (a CSS transition, so it springs).
* - The +N chip toggles a small list of everyone, with presence dots.
*/
export function AvatarStack({ theme = "light" }: { theme?: "light" | "dark" }) {
const [fanned, setFanned] = useState(false);
const [list, setList] = useState(false);
const extra = PEOPLE.length - VISIBLE;
const online = PEOPLE.filter((p) => p.online).length;
return (
<div className="gu-avs" data-theme={theme}>
<div className="gu-avs__row">
<ul
className="gu-avs__stack"
data-fanned={fanned ? "" : undefined}
onClick={() => setFanned((f) => !f)}
aria-label="People on this file"
>
{PEOPLE.slice(0, VISIBLE).map((p, i) => (
<li
key={p.name}
style={{ "--i": i, "--tone": p.tone } as CSSProperties}
>
<button
type="button"
className="gu-avs__av"
data-dark-text={darkText(p.tone) ? "" : undefined}
aria-label={`${p.name}, ${p.role}${p.online ? ", online" : ""}`}
>
{initials(p.name)}
{p.online && <i aria-hidden="true" />}
</button>
<span className="gu-avs__tip" aria-hidden="true">
{p.name}
</span>
</li>
))}
<li style={{ "--i": VISIBLE } as CSSProperties}>
<button
type="button"
className="gu-avs__more"
aria-expanded={list}
aria-controls="gu-avs-list"
onClick={(e) => {
e.stopPropagation();
setList((l) => !l);
}}
>
+{extra}
<span className="gu-sr"> more people</span>
</button>
</li>
</ul>
<p className="gu-avs__meta">
<b>{online} online</b> · {PEOPLE.length} on this file
</p>
</div>
{list && (
<ul className="gu-avs__list" id="gu-avs-list">
{PEOPLE.map((p) => (
<li key={p.name}>
<span
className="gu-avs__mini"
style={{ "--tone": p.tone } as CSSProperties}
data-dark-text={darkText(p.tone) ? "" : undefined}
aria-hidden="true"
>
{initials(p.name)}
</span>
<span>
<b>{p.name}</b>
<small>{p.role}</small>
</span>
<em data-online={p.online ? "" : undefined}>
{p.online ? "Online" : "Away"}
</em>
</li>
))}
</ul>
)}
</div>
);
}
```
### avatar-stack.css
```css
/* AvatarStack: change these colors to match your brand. */
.gu-avs {
--bg: #f3eee3;
--card: #fbf8f2;
--text: #0e0e10;
--muted: #57534b;
--line: rgb(14 14 16 / 0.1);
--online: #16a34a;
--tip: #0e0e10;
--tip-text: #f3eee3;
--focus: #2b35ff;
--spring: cubic-bezier(0.34, 1.56, 0.64, 1);
display: grid;
justify-items: center;
gap: 14px;
min-height: 360px;
align-content: start;
padding-top: 40px;
color: var(--text);
font-family: system-ui, sans-serif;
}
.gu-avs[data-theme="dark"] {
--bg: #0e0e10;
--card: #18181b;
--text: #f3eee3;
--muted: #aea89c;
--line: rgb(243 238 227 / 0.1);
--online: #4ade80;
--tip: #f3eee3;
--tip-text: #0e0e10;
--focus: #d7ff3a;
}
.gu-avs__row {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
gap: 14px;
}
.gu-avs__stack {
display: flex;
margin: 0;
padding: 0 0 0 14px;
list-style: none;
}
.gu-avs__stack li {
position: relative;
z-index: calc(10 - var(--i));
margin-left: -14px;
transition: margin 0.45s var(--spring);
}
/* Fan out on hover, focus or tap */
.gu-avs__stack:hover li,
.gu-avs__stack:focus-within li,
.gu-avs__stack[data-fanned] li {
margin-left: 6px;
}
.gu-avs button {
font: inherit;
cursor: pointer;
}
.gu-avs button:focus-visible {
outline: 3px solid var(--focus);
outline-offset: 2px;
}
.gu-avs__av,
.gu-avs__more {
position: relative;
display: grid;
place-items: center;
width: 48px;
height: 48px;
padding: 0;
border: 3px solid var(--bg);
border-radius: 50%;
font-size: 0.85rem !important;
font-weight: 900 !important;
transition: transform 0.3s var(--spring);
}
.gu-avs__av {
background: var(--tone);
color: #f3eee3;
}
.gu-avs[data-theme="dark"] .gu-avs__av[style*="0e0e10"],
.gu-avs[data-theme="dark"] li[style*="0e0e10"] .gu-avs__av {
background: #f3eee3;
color: #0e0e10;
}
[data-dark-text] {
color: #0e0e10 !important;
}
.gu-avs__av:hover {
transform: translateY(-4px) scale(1.06);
}
/* Presence ring dot */
.gu-avs__av i {
position: absolute;
right: -2px;
bottom: -2px;
width: 14px;
height: 14px;
border: 3px solid var(--bg);
border-radius: 50%;
background: var(--online);
}
.gu-avs__more {
background: var(--card);
color: var(--text);
box-shadow: inset 0 0 0 1.5px var(--line);
}
.gu-avs__more[aria-expanded="true"] {
background: var(--text);
color: var(--bg);
}
.gu-avs__tip {
position: absolute;
bottom: calc(100% + 10px);
left: 50%;
padding: 5px 10px;
border-radius: 8px;
background: var(--tip);
color: var(--tip-text);
font-size: 0.75rem;
font-weight: 700;
white-space: nowrap;
opacity: 0;
translate: -50% 4px;
pointer-events: none;
transition:
opacity 0.2s,
translate 0.3s var(--spring);
}
.gu-avs__stack li:hover .gu-avs__tip,
.gu-avs__stack li:focus-within .gu-avs__tip {
opacity: 1;
translate: -50% 0;
}
.gu-avs__meta {
margin: 0;
color: var(--muted);
font-size: 0.88rem;
}
.gu-avs__meta b {
color: var(--online);
}
.gu-avs__list {
width: min(100%, 320px);
margin: 0;
padding: 6px;
border: 1px solid var(--line);
border-radius: 20px;
background: var(--card);
list-style: none;
box-shadow: 0 20px 40px -20px rgb(0 0 0 / 0.3);
animation: gu-avs-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes gu-avs-in {
from {
opacity: 0;
transform: translateY(-6px);
}
}
.gu-avs__list li {
display: grid;
grid-template-columns: 34px 1fr auto;
align-items: center;
gap: 10px;
min-height: 52px;
padding: 0 10px;
border-radius: 12px;
}
.gu-avs__list li > span:nth-child(2) {
display: grid;
}
.gu-avs__list small {
color: var(--muted);
}
.gu-avs__mini {
display: grid;
place-items: center;
width: 34px;
height: 34px;
border-radius: 50%;
background: var(--tone);
color: #f3eee3;
font-size: 0.72rem;
font-weight: 900;
}
.gu-avs__list em {
color: var(--muted);
font-size: 0.78rem;
font-style: normal;
font-weight: 700;
}
.gu-avs__list em[data-online] {
color: var(--online);
}
.gu-sr {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
}
@media (prefers-reduced-motion: reduce) {
.gu-avs__stack li,
.gu-avs__av,
.gu-avs__tip {
transition: none;
}
.gu-avs__list {
animation: none;
}
}
```
You might also want
Next piece: Before and after sliderSmart tooltips
Components, intermediate
3D tilt card
Components, intermediate
Activity heatmap
Components, intermediate