Command Palette

Search for a command to run...

Docs
Avatar

Avatar

An image element with a fallback for representing the user.

CN

Installation

Run the following command:

Update your imports:
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"

Usage

import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
 
export default function Home() {
  return (
    <Avatar>
      <AvatarImage src="https://github.com/shadcn.png" alt="@shadcn" />
      <AvatarFallback>CN</AvatarFallback>
    </Avatar>
  );
}

Props

Avatar

PropTypeDefaultDescription
sizesm | md | lgmdSize of the avatar
variantdefault | rounddefaultStyle variant of avatar

Radix UI Props

Avatar

  • asChild - Change the default rendered element for the one passed as a child, merging their props and behavior.
  • onLoadingStatusChange - Event handler called when the image loading status changes.

AvatarImage

  • asChild - Change the default rendered element for the one passed as a child, merging their props and behavior.
  • onLoadingStatusChange - Event handler called when the image loading status changes.
  • src - The image source to use for the avatar.
  • alt - The alt text to use for the avatar image.

AvatarFallback

  • asChild - Change the default rendered element for the one passed as a child, merging their props and behavior.
  • delayMs - Delay (in ms) before showing the fallback. Useful to prevent flickering where the fallback shows briefly before the image loads.

HTML Attributes

All Avatar components support standard HTML attributes:

Avatar

  • Standard div element attributes.

AvatarImage

  • Standard img element attributes.

AvatarFallback

  • Standard div element attributes.