Avatar
<wa-avatar>
Avatars represent a person or object with an image, initials, or icon. Use them in lists, comments, and profiles to give users visual context at a glance.
By default, a generic icon will be shown. You can personalize avatars by adding custom icons, initials, and images. You should always provide a label for assistive devices.
Examples
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 lazily 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 personalized than an icon.
Custom Icons
When no image or initials are set, an icon will be shown. The default avatar shows a generic "user" icon, but you can customize this with the icon slot.
Shapes
Avatars can be shaped using the shape attribute.
Avatar Groups
You can group avatars with a few lines of CSS.
Importing
If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.
Import this component directly from the CDN:
import 'https://ka-f.webawesome.com/[email protected]/components/avatar/avatar.js';
After installing Web Awesome via npm, import this component:
import '@awesome.me/webawesome/dist/components/avatar/avatar.js';
If you're self-hosting Web Awesome, import this component from your server:
import './webawesome/dist/components/avatar/avatar.js';
To import this component for React 18 or below, use the following code:
import WaAvatar from '@awesome.me/webawesome/dist/react/avatar/index.js';
Slots
Learn more about using slots.
| Name | Description |
|---|---|
icon
|
The default icon to use when no image or initials are present. Works best with <wa-icon>. |
Attributes & Properties
Learn more about attributes and properties.
| Name | Description | Reflects | |
|---|---|---|---|
css |
One or more CSSResultGroup to include in the component's shadow root. Host styles are automatically prepended.
Type
CSSResultGroup | undefinedDefault
styles |
||
imageimage |
The image source to use for the avatar.
Type
stringDefault
'' |
||
initialsinitials |
Initials to use as a fallback when no image is available (1-2 characters max recommended).
Type
stringDefault
'' |
||
labellabel |
A label to use to describe the avatar to assistive devices.
Type
stringDefault
'' |
||
loadingloading |
Indicates how the browser should load the image.
Type
'eager' | 'lazy'Default
'eager' |
||
shapeshape |
The shape of the avatar.
Type
'circle' | 'square' | 'rounded'Default
'circle' |
|
Events
Learn more about events.
| Name | Description |
|---|---|
wa-error |
The image could not be loaded. This may because of an invalid URL, a temporary network condition, or some unknown cause. |
CSS custom properties
Learn more about CSS custom properties.
| Name | Description |
|---|---|
--size |
The size of the avatar.
|
CSS parts
Learn more about CSS parts.
| Name | Description | CSS selector |
|---|---|---|
icon |
The container that wraps the avatar's icon. |
::part(icon)
|
image |
The avatar image. Only shown when the image attribute is set. |
::part(image)
|
initials |
The container that wraps the avatar's initials. |
::part(initials)
|
Dependencies
This component automatically imports the following elements. Sub-dependencies, if any exist, will also be included in this list.