Components
Avatar

Avatar

A graphical representation of the user, often used in profile sections.

Loading...

Anatomy

<Avatar.Root>
  <Avatar.Fallback />
  <Avatar.Image />
</Avatar.Root>

Examples

Basic

Display a user's profile image with a fallback.

Events

Use onStatusChange to listen for loading state changes.

Root Provider

An alternative way to control the avatar is to use the RootProvider component and the useAvatar hook. This way you can access the state and methods from outside the component.

API Reference

Props

Root

Renders a <div> element.

PropDefaultType
asChild
Component<{ propsFn: (userProps?: Object) => Object }>

Use the provided named component as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.
ids
Partial<{ root: string; image: string; fallback: string }>

The ids of the elements in the avatar. Useful for composition.

onStatusChange
(details: StatusChangeDetails) => void

Functional called when the image loading status changes.

Fallback

Renders a <span> element.

PropDefaultType
asChild
Component<{ propsFn: (userProps?: Object) => Object }>

Use the provided named component as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.
AttributeDescription
[data-scope]avatar
[data-part]fallback
[data-state]"hidden" | "visible"

Image

Renders a <img> element.

PropDefaultType
asChild
Component<{ propsFn: (userProps?: Object) => Object }>

Use the provided named component as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.
AttributeDescription
[data-scope]avatar
[data-part]image
[data-state]"visible" | "hidden"

RootProvider

Renders a <div> element.

PropDefaultType
value
UseAvatarReturn

asChild
Component<{ propsFn: (userProps?: Object) => Object }>

Use the provided named component as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.

Context

API

PropertyType
loaded
boolean

Whether the image is loaded.

setSrc
(src: string) => void

Function to set new src.

setLoaded
VoidFunction

Function to set loaded state.

setError
VoidFunction

Function to set error state.