0

Avatar

An image element with a fallback for representing the user.

CNER
CNLRER
+3
import {
  Avatar,
  AvatarBadge,

Installation

bunx --bun shadcn@latest add @ondo-ui/avatar

Usage

import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
<Avatar>
  <AvatarImage src="https://github.com/shadcn.png" />
  <AvatarFallback>CN</AvatarFallback>
</Avatar>

Composition

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

Examples

Basic

A basic avatar component with an image and a fallback.

CN
import {
  Avatar,
  AvatarFallback,

Badge

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

CN
import {
  Avatar,
  AvatarBadge as AvatarBadgeComponent,

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-green-600 dark:bg-green-800" />
</Avatar>

Badge with Icon

You can also use an icon inside <AvatarBadge>.

PP
import { IconPlus } from "@tabler/icons-react"

import {

Avatar Group

Use the AvatarGroup component to add a group of avatars.

CNLRER
import {
  Avatar,
  AvatarFallback,

Avatar Group Count

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

CNLRER
+3
import {
  Avatar,
  AvatarFallback,

Avatar Group with Icon

You can also use an icon inside <AvatarGroupCount>.

CNLRER
import { IconPlus } from "@tabler/icons-react"

import {

Sizes

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

CNCNCN
import {
  Avatar,
  AvatarFallback,

You can use the Avatar component as a trigger for a dropdown menu.

"use client"

import {

API reference

The component wraps Base UI Avatar and accepts all of its props.