Avatar group
Overlapping row of avatars that collapses extra people into a "+N" chip after a chosen limit.
pnpm dlx shadcn@latest add @haze/avatar-group---
import { cn } from "../../../lib/haze/utils";
import Avatar from "./avatar.astro";
interface Props {
/** People in order. src is an optional photo URL. */
people: { name: string; src?: string }[];
/** Most avatars to show before the "+N" chip. */
max?: number;
size?: "sm" | "md" | "lg";
/** Accessible name of the group. Defaults to the member count. */
label?: string;
/** Screen-reader word after the overflow count, so "+4" is read as "4 more". Translate it for other languages. */
moreLabel?: string;
class?: string;
}
const { people, max = 4, size = "md", label, moreLabel = "more", class: className } = Astro.props;
const limit = Math.max(Math.floor(max), 0);
const shown = people.slice(0, limit);
const extra = people.length - shown.length;
const groupLabel = label ?? `${people.length} ${people.length === 1 ? "member" : "members"}`;
const chipSizes = { sm: "size-6 text-[0.625rem]/4", md: "size-8 text-xs/4", lg: "size-10 text-sm/5" };
// Overlap scales with size; the 2 px background ring separates neighbours without touching the initials.
const overlaps = { sm: "-space-x-1", md: "-space-x-1.5", lg: "-space-x-2" };
---
<div role="group" aria-label={groupLabel} class={cn("flex", overlaps[size], className)}>
{
shown.map((person) => (
<Avatar
name={person.name}
src={person.src}
size={size}
class="ring-2 ring-background"
/>
))
}
{
extra > 0 && (
<span
role="img"
aria-label={`${extra} ${moreLabel}`}
class={cn(
"relative inline-flex shrink-0 items-center justify-center rounded-full bg-muted font-medium text-foreground tabular-nums inset-ring inset-ring-frame ring-2 ring-background",
chipSizes[size],
)}
>
+{extra}
</span>
)
}
</div>When to use
- Showing who is on a project, a document or a meeting in a small space
- Teams of unknown size, where only the first few faces fit
- Cards and table rows that need a compact member list
When not to use
- Readers need every name in view; list the people instead
- A single person; use avatar
Installation
Add the Haze registry to components.json once, then install Avatar group with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/avatar-groupnpx shadcn@latest add @haze/avatar-groupyarn dlx shadcn@latest add @haze/avatar-groupbunx --bun shadcn@latest add @haze/avatar-groupFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| people* | { name: string; src?: string }[] | – | People in order; each avatar shows the initials of its name, or the photo when src is set. |
| max | number | 4 | Avatars shown before the overflow chip. |
| size | "sm" | "md" | "lg" | "md" | Passed to every avatar and to the chip. |
| label | string | – | Accessible name of the group; defaults to a member count such as "5 members". |
| moreLabel | string | "more" | Screen-reader word after the overflow count, so "+4" is read as "4 more". Translate it for other languages. |
| class | string | – | Extra classes on the group. |
Accessibility
- The group has role="group" and a label with the full count, so the total is known even when the chip hides most names.
- Each avatar is announced by its full name and the chip as "3 more" (or the moreLabel you pass); the initials alone are never the only text.
- The ring in the page background keeps overlapping avatars distinct without relying on their fill colors.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI component "Avatar group" with `npx shadcn@latest add @haze/avatar-group`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import AvatarGroup from "@/components/haze/ui/avatar-group.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/avatar-group.md
Customize with real content
Adapt the Haze avatar-group ui for our product. Replace the demo values of these props with our real content: people, max, size, label, moreLabel, class. Keep the layout, the heading level rules and these accessibility details: The group has role="group" and a label with the full count, so the total is known even when the chip hides most names. Each avatar is announced by its full name and the chip as "3 more" (or the moreLabel you pass); the initials alone are never the only text. The ring in the page background keeps overlapping avatars distinct without relying on their fill colors. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using avatar-group, check it fits: use it when showing who is on a project, a document or a meeting in a small space; teams of unknown size, where only the first few faces fit; cards and table rows that need a compact member list. Avoid it when readers need every name in view; list the people instead; a single person; use avatar. Alternatives: @haze/avatar, @haze/tag, @haze/item.
Dependencies
- @haze/avatar
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.