Skip to main content

Avatar

The Avatar component displays a user’s profile picture, initials, or fallback icon. It automatically handles image loading states and provides a fallback when the image fails to load or is unavailable.

Import

Anatomy

The Avatar component consists of three parts:
  • <Avatar.Root> - The container element
  • <Avatar.Image> - The profile image
  • <Avatar.Fallback> - Content shown when the image is unavailable

Basic Usage

Key Features

  • Automatic fallback: Shows fallback content when the image fails to load
  • Loading states: Tracks image loading status (idle, loading, loaded, error)
  • Delayed fallback: Optionally delay the fallback display
  • Accessible: Proper image alt text support
  • Unstyled: Full control over styling

Component Props

Root

The root container element that manages the avatar state. Props:
  • Renders a <span> element
  • Accepts all standard HTML span attributes

Image

The image element to display in the avatar. Props:
  • src (string): The image source URL
  • alt (string): Alternative text for the image
  • onLoadingStatusChange (function): Callback fired when loading status changes
  • referrerPolicy (string): Referrer policy for the image
  • crossOrigin (string): CORS settings for the image
  • Renders an <img> element

Fallback

Content displayed when the image is unavailable or fails to load. Props:
  • delay (number): How long to wait before showing the fallback, in milliseconds
  • Renders a <span> element

Styling

Common Patterns

With Delayed Fallback

Delay showing the fallback to avoid flashing content during quick loads:

Different Sizes

With Status Indicator

Tracking Loading Status