Installation
Section titled “Installation”pnpm dlx shadcn@latest add pxl-ui/registry/avatar
Install the following dependencies:
pnpm add @base-ui/react
Copy and paste the following code into your project.
Update the import paths to match your project setup.
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/pxl/avatar"<Avatar> <AvatarImage src="https://github.com/shadcn.png" /> <AvatarFallback>CN</AvatarFallback></Avatar>Composition
Section titled “Composition”Use the following composition to build an Avatar:
Avatar├── AvatarImage├── AvatarFallback└── AvatarBadgeUse the following composition to build an AvatarGroup:
AvatarGroup├── Avatar│ ├── AvatarImage│ ├── AvatarFallback│ └── AvatarBadge├── Avatar│ ├── AvatarImage│ ├── AvatarFallback│ └── AvatarBadge└── AvatarGroupCountUse the AvatarBadge component to add a badge to the avatar. The badge is positioned at the bottom right of the avatar.
Use the className prop to add custom styles to the badge such as custom colors, sizes, etc.
<Avatar> <AvatarImage src="https://github.com/shadcn.png" alt="@shadcn" /> <AvatarFallback>CN</AvatarFallback> <AvatarBadge className="bg-success-foreground" /></Avatar>Badge with Icon
Section titled “Badge with Icon”You can also use an icon inside <AvatarBadge>.
Avatar Group
Section titled “Avatar Group”Use the AvatarGroup component to add a group of avatars.
Avatar Group Count
Section titled “Avatar Group Count”Use <AvatarGroupCount> to add a count to the group.
Avatar Group with Icon
Section titled “Avatar Group with Icon”You can also use an icon inside <AvatarGroupCount>.
Use the size prop to change the size of the avatar.
API Reference
Section titled “API Reference”Avatar
Section titled “Avatar”The Avatar component is the root component that wraps the avatar image and fallback.
| Prop | Type | Default |
|---|---|---|
size |
"default" | "sm" | "lg" |
"default" |
className |
string |
- |
AvatarImage
Section titled “AvatarImage”The AvatarImage component displays the avatar image. It accepts all Base UI Avatar Image props.
| Prop | Type | Default |
|---|---|---|
src |
string |
- |
alt |
string |
- |
className |
string |
- |
AvatarFallback
Section titled “AvatarFallback”The AvatarFallback component displays a fallback when the image fails to load. It accepts all Base UI Avatar Fallback props.
| Prop | Type | Default |
|---|---|---|
className |
string |
- |
AvatarBadge
Section titled “AvatarBadge”The AvatarBadge component displays a badge indicator on the avatar, typically positioned at the bottom right.
| Prop | Type | Default |
|---|---|---|
className |
string |
- |
AvatarGroup
Section titled “AvatarGroup”The AvatarGroup component displays a group of avatars with overlapping styling.
| Prop | Type | Default |
|---|---|---|
className |
string |
- |
AvatarGroupCount
Section titled “AvatarGroupCount”The AvatarGroupCount component displays a count indicator in an avatar group, typically showing the number of additional avatars.
| Prop | Type | Default |
|---|---|---|
className |
string |
- |
For more information about Base UI Avatar props, see the Base UI documentation.