A seamless infinite scroller for logos and testimonials that pauses on hover.
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.
Customize
Usage
import { AvatarStack } from "@/components/motionkit/avatar-stack";
<AvatarStack
people={[
{ name: "Amara Okafor", src: "/team/amara.jpg", status: "online" },
{ name: "Leo Hart", status: "online" },
{ name: "Priya Nair", status: "away" },
// ...
]}
/>Motion
The exact curves this component runs, plotted with Motion's own maths.
Faces fan out
Hover or focus
Name appears
Hover or focus a face
Team and collaborator lists, "who's viewing" indicators, shared documents and boards, social proof and community sections.
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.
Works in the App Router as is. Requires Tailwind CSS v4.
One command adds the file and installs its dependencies. Needs a components.json (run npx shadcn@latest init once if you don't have one).
npx shadcn@latest add https://www.motionkitui.com/r/avatar-stack.jsonnpm install motionSave as components/motionkit/avatar-stack.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>
);
}
| 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. |
How we audit: the WCAG 2.2 animation checklist and respecting reduced motion in React.
Yes. The file starts with "use client", so you can import it straight into a Server Component page or layout. It works in Vite as is, and in Astro as a React island.
Only the motion package, beside React and Tailwind CSS v4. There is no MotionKit package and no Tailwind config to add.
Yes. Run npx shadcn@latest add https://www.motionkitui.com/r/avatar-stack.json in any project with a components.json. It saves the file to components/motionkit and installs its dependencies.
With reduced motion on, the stack spreads and names appear without springing.
A seamless infinite scroller for logos and testimonials that pauses on hover.
FAQ panels that open with a smooth, springy height and a turning chevron.
Drag a handle across two layers to compare before and after, smoothly sprung.