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 URLalt(string): Alternative text for the imageonLoadingStatusChange(function): Callback fired when loading status changesreferrerPolicy(string): Referrer policy for the imagecrossOrigin(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
- Tab Title
- Tab Title