Skip to content
GitHub

Avatar

An image element with a fallback for representing the user.

HRPR
CNPRWZ
+3
import {
Avatar,
AvatarBadge,
AvatarFallback,
AvatarGroup,
AvatarGroupCount,
AvatarImage,
} from "@/components/ui/pxl/avatar";
export default function AvatarDemo() {
return (
<div className="flex flex-row flex-wrap items-center gap-6 md:gap-12">
<Avatar>
<AvatarImage
src="https://raw.githubusercontent.com/pxl-ui/registry/main/app/public/portraits/hero.png"
alt="@hero"
className="grayscale group-hover/avatar:bg-primary group-hover/avatar:grayscale-0"
/>
<AvatarFallback>HR</AvatarFallback>
</Avatar>
<Avatar>
<AvatarImage
src="https://raw.githubusercontent.com/pxl-ui/registry/main/app/public/portraits/princess.png"
alt="@princess"
className="bg-success"
/>
<AvatarFallback>PR</AvatarFallback>
<AvatarBadge className="bg-success-foreground" />
</Avatar>
<AvatarGroup className="grayscale hover:grayscale-0">
<Avatar>
<AvatarImage
src="https://raw.githubusercontent.com/pxl-ui/registry/main/app/public/portraits/hero.png"
alt="@hero"
className="bg-primary"
/>
<AvatarFallback>CN</AvatarFallback>
</Avatar>
<Avatar>
<AvatarImage
src="https://raw.githubusercontent.com/pxl-ui/registry/main/app/public/portraits/princess.png"
alt="@princess"
className="bg-success"
/>
<AvatarFallback>PR</AvatarFallback>
</Avatar>
<Avatar>
<AvatarImage
src="https://raw.githubusercontent.com/pxl-ui/registry/main/app/public/portraits/wizard.png"
alt="@wizard"
className="bg-warning"
/>
<AvatarFallback>WZ</AvatarFallback>
</Avatar>
<AvatarGroupCount>+3</AvatarGroupCount>
</AvatarGroup>
</div>
)
}
pnpm dlx shadcn@latest add pxl-ui/registry/avatar
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/pxl/avatar"
<Avatar>
<AvatarImage src="https://github.com/shadcn.png" />
<AvatarFallback>CN</AvatarFallback>
</Avatar>

Use the following composition to build an Avatar:

Avatar
├── AvatarImage
├── AvatarFallback
└── AvatarBadge

Use the following composition to build an AvatarGroup:

AvatarGroup
├── Avatar
│ ├── AvatarImage
│ ├── AvatarFallback
│ └── AvatarBadge
├── Avatar
│ ├── AvatarImage
│ ├── AvatarFallback
│ └── AvatarBadge
└── AvatarGroupCount

Use the AvatarBadge component to add a badge to the avatar. The badge is positioned at the bottom right of the avatar.

HR
import {
Avatar,
AvatarBadge,
AvatarFallback,
AvatarImage,
} from "@/components/ui/pxl/avatar"
export default function AvatarWithBadge() {
return (
<Avatar>
<AvatarImage
src="https://raw.githubusercontent.com/pxl-ui/registry/main/app/public/portraits/hero.png"
alt="@hero" />
<AvatarFallback>HR</AvatarFallback>
<AvatarBadge className="bg-success-foreground" />
</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>

You can also use an icon inside <AvatarBadge>.

HR
import {
Avatar,
AvatarBadge,
AvatarFallback,
AvatarImage,
} from "@/components/ui/pxl/avatar"
export default function AvatarWithBadge() {
return (
<Avatar>
<AvatarImage
src="https://raw.githubusercontent.com/pxl-ui/registry/main/app/public/portraits/hero.png"
alt="@hero" />
<AvatarFallback>HR</AvatarFallback>
<AvatarBadge>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="currentColor"
viewBox="0 0 24 24"
>
<path d="M13 11h7v2h-7v7h-2v-7H4v-2h7V4h2v7Z" />
</svg>
</AvatarBadge>
</Avatar>
)
}

Use the AvatarGroup component to add a group of avatars.

HRPRWZ
import {
Avatar,
AvatarFallback,
AvatarGroup,
AvatarImage
} from "@/components/ui/pxl/avatar";
export default function AvatarGroupExample() {
return (
<AvatarGroup className="grayscale">
<Avatar>
<AvatarImage
src="https://raw.githubusercontent.com/pxl-ui/registry/main/app/public/portraits/hero.png"
alt="@hero"
/>
<AvatarFallback>HR</AvatarFallback>
</Avatar>
<Avatar>
<AvatarImage
src="https://raw.githubusercontent.com/pxl-ui/registry/main/app/public/portraits/princess.png"
alt="@princess"
/>
<AvatarFallback>PR</AvatarFallback>
</Avatar>
<Avatar>
<AvatarImage
src="https://raw.githubusercontent.com/pxl-ui/registry/main/app/public/portraits/wizard.png"
alt="@wizard"
/>
<AvatarFallback>WZ</AvatarFallback>
</Avatar>
</AvatarGroup>
);
}

Use <AvatarGroupCount> to add a count to the group.

HRPRWZ
+3
import {
Avatar,
AvatarFallback,
AvatarGroup,
AvatarGroupCount,
AvatarImage,
} from "@/components/ui/pxl/avatar";
export default function AvatarGroupCountExample() {
return (
<AvatarGroup className="grayscale">
<Avatar>
<AvatarImage
src="https://raw.githubusercontent.com/pxl-ui/registry/main/app/public/portraits/hero.png"
alt="@hero"
/>
<AvatarFallback>HR</AvatarFallback>
</Avatar>
<Avatar>
<AvatarImage
src="https://raw.githubusercontent.com/pxl-ui/registry/main/app/public/portraits/princess.png"
alt="@princess"
/>
<AvatarFallback>PR</AvatarFallback>
</Avatar>
<Avatar>
<AvatarImage
src="https://raw.githubusercontent.com/pxl-ui/registry/main/app/public/portraits/wizard.png"
alt="@wizard"
/>
<AvatarFallback>WZ</AvatarFallback>
</Avatar>
<AvatarGroupCount>+3</AvatarGroupCount>
</AvatarGroup>
);
}

You can also use an icon inside <AvatarGroupCount>.

HRPRWZ
import {
Avatar,
AvatarFallback,
AvatarGroup,
AvatarGroupCount,
AvatarImage,
} from "@/components/ui/pxl/avatar";
export default function AvatarGroupCountIconExample() {
return (
<AvatarGroup className="grayscale">
<Avatar>
<AvatarImage
src="https://raw.githubusercontent.com/pxl-ui/registry/main/app/public/portraits/hero.png"
alt="@hero"
/>
<AvatarFallback>HR</AvatarFallback>
</Avatar>
<Avatar>
<AvatarImage
src="https://raw.githubusercontent.com/pxl-ui/registry/main/app/public/portraits/princess.png"
alt="@princess"
/>
<AvatarFallback>PR</AvatarFallback>
</Avatar>
<Avatar>
<AvatarImage
src="https://raw.githubusercontent.com/pxl-ui/registry/main/app/public/portraits/wizard.png"
alt="@wizard"
/>
<AvatarFallback>WZ</AvatarFallback>
</Avatar>
<AvatarGroupCount>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="currentColor"
viewBox="0 0 24 24"
>
<path d="M13 11h7v2h-7v7h-2v-7H4v-2h7V4h2v7Z" />
</svg>
</AvatarGroupCount>
</AvatarGroup>
);
}

Use the size prop to change the size of the avatar.

IHSIHSIHSIHS
import {
Avatar,
AvatarFallback,
AvatarImage,
} from "@/components/ui/pxl/avatar";
export default function SizesExample() {
return (
<div className="flex flex-wrap items-center gap-2 grayscale">
<Avatar size="sm">
<AvatarImage
alt="@hero"
className="bg-primary"
src="https://raw.githubusercontent.com/pxl-ui/registry/main/app/public/portraits/hero.png"
/>
<AvatarFallback>IHS</AvatarFallback>
</Avatar>
<Avatar size="md">
<AvatarImage
alt="@hero"
className="bg-primary"
src="https://raw.githubusercontent.com/pxl-ui/registry/main/app/public/portraits/hero.png"
/>
<AvatarFallback>IHS</AvatarFallback>
</Avatar>
<Avatar size="lg">
<AvatarImage
alt="@hero"
className="bg-primary"
src="https://raw.githubusercontent.com/pxl-ui/registry/main/app/public/portraits/hero.png"
/>
<AvatarFallback>IHS</AvatarFallback>
</Avatar>
<Avatar size="xl">
<AvatarImage
alt="@hero"
className="bg-primary"
src="https://raw.githubusercontent.com/pxl-ui/registry/main/app/public/portraits/hero.png"
/>
<AvatarFallback>IHS</AvatarFallback>
</Avatar>
</div>
);
}

The Avatar component is the root component that wraps the avatar image and fallback.

Prop Type Default
size "default" | "sm" | "lg" "default"
className string -

The AvatarImage component displays the avatar image. It accepts all Base UI Avatar Image props.

Prop Type Default
src string -
alt string -
className string -

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 -

The AvatarBadge component displays a badge indicator on the avatar, typically positioned at the bottom right.

Prop Type Default
className string -

The AvatarGroup component displays a group of avatars with overlapping styling.

Prop Type Default
className string -

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.