import {
Avatar,
AvatarBadge,
AvatarFallback,
AvatarGroup,Installation
pnpm slabui add avatar
Usage
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"<Avatar>
<AvatarImage src="https://github.com/slabui.png" />
<AvatarFallback>John Doeh</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
โโโ AvatarGroupCountExamples
Basic
A basic avatar component with an image and a fallback.
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
export function AvatarDemo() {
return (
<Avatar>Badge
Use the AvatarBadge component to add a badge to the avatar. The badge is positioned at the bottom right of the avatar.
import {
Avatar,
AvatarBadge,
AvatarFallback,
AvatarImage,Use the className prop to add custom styles to the badge such as custom colors, sizes, etc.
<Avatar>
<AvatarImage src="https://github.com/slabui.png" alt="@slabui" />
<AvatarFallback>CN</AvatarFallback>
<AvatarBadge className="bg-green-600 dark:bg-green-800" />
</Avatar>Badge with Icon
You can also use an icon inside <AvatarBadge>.
import { PlusIcon } from "lucide-react"
import {
Avatar,
AvatarBadge,Avatar Group
Use the AvatarGroup component to add a group of avatars.
import {
Avatar,
AvatarFallback,
AvatarGroup,
AvatarImage,Avatar Group Count
Use <AvatarGroupCount> to add a count to the group.
import {
Avatar,
AvatarFallback,
AvatarGroup,
AvatarGroupCount,Avatar Group Count
Use <AvatarGroupCount> to add a count to the group.
import { cn } from "@/lib/cn"
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"
const avatars = [Avatar Group Hover
Avatar group with hover effect and tooltips.
import { PlusIcon } from "lucide-react"
import {
Avatar,
AvatarFallback,Sizes
Use the size prop to change the size of the avatar.
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
export function AvatarSizeExample() {
return (
<div className="flex flex-wrap items-center gap-2 grayscale">Dropdown
You can use the Avatar component as a trigger for a dropdown menu.
"use client"
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
import { Button } from "@/components/ui/button"
import {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" |
className | string | - |
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 | - |
For more information about Base UI Avatar props, see the Base UI documentation.