Skip to main content Design tokens Components Style utilities
Skip to table of contents

    Avatar

    Avatars are used to represent a person or object.

    By default, a generic icon will be shown. You can personalise avatars by adding custom icons, initials and images. You should always provide a label for assistive devices.

    <pc-avatar label="User avatar"></pc-avatar>
    Code

    Demos

    Images

    To use an image for the avatar, set the image and label attributes. This will take priority and be shown over initials and icons. Avatar images can be lazy‐loaded by setting the loading attribute to lazy.

    Initials

    When you don’t have an image to use, you can set the initials attribute to show something more personalised than an icon.

    Custom icons

    When no image or initials are set, an icon will be shown. The default avatar shows the Font Awesome user icon, but you can customise this with the icon slot.

    Shapes

    Avatar shapes can be changed with the shape attribute.

    Avatar groups

    You can group avatars into an avatar group with a few lines of CSS.

    Properties

    NameDescriptionReflectsDefault
    imageThe image source to use for the avatar. string""
    labelA label to use to describe the avatar to assistive devices. string""
    initialsInitials to use as a fallback when no image is available (1–2 characters recommended). string""
    loadingIndicates how the browser should load the image. "eager" | "lazy""eager"
    shapeThe shape of the avatar. "circle" | "rounded" | "square""circle"
    updateComplete A read‐only promise that resolves when the component has finished updating. -

    Learn more about attributes and properties.

    Slots

    NameDescription
    iconThe default icon to use when no image or initials are present. Works best with <pc-icon>.

    Learn more about using slots.

    Events

    NameDescriptionEvent detail
    pc-errorEmitted when the image couldn’t be loaded. This may be because of an invalid URL, a temporary network error or some other unknown cause.-

    Learn more about events.

    Custom properties

    NameDescriptionDefault
    --sizeThe size of the avatar.-

    Learn more about customising custom properties.

    Parts

    NameDescription
    baseThe component’s base wrapper.
    iconThe container that wraps the avatar’s icon.
    initialsThe container that wraps the avatar’s initials.
    imageThe avatar image. Only shown when the image attribute is set.

    Learn more about customising CSS parts.

    Importing

    If you’re using the autoloader or the standard loader, you can ignore this section. If you’re cherry picking, you can use any of the following snippets to import this component.

    ScriptImportBundler

    To import this component from the CDN with a script tag, copy this snippet and paste it in your HTML.

    <script type="module" src="https://cdn.jsdelivr.net/npm/placer-toolkit@0.5.1/dist/components/avatar/avatar.js"></script>

    To import this component from the CDN using a JavaScript import, copy this snippet and paste it in your JavaScript:

    import "https://cdn.jsdelivr.net/npm/placer-toolkit@0.5.1/dist/components/avatar/avatar.js";

    To import this component with a bundler using a JavaScript import, copy this snippet and paste it in your JavaScript:

    import "placer-toolkit/dist/components/avatar/avatar.js";

    Dependencies

    This component automatically imports these components: