Skip to main content
The Avatar component is a composable component that displays user profile images with automatic fallback handling when images fail to load.

Installation

npx shadcn@latest add @eo-n/avatar

Usage

import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
<Avatar>
  <AvatarImage src="https://github.com/aeonzz.png" alt="@aeonz" />
  <AvatarFallback>AE</AvatarFallback>
</Avatar>

Examples

Basic Avatar

<Avatar>
  <AvatarImage src="https://github.com/aeonzz.png" />
  <AvatarFallback>AE</AvatarFallback>
</Avatar>

With Fallback

When the image fails to load, the fallback content is displayed:
<Avatar>
  <AvatarImage src="/invalid-image.png" />
  <AvatarFallback>JD</AvatarFallback>
</Avatar>

Custom Size

<Avatar className="size-12">
  <AvatarImage src="https://github.com/aeonzz.png" />
  <AvatarFallback>AE</AvatarFallback>
</Avatar>

Component API

Avatar

The root container component.
className
string
Additional CSS classes to apply to the avatar container.
...props
React.ComponentProps<typeof AvatarPrimitive.Root>
All props from Base UI Avatar.Root component.

AvatarImage

Displays the avatar image.
src
string
required
The image source URL.
alt
string
Alternative text for the image.
className
string
Additional CSS classes to apply to the image.

AvatarFallback

Displays fallback content when the image fails to load.
children
React.ReactNode
required
The fallback content (usually initials).
className
string
Additional CSS classes to apply to the fallback.

Reference

Built on top of Base UI Avatar.

Build docs developers (and LLMs) love