GooseUI

Components

Avatar Group

New

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 available
3 features
Details
color-mix()

Tints the background and the initials from the theme colors, so they follow light and dark mode.

Your browser:
:focus-within

Fans the group out when a link or button inside it gets keyboard focus.

Your browser:
sibling-count() and sibling-index()

Computes the stacking order and the stagger from the position. Elsewhere the same rules read --i and --n, set inline on every item.

Your browser:

Preview

Hover the group or tab into it to fan it out.

Installation

npx shadcn@latest add @gooseui/avatar-group
pnpm dlx shadcn@latest add @gooseui/avatar-group
yarn dlx shadcn@latest add @gooseui/avatar-group
bunx --bun shadcn@latest add @gooseui/avatar-group

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.

tightnormalloosesm
+3
+3
+3
md
+3
+3
+3
lg
+3
+3
+3
<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.

Q1 roadmap review

Thursday, 14:00 · Room Fjord

+3
6 attending
<Card className="[--avatar-ring:var(--card)]">
  <CardContent>
    <AvatarGroup size="sm" max={3} aria-label="Attendees">…</AvatarGroup>
  </CardContent>
</Card>

Props

AvatarGroup

PropTypeDefaultDescription
maxnumber-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
fanOutbooleantrueSpread the avatars apart on hover and keyboard focus
overflowHrefstring-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
classNamestring-Additional CSS classes

Avatar

PropTypeDefaultDescription
namestring-Full name: initials, color and accessible label
srcstring-Image URL. Initials stay visible while it loads and when it fails
altstringnameAccessible 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
statusLabelsPartial<Record<AvatarStatus, string>>-Words for the status in the accessible label
classNamestring-Additional CSS classes

Components

ComponentDescription
AvatarGroupOverlapping list (role=list) with the +N bubble
AvatarOne 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