Skip to content

Avatar

An image element with a fallback for representing the user.

When to use

  • Displaying a user's profile picture.
  • Showing initials when no image is available.

API

Avatar::new(fallback)

Creates an avatar with fallback initials.

MethodTypeDefaultDescription
.src(src)impl Into<SharedString>Image source file/asset path

When src is set, the image is rendered; otherwise the fallback initials are shown in a 40×40px ZINC_100 circle.

Usage

rust
use gpui::{Component, div, prelude::*};
use components::Avatar;

div().child(Component::new(
    Avatar::new("JD").src("path/to/image.png"),
))

Copy the source

crates/components/src/avatar.rs — self-contained, stateless, and free to modify.

Released under the MIT License.