Avatar

An image element with a fallback for representing the user.

CN

Installation

pnpm dlx cubix@latest add avatar --base aria

Usage

Import
import {
  Avatar,
  AvatarFallback,
  AvatarImage,
} from "@/components/cubix/avatar"
Example
<Avatar>
  <AvatarImage src="/docs/avatar/cn.png" alt="CN" />
  <AvatarFallback>CN</AvatarFallback>
</Avatar>

Composition

Use the following composition to build an Avatar:

 
Avatar
├── AvatarImage
├── AvatarFallback
└── AvatarBadge

Use the following composition to build an Avatar Group:

 
AvatarGroup
├── Avatar
├── Avatar
└── AvatarGroupCount

Examples

Badge

Use AvatarBadge for a status dot. Override the color with className. Give the badge an aria-label so the status is announced.

ER

Badge with icon

For real actions, compose AvatarBadge onto a button with render (Base UI / React Aria) or asChild (Radix), and give it an aria-label.

CN

Avatar Group

Stack avatars with AvatarGroup. Label the group so the set of people is announced.

CNLRER

Group count

Use AvatarGroupCount to show remaining people.

CNLRER
+3

Group with icon

You can also pass an icon as the AvatarGroupCount child.

CNLRER

Sizes

Use the size prop on the root avatar.

CNCNCN

Accessibility

Avatar is presentational. The image, fallback, badge, and group need names so the control stays readable without the photo.

Name the image

Give AvatarImage an alt that names the person. Always keep AvatarFallback so initials remain if the image fails.

 
<Avatar>
  <AvatarImage src="/docs/avatar/cn.png" alt="CN" />
  <AvatarFallback>CN</AvatarFallback>
</Avatar>

Label status badges

An empty badge is only a color. Add aria-label for the status it represents. For clickable actions, compose the badge onto a button with render or asChild so keyboard and focus work.

 
<AvatarBadge aria-label="Online" />
<AvatarBadge
  aria-label="Add teammate"
  render={<button type="button" />}
>
  <PlusIcon />
</AvatarBadge>

Label the group

AvatarGroup renders role="group". Give it an aria-label that describes the set of people.

 
<AvatarGroup aria-label="Team">
  <Avatar>
    <AvatarImage src="/docs/avatar/cn.png" alt="CN" />
    <AvatarFallback>CN</AvatarFallback>
  </Avatar>
</AvatarGroup>

RTL

To enable RTL support, see the Direction guide.

CNER
CNLRER

API Reference

Note: Always provide AvatarFallback so the control stays readable when the image is missing.

Avatar

The root that wraps the image, fallback, and optional badge.

PropTypeDefaultDescription
size"default" | "sm" | "lg""default"The size of the avatar.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

AvatarImage

The photo. Hidden automatically when it fails to load.

PropTypeDefaultDescription
srcstring-Image URL. When it fails to load, the fallback is shown.
altstring-Required accessible name for the person in the image.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

AvatarFallback

Initials or an icon shown while the image loads or after it fails.

PropTypeDefaultDescription
delaynumber0Milliseconds to wait before showing the fallback while the image loads.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
childrenReact.ReactNode-Usually initials shown when the image is missing.

AvatarBadge

A status indicator at the end of the avatar. Compose onto a button when the badge is an action.

PropTypeDefaultDescription
renderReact.ReactElement-Render the badge as another element, such as a button, for real actions. On Radix, use asChild instead.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
childrenReact.ReactNode-Optional icon inside the badge. Empty badges are status dots.
aria-labelstring-Name for a status or action when the badge has no text.

AvatarGroup

Overlapping avatars for a set of people.

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
childrenReact.ReactNode-Avatar items, optionally followed by AvatarGroupCount.
aria-labelstring-Name for the group. Required when the group is a set of people.

AvatarGroupCount

Overflow count or icon after the stacked avatars.

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
childrenReact.ReactNode-Overflow count text such as +3, or an icon.