Skip to main content

Overview

Avatar is an image element with a fallback for representing a user or entity. It automatically handles loading states and can show initials or an icon when an image is unavailable.

Features

  • Automatic and manual control over when the image renders
  • Fallback part accepts any children
  • Optionally delay fallback rendering to avoid content flashing

Installation

Anatomy

API Reference

Root

Contains all the parts of an avatar.

Image

The image to render. By default it will only render when it has loaded.
string
The source of the image.
string
Alternative text description of the image.
(status: 'idle' | 'loading' | 'loaded' | 'error') => void
Callback fired when the loading status changes.

Fallback

An element that renders when the image hasn’t loaded. This means whilst it’s loading, or if there was an error.
number
Useful for delaying rendering so it only appears for those with slower connections.

Examples

Basic Usage

Delayed Fallback

The delayMs prop is useful for preventing the fallback from flashing on screen for users with fast connections.

With Loading Status

Accessibility

Adheres to the img role requirements. The Image component should always have alt text to describe the image for screen reader users.