Avatar
<afp-avatar>
An avatar component to display user profile images with initials fallback.
Examples #
Variants #
The avatar component supports different variants using the variant attribute.
Shapes #
use the shape attribute to change avatar's shape.
Sizes #
Use the size attribute to change an avatar's size.
Images #
Display an avatar with a custom image using the image attribute.
Initials #
Display an avatar with user initials using the name attribute.
Custom Default Icon #
Use the icon slot within the avatar to display custom default icons.
With Tooltip #
Add a tooltip using the title attribute.
Disabled #
Disable an avatar using the disabled attribute.
Properties
Learn more about properties.
| Name | Description | Reflects | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
image
|
The URL of the image to be displayed inside the avatar.
Type
string
|
|||||||||||||||||
name
|
A placeholder for initials when no image is available.
Initials are generated based on the name assigned to this property,
typically limited to 1–2 characters for best readability.
Type
string
|
|||||||||||||||||
shape
|
shape of the avatar
Type
AfpShape
Default
AfpShape.CIRCLE |
|
||||||||||||||||
variant
|
variant of avatar (color/appearance)
Type
AfpVariant
Default
AfpVariant.NEUTRAL |
|
||||||||||||||||
size
|
size of the avatar
Type
AfpSize
Default
AfpSize.MEDIUM |
|
||||||||||||||||
disabled
|
Disabled property of avatar.
Type
boolean
|
|
||||||||||||||||
label
|
A label that describes the avatar for assistive devices.
Type
string
|
|||||||||||||||||
title
|
The title of a browser-specific tooltip when provided.
Type
string
|
|
Slots
Learn more about slots.
| Name | Description |
|---|---|
icon
|
The default icon slot when no image or initials are provided.
|
Internationalization
Learn more about internationalization.
| Key | Description |
|---|---|
avatar.aria-label
|
The default `aria-label` text for Avatar
|
avatar.img.alt
|
The default image `alt` text for Avatar
|
CSS Parts
Learn more about CSS Parts.
| Name | Description | Selector |
|---|---|---|
base
|
The avatar element wrapper.
|
::part(base)
|
image
|
The image element when an image is provided.
|
::part(image)
|
initials
|
The initials container when image is not provided.
|
::part(initials)
|
default-icon
|
The default icon when no image or initials are provided.
|
::part(default-icon)
|
CSS Custom Properties
| Name | Description | Default |
|---|---|---|
--afp-avatar-disabled-opacity
|
The opacity of the avatar when disabled.
|
0.5
|
--afp-avatar-border-color
|
The border color of the avatar.
|
--afp-color-body
|
--afp-avatar-border-width
|
The border width of the avatar.
|
--afp-border-width-m
|
Dependencies
The component automatically brings in the listed items, including any nested dependencies that may exist.
| Component | CSS Part Prefix |
|---|---|
|
|
default-icon
- The default icon when no image or initials are provided.
|
Importing
Using the bundle is the recommended method to include components. If you’d rather handle imports manually, you can use the code examples below.
import '@afp-design-system/core/dist/components/avatar/avatar.js';