Avatars with an initials fallback and a presence dot, stacked into an overlapping group. Avatars past max collapse into a +N bubble whose tooltip and accessible name list who is hidden. On hover or keyboard focus the group fans out with a small stagger. Both components are server components: sizes come from CSS variables instead of React context, and a broken image URL falls back to initials without onError.
Browser Support
Baseline Newly available3 featuresDetails
Tints the background and the initials from the theme colors, so they follow light and dark mode.
Fans the group out when a link or button inside it gets keyboard focus.
Computes the stacking order and the stagger from the position. Elsewhere the same rules read --i and --n, set inline on every item.
Installation
Usage
import { Avatar, AvatarGroup } from "@/components/ui/avatar-group"
export function Team({ people }) {
return (
<AvatarGroup max={5} aria-label="Team">
{people.map((person) => (
<Avatar
key={person.id}
name={person.name}
src={person.photo}
status={person.online ? "online" : undefined}
/>
))}
</AvatarGroup>
)
}Examples
Clickable avatars
onAvatarClick turns every avatar into a button, onOverflowClick does the same for +N. Callbacks are functions, so this only works inside a client component.
Platform squad
12 members
Every avatar is a button here, +N shows the rest.
"use client"
const [selected, setSelected] = useState<string | null>(null)
const [showAll, setShowAll] = useState(false)
<AvatarGroup
max={showAll ? undefined : 5}
onAvatarClick={({ name }) => setSelected(name ?? null)}
onOverflowClick={() => setShowAll(true)}
>
{team.map((person) => (
<Avatar key={person.name} {...person} />
))}
</AvatarGroup>+N as a link
overflowHref makes the bubble a plain link, for example to the members page. Works in a server component and without JavaScript.
<AvatarGroup max={4} overflowHref="/team/members">
{team.map((person) => (
<Avatar key={person.name} name={person.name} src={person.src} />
))}
</AvatarGroup>Sizes and spacing
size is sm, md or lg; spacing tight, normal or loose sets how much the avatars overlap at rest.
<AvatarGroup size="sm" spacing="tight" max={3}>…</AvatarGroup>
<AvatarGroup size="md" spacing="normal" max={3}>…</AvatarGroup>
<AvatarGroup size="lg" spacing="loose" max={3}>…</AvatarGroup>Statuses and fallbacks
The second-to-last avatar has a broken image URL and shows initials. Without a name the avatar shows a generic person icon. The colors come from the name, so a person always gets the same one.
<Avatar size="lg" name="Amara Okafor" src="/team/amara.webp" status="online" />
<Avatar size="lg" name="Noah Fischer" />
<Avatar size="lg" name="Diego Ramírez" src="/missing.jpg" status="online" />
<Avatar size="lg" />Inside a card
The ring around each avatar follows --avatar-ring. On a card, set it to the card color.
Thursday, 14:00 · Room Fjord
<Card className="[--avatar-ring:var(--card)]">
<CardContent>
<AvatarGroup size="sm" max={3} aria-label="Attendees">…</AvatarGroup>
</CardContent>
</Card>Props
AvatarGroup
| Prop | Type | Default | Description |
|---|---|---|---|
| max | number | - | Avatars shown before the +N bubble. All when omitted |
| size | "sm" | "md" | "lg" | "md" | Size of every avatar in the group |
| spacing | "tight" | "normal" | "loose" | "normal" | How much the avatars overlap at rest |
| fanOut | boolean | true | Spread the avatars apart on hover and keyboard focus |
| overflowHref | string | - | Turns +N into a link |
| overflowLabel | (count, names) => string | "N more: …" | Tooltip and accessible name of +N |
| onAvatarClick | ({ index, name }) => void | - | Makes each avatar a button. Client components only |
| onOverflowClick | () => void | - | Makes +N a button. Client components only |
| className | string | - | Additional CSS classes |
Avatar
| Prop | Type | Default | Description |
|---|---|---|---|
| name | string | - | Full name: initials, color and accessible label |
| src | string | - | Image URL. Initials stay visible while it loads and when it fails |
| alt | string | name | Accessible label. Defaults to name |
| size | "sm" | "md" | "lg" | - | Defaults to the group size, otherwise md |
| status | "online" | "away" | "busy" | - | Presence dot in the bottom corner |
| statusLabels | Partial<Record<AvatarStatus, string>> | - | Words for the status in the accessible label |
| className | string | - | Additional CSS classes |
Components
| Component | Description |
|---|---|
| AvatarGroup | Overlapping list (role=list) with the +N bubble |
| Avatar | One round avatar (role=img). Works on its own as well |
Features
- No JavaScript: both components render on the server, the fan-out and the stacking are pure CSS
- Image fallback without onError: the photo is a background layer over the initials: a URL that fails to load paints nothing, so the initials stay
- Accessible: the group is a list, every avatar has a label with its status, +N names the hidden people
- Theme aware: the name colors are mixed with --background and --foreground, so they work in light and dark mode
- Reduced motion: the fan-out happens without a transition