Avatar

An image element with a fallback for representing the user.

Installation

npx shadcn@latest add avatar

Usage

Import and use the avatar component in your project.

import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"

export default function MyComponent() {
  return (
    <Avatar>
      <AvatarImage src="https://github.com/shadcn.png" alt="@shadcn" />
      <AvatarFallback>CN</AvatarFallback>
    </Avatar>
  )
}

Examples

Default

An avatar with an image and fallback.

CN

Fallback

Avatar fallback is shown when the image fails to load.

JD

Multiple Avatars

Display multiple avatars together.

SCJDAB+3

API Reference

Props available for the Avatar component.

Avatar

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the avatar.

AvatarImage

PropTypeDefaultDescription
src*string-The image source URL.
altstring-Alternative text for the image.
classNamestring-Additional CSS classes to apply.

AvatarFallback

PropTypeDefaultDescription
children*React.ReactNode-Content to display when image fails to load (usually initials).
delayMsnumber-Delay in ms before showing fallback.
classNamestring-Additional CSS classes to apply.

Accessibility

Avatar component follows WAI-ARIA image pattern.

Alternative Text

Always provide meaningful alt text for the AvatarImage component to ensure screen reader users can understand the content.

Fallback Content

Use clear, recognizable fallback content (like initials) that conveys the same information as the image would.