Avatar
Avatars represent users or entities by displaying images, icons, or characters.
Usage
Import the component:
import 'mdui/components/avatar.js';
Import the TypeScript type:
import type { Avatar } from 'mdui/components/avatar.js';
Example:
<mdui-avatar src="https://avatars.githubusercontent.com/u/3030330?s=40&v=4"></mdui-avatar>
Examples
Image Avatar
To use an image as the avatar, specify the image link using the src
attribute, or provide an <img>
element within the default slot.
The fit
attribute determines how the image should fit the container box. It works similar to the native object-fit
property.
Icon Avatar
To use a Material Icons icon as the avatar, specify the icon using the icon
attribute. Alternatively, provide an icon element within the default slot.
Character Avatar
You can use any text within the default slot as the avatar.
API
Properties
Attribute | Property | Reflect | Type | Default |
---|---|---|---|---|
src | src | string | - | |
URL of the avatar image. | ||||
fit | fit | 'contain' | 'cover' | 'fill' | 'none' | 'scale-down' | - | |
Image resizing method, similar to the native CSS
| ||||
icon | icon | string | - | |
The Material Icons name for the avatar. | ||||
label | label | string | - | |
Text description of the avatar. |
CSS Custom Properties
Name |
---|
--shape-corner |
The size of the component corner. You can use a specific pixel value, but it's recommended to reference design tokens. |