Skip to main content Sidebar
On this page
Skip to table of contents

Avatar

<pc-avatar> 0.1.0 experimental

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.

Edit

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.

Edit

Initials

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

Edit

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.

Edit

Shapes

Avatar shapes can be changed with the shape attribute.

Edit

Avatar groups

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

Edit

Properties

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

Learn more about customising animations.

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.3rem

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 skip this section. But if you’re cherry picking, you can use any of the following snippets to import this component.

CDN (script tag)CDN (import)npm (import)

To manually import this component from the CDN, copy this code snippet and paste it in your HTML.

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

To manually import this component from the CDN, copy this code snippet and paste it in your JavaScript file.

import "https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.3/cdn/components/avatar/avatar.js";

To manually import this component from npm, copy this code snippet and paste it in your JavaScript file.

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

Dependencies

This component automatically imports these components:

We’d love to hear from you. Please reach out to us with any questions or enquiries you may have.

You can contact us via e‐mail at placer.coc.reports+contact@gmail.com.

We look forward to hearing from you!

Got it!
Dangerous lands

Whoa! You’ve wandered into the dangerous lands of Placer Toolkit. Version 0 is out of date and doesn’t meet EU privacy standards, including GDPR.

Want the latest powers, security and compliance? Stick with the current version of Placer Toolkit!

Yikes! Power up!

Our site is 100 % cookie‐free! We value your privacy, which is why we don’t store any cookies or personal information related to you.

Your browser history is safe from crumbs, and your data is protected, aligning with modern privacy standards like the GDPR. Enjoy your visit without a single digital cookie in sight! 🍪🚫

View our Privacy Policy for more information.

Got it!