Avatar

Web/Mobile

An image element with a fallback for representing the user.

م

Installation

pnpm dlx cubix-ui@latest add avatar

Usage

Import
import { Avatar, AvatarFallback, AvatarImage } from "@/components/cubix/avatar"
Example
<Avatar>
  <AvatarImage src="/docs/avatar/girl.jpg" alt="مریم" />
  <AvatarFallback>م</AvatarFallback>
</Avatar>

Composition

Always keep AvatarFallback next to AvatarImage so initials stay visible when the photo is missing. AvatarBadge and AvatarGroup are optional.

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

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

Accessibility

Give AvatarImage an alt that names the person. Label status badges with aria-label, compose action badges onto a button with render, and name each AvatarGroup with aria-label.

Examples

Sizes

Use size on the root: sm (24px), default (32px), lg (40px), xl (48px) and 2xl (64px).

ممممم

Fallback

When the image fails to load, the fallback initials stay visible.

نعس

Badge

Use AvatarBadge for a status dot. Override the color with a Cubix token such as bg-chart-2, and give the badge an aria-label.

ممممم

Badge with icon

For real actions, compose AvatarBadge onto a button with render and give it an aria-label.

مممم

Avatar group

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

معن
معن
معن

Group count

Use AvatarGroupCount to show remaining people.

معن
+۳

Group with icon

Pass an icon as the AvatarGroupCount child for an invite or overflow action.

معن

Ring

Add ring to draw a border-token ring around the avatar with a 2px gap.

ممممم

API Reference

Note: Parts render data-slot attributes (avatar, avatar-image, avatar-fallback, avatar-badge, avatar-group, avatar-group-count) for targeting in tests and parent selectors. Always provide AvatarFallback. Use the same props on Base UI, React Aria, and Radix.

Avatar

PropTypeDefaultDescription
size"sm" | "default" | "lg" | "xl" | "2xl""default"The size of the avatar: 24, 32, 40, 48 or 64 px.
ringbooleanfalseDraws a 1px border-token ring around the avatar with a 2px gap from the circle.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

AvatarImage

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

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

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

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

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