An image element with a fallback for representing the user.
Installation#
bunx --bun fabricator-ui@latest add avatar
Usage#
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"<Avatar>
<AvatarImage src="https://github.com/gabrielespinheira.png" />
<AvatarFallback>CN</AvatarFallback>
</Avatar>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
└── AvatarGroupCountBasic#
A basic avatar component with an image and a fallback.
Badge#
Use 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/gabrielespinheira.png"
alt="@gabrielespinheira"
/>
<AvatarFallback>CN</AvatarFallback>
<AvatarBadge className="bg-green-600 dark:bg-green-800" />
</Avatar>Badge with Icon#
You can also use an icon inside <AvatarBadge>.
Avatar Group#
Use the AvatarGroup component to add a group of avatars.
Avatar Group Count#
Use <AvatarGroupCount> to add a count to the group.
Avatar Group with Icon#
You can also use an icon inside <AvatarGroupCount>.
Avatar Group with Tooltips#
Pass tooltip to name each person on hover and keyboard focus. The group parts around the avatar the pointer enters: it lifts and comes forward while its neighbours slide aside on a spring, and stays parted until the pointer leaves the group. In a group the names show in one label, the tooltip's chip, which appears after a short beat and glides with the parting from avatar to avatar.
<AvatarGroup>
<Avatar tooltip="Gabriel Espinheira">
<AvatarImage src="https://github.com/gabrielespinheira.png" alt="" />
<AvatarFallback>GE</AvatarFallback>
</Avatar>
<AvatarGroupCount>+3</AvatarGroupCount>
</AvatarGroup>Sizes#
Use the size prop to change the size of the avatar.
Dropdown#
You can use the Avatar component as a trigger for a dropdown menu.
API Reference#
Avatar#
The Avatar component is the root component that wraps the avatar image and fallback.
| Prop | Type | Default |
|---|---|---|
size | "default" | "sm" | "lg" | "default" |
tooltip | string | TooltipContentProps | - |
className | string | - |
A string is the tooltip's text; an object is passed to the tooltip's content, for its side, className or richer children. An avatar with a tooltip takes focus and becomes an image named by a string tooltip; pass aria-label when its content isn't a string. In an AvatarGroup only its children are used, as the name in the group's label.
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#
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#
The AvatarBadge component displays a badge indicator on the avatar, typically positioned at the bottom right.
| Prop | Type | Default |
|---|---|---|
className | string | - |
AvatarGroup#
The AvatarGroup component displays a group of avatars with overlapping styling.
| Prop | Type | Default |
|---|---|---|
className | string | - |
AvatarGroupCount#
The AvatarGroupCount component displays a count indicator in an avatar group, typically showing the number of additional avatars.
| Prop | Type | Default |
|---|---|---|
className | string | - |
Accessibility#
- An avatar's image takes its
alt; with an image that fails, the fallback's initials show instead. - With a
tooltip, the avatar is in the tab order withrole="img", named by the tooltip's text, which also shows on focus. - The group parts for a mouse and for keyboard focus, never for touch, and reduced motion keeps the avatar coming forward without the moves.
- A group's name label is hidden from assistive tech: each avatar is already named by its
tooltip.
For more information about Base UI Avatar props, see the Base UI documentation.