Avatar
Web/MobileAn image element with a fallback for representing the user.
Installation
pnpm dlx cubix-ui@latest add avatar --base radixUsage
import { Avatar, AvatarFallback, AvatarImage } from "@/components/cubix/avatar"
<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.
Avatar
├── AvatarImage
├── AvatarFallback
└── AvatarBadge
AvatarGroup
├── Avatar
├── Avatar
└── AvatarGroupCountAccessibility
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
| Prop | Type | Default | Description |
|---|---|---|---|
| size | "sm" | "default" | "lg" | "xl" | "2xl" | "default" | The size of the avatar: 24, 32, 40, 48 or 64 px. |
| ring | boolean | false | Draws a 1px border-token ring around the avatar with a 2px gap from the circle. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
AvatarImage
| Prop | Type | Default | Description |
|---|---|---|---|
| src | string | - | Image URL. When it fails to load, the fallback is shown. |
| alt | string | - | Required accessible name for the person in the image. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
AvatarFallback
| Prop | Type | Default | Description |
|---|---|---|---|
| delay | number | 0 | Milliseconds to wait before showing the fallback while the image loads. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
| children | React.ReactNode | - | Usually initials shown when the image is missing. |
AvatarBadge
| Prop | Type | Default | Description |
|---|---|---|---|
| render | React.ReactElement | - | Render the badge as another element, such as a button, for real actions. On Radix, use asChild instead. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
| children | React.ReactNode | - | Optional icon inside the badge. Empty badges are status dots. |
| aria-label | string | - | Name for a status or action when the badge has no text. |
AvatarGroup
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
| children | React.ReactNode | - | Avatar items, optionally followed by AvatarGroupCount. |
| aria-label | string | - | Name for the group. Required when the group is a set of people. |
AvatarGroupCount
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
| children | React.ReactNode | - | Overflow count text such as +3, or an icon. |