Avatar

An image that represents a user, with a fallback while it loads or fails.

EXAMPLEwasm · webgpu

This demo runs the real GPUI component on WebGPU, which this browser does not expose.

Try Chrome or Edge 113+, or Safari 26+. In Firefox, enable dom.webgpu.enabled.

You can also run it natively: cargo run -p showcase avatar

The demo failed to start in this browser.

You can run it natively instead: cargo run -p showcase avatar

Live examples are not supported on most mobile browsers yet — open this page on a desktop or tablet to run the demo.

Recent phones with WebGPU may manage it (downloads ~18 MB):

#Anatomy

Import the component's parts and compose them under its root:

use base_gpui::avatar::{
    AvatarFallback,
    AvatarImage,
    AvatarRoot,
};

AvatarRoot::new()
    .child(
        AvatarFallback::new(),
    )
    .child(
        AvatarImage::new(/* source: impl Into<ImageSource> */),
    );
The anatomy is a structural overview. Parts with mutually exclusive modes may need separate instances; each part's section below documents its configuration.

#AvatarRoot

Coordinates the component's state and supplies context to its child parts.

Source

use base_gpui::avatar::AvatarRoot;

AvatarRoot::new()
    .child_element(/* element: impl IntoElement */)
    .aria_label("label")
    .id("example-id")
    .style_with_state(|/* callback arguments */| { /* handle change */ });

#Builders

BuilderSignature & description
.newpub fn new() -> Self

Creates a AvatarRoot with its default configuration.

.childpub fn child(mut self, child: impl Into<AvatarChild>) -> Self
  • child: impl Into<AvatarChild>

Adds one typed child to this part.

.childrenpub fn children(mut self, children: impl IntoIterator<Item = impl Into<AvatarChild>>) -> Self
  • children: impl IntoIterator<Item = impl Into<AvatarChild>>

Adds multiple typed children in iteration order.

.child_elementpub fn child_element(mut self, element: impl IntoElement) -> Self
  • element: impl IntoElement

Sets the child element configuration for this part.

.aria_labelpub fn aria_label(mut self, label: impl Into<SharedString>) -> Self
  • label: impl Into<SharedString>

Accessible label for the avatar (the GPUI stand-in for <img alt>). When set, the root enters the AccessKit tree as Role::Image with this label. When unset, the avatar has no role and produces no AccessKit node — omitting the label is how you mark an avatar decorative (there is no aria-hidden builder in this gpui revision). There is also no live-region API, so loading status is never announced.

.idpub fn id(mut self, id: impl Into<ElementId>) -> Self
  • id: impl Into<ElementId>

Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view.

.style_with_statepub fn style_with_state(mut self, style: impl Fn(AvatarRootStyleState, Div) -> Div + 'static,) -> Self
  • style: impl Fn(AvatarRootStyleState, Div) -> Div + 'static,

Styles the part from its current behavioral state while preserving separation between behavior and visual design.

AvatarRoot also supports the GPUI traits implemented in its source, such as standard styling or child composition.

#AvatarFallback

Public renderable part of the Avatar Fallback component.

Source

use base_gpui::avatar::AvatarFallback;

AvatarFallback::new()
    .delay(/* delay: Duration */)
    .style_with_state(|/* callback arguments */| { /* handle change */ });

#Builders

BuilderSignature & description
.newpub fn new() -> Self

Creates a AvatarFallback with its default configuration.

.delaypub fn delay(mut self, delay: Duration) -> Self
  • delay: Duration

Sets the delay before the related transition or interaction begins.

.style_with_statepub fn style_with_state(mut self, style: impl Fn(AvatarFallbackStyleState, Div) -> Div + 'static,) -> Self
  • style: impl Fn(AvatarFallbackStyleState, Div) -> Div + 'static,

Styles the part from its current behavioral state while preserving separation between behavior and visual design.

AvatarFallback also supports the GPUI traits implemented in its source, such as standard styling or child composition.

#AvatarImage

Public renderable part of the Avatar Image component.

Source

use base_gpui::avatar::AvatarImage;

AvatarImage::new()
    .on_loading_status_change(|/* callback arguments */| { /* handle change */ })
    .style_with_state(|/* callback arguments */| { /* handle change */ });

#Builders

BuilderSignature & description
.newpub fn new(source: impl Into<ImageSource>) -> Self
  • source: impl Into<ImageSource>

Creates a AvatarImage with its default configuration.

.on_loading_status_changepub fn on_loading_status_change(mut self, on_loading_status_change: impl Fn(AvatarImageLoadingStatus, &mut Window, &mut App) + 'static,) -> Self
  • on_loading_status_change: impl Fn(AvatarImageLoadingStatus, &mut Window, &mut App) + 'static

Registers a callback invoked when loading status change occurs.

.style_with_statepub fn style_with_state(mut self, style: impl Fn(AvatarImageStyleState, Div) -> Div + 'static,) -> Self
  • style: impl Fn(AvatarImageStyleState, Div) -> Div + 'static,

Styles the part from its current behavioral state while preserving separation between behavior and visual design.

AvatarImage also supports the GPUI traits implemented in its source, such as standard styling or child composition.

#Accessibility

Keyboard interaction and accessibility semantics are implemented by the component, independently of visual styling. Known limitations caused by missing GPUI accessibility primitives are documented in the module source and are not silently approximated.

#Stability

Base GPUI is pre-1.0. Builder names and state types may evolve as GPUI and this port mature.