Skip to main content

Avatar

Avatar component is used to show a thumbnail representation of an individual or business in the interface. It can be a graphical representation or visual depiction, such as an image, initials, or an icon.

string

An alternative text description that describe the image for the reader to understand what it is about or identify the user the avatar belongs to.

string

A unique identifier for the element.

string

Initials to display in the avatar.

'small' | 'large' | 'base' | 'small-200' | 'large-200'
Default: 'base'

Size of the avatar.

string

The URL or path to the image.

Initials will be rendered as a fallback if src is not provided, fails to load or does not load quickly.

Was this section helpful?

Learn more about registering events.

((event: <typeof tagName>) => void) | null

Callback when the image fails to load.

((event: <typeof tagName>) => void) | null

Callback when the image loads successfully.

Was this section helpful?

Basic Avatar

Preact

import '@shopify/ui-extensions/preact';
import {render} from 'preact';

export default async () => {
render(<Extension />, document.body);
};

function Extension() {
return <s-avatar initials="EW" alt="Evan White" size="base" />;
}

Preview

An example of the Avatar component shows the default avatar in four sizes.

  • By default, if a user does not provide their first or last name, the avatar component will display a placeholder icon. However, if at least one of the names is provided, the avatar will be replaced with one or two initials representing the user.

    • There are 5 sizes for the avatar component:

      • small-200 (21x21 px): Use when showing avatars in tables / lists where space is limited.
      • small (26x26 px): Use when you want to conserve space but want a larger size than small-200.
      • base (32x32 px): Use by default.
      • large (39×39 px): Use when the avatar is a focal point, such as a customer details card.
      • large-200 (47x47 px): Use when placing more emphasis on the avatar.
    • Provide alt text for avatars to assist customers using assistive technologies.

    Dos

    • When using multiple avatars on the same page, maintain a consistent style and size to create a unified visual pattern for users.

    Don'ts

    • Don't use different size avatars on the same page.

    An example showing dos and don'ts of the Avatar component

Was this section helpful?