Skip to main content

avatar

An image element with a fallback for representing the user.

Philosophy

Identity in UI starts with a face. Avatars humanize interfaces by giving users a visual anchor. We support both single avatars and groups because social context - seeing who else is involved - is a fundamental interaction pattern. The fallback-to-initials behavior ensures graceful degradation when images fail.

Installation


npx @gentleduck/cli add avatar

npx @gentleduck/cli add avatar

Usage

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

RTL Support

Motion

Use MotionAvatar and MotionAvatarGroup for animated entrance powered by motion. Avatars spin in with scale, rotate, and blur. The group staggers each avatar 80ms apart.

API Reference

Avatar

The root container rendered as a span. Provides context for AvatarImage and AvatarFallback.

PropTypeDefaultDescription
classNamestring-Additional class names for styling the avatar container
...propsReact.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root>-Additional props inherited from the avatar primitive root (span element)

AvatarImage

The img element inside the avatar. Automatically tracks loading status and hides when the image fails.

PropTypeDefaultDescription
srcstring-Image source URL
altstring-Alternate text for the image
onLoadingStatusChange(status: 'idle' | 'loading' | 'loaded' | 'error') => void-Callback when the image loading status changes
classNamestring-Additional class names for styling the image
...propsReact.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>-Additional props inherited from the avatar image primitive

AvatarFallback

Content displayed when the image has not loaded. Typically initials or an icon.

PropTypeDefaultDescription
delayMsnumber-Optional delay in milliseconds before showing the fallback (avoids flicker for fast-loading images)
classNamestring-Additional class names for styling the fallback
childrenReact.ReactNode-Fallback content (e.g. initials)
...propsReact.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>-Additional props inherited from the avatar fallback primitive

AvatarGroup

PropTypeDefaultDescription
imgs{ src?: string; alt?: string; fallback?: string; id?: string }[](required)Array of avatar data objects. Fallback text is truncated to 2 characters.
maxVisiblenumber3Maximum number of avatars to display before showing a +N overflow counter
classNamestring-Additional class names for styling the avatar group container
...propsReact.HTMLAttributes<HTMLDivElement>-Additional props to spread to the container div

MotionAvatar

Content spins in on mount with rotate, scale, and blur using the spinIn preset. Requires the motion package.

PropTypeDefaultDescription
...propsAvatarProps-All props from Avatar are supported

MotionAvatarGroup

Each avatar staggers in 80ms apart with spinIn animation. The overflow counter staggers last. Requires the motion package.

PropTypeDefaultDescription
...propsAvatarGroupProps-All props from AvatarGroup are supported