Avatar
visual representation of a user with image and fallback support
Installation
pnpm dlx shadcn@latest add https://prototyper-ui.com/r/avatar.jsonnpx shadcn@latest add https://prototyper-ui.com/r/avatar.jsonyarn dlx shadcn@latest add https://prototyper-ui.com/r/avatar.jsonbunx --bun shadcn@latest add https://prototyper-ui.com/r/avatar.jsonThis will add the following files to your project:
components/ui/avatar.tsx
Usage
import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar"
<Avatar>
<AvatarImage src="/avatar.png" alt="User" />
<AvatarFallback>AB</AvatarFallback>
</Avatar>Examples
Fallback
Styling
Data Slots
Use data-slot attributes to target specific parts of the avatar:
| Slot name | Element |
|---|---|
avatar | Root container |
avatar-image | The <img> element |
avatar-fallback | Fallback content (initials or icon) |
avatar-badge | Status badge indicator |
avatar-group | Group wrapper for multiple avatars |
avatar-group-count | Overflow count element in a group |
Customization Examples
/* Make all avatars larger */
[data-slot="avatar"] {
@apply size-12 rounded-lg after:rounded-lg;
}
/* Custom fallback color */
[data-slot="avatar-fallback"] {
@apply bg-primary text-primary-foreground;
}{/* Override styles via className */}
<Avatar className="size-12 rounded-lg after:rounded-lg">
<AvatarImage src="/avatar.png" alt="User" />
<AvatarFallback className="rounded-lg">AB</AvatarFallback>
</Avatar>API Reference
Avatar
Root component that wraps the avatar image and fallback. Supports three sizes via the size prop.
Prop
Type
All Base UI Avatar.Root props are forwarded via ...props.
AvatarImage
Displays the user's image. Automatically hidden when the image fails to load.
Prop
Type
All Base UI Avatar.Image props are forwarded via ...props.
AvatarFallback
Displayed when no image is provided or while the image is loading. Typically renders initials or an icon.
Prop
Type
All Base UI Avatar.Fallback props are forwarded via ...props.
AvatarBadge
A small status indicator positioned at the bottom-right corner of the avatar. Size adapts to the parent avatar's size.
Prop
Type
All standard span props are forwarded via ...props.
AvatarGroup
Wraps multiple avatars in an overlapping horizontal stack.
Prop
Type
All standard div props are forwarded via ...props.
AvatarGroupCount
Displays the count of remaining avatars that are not shown in the group.
Prop
Type
All standard div props are forwarded via ...props.
Accessibility
ARIA Attributes
- The
AvatarImagerenders a standard<img>element. Always provide a descriptivealtattribute for screen readers. - When no image is available,
AvatarFallbackcontent (initials or icon) serves as the visual representation. Ensure the fallback is meaningful. AvatarBadgeis decorative by default. Addaria-labelif the badge conveys important status information.AvatarGroupuses standarddivsemantics. Consider addingrole="group"andaria-labelfor groups of avatars.