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
Use the src attribute to set an image as the avatar, or pass an <img> element into the default slot.
The fit attribute controls how the image fits in its container. It works similarly to the native object-fit property.
Icon Avatar
Use the icon attribute to set a Material Icon for the avatar. Alternatively, pass an icon element into the default slot.
Character Avatar
You can use any text in 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 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 corner radius of the component. You can use a specific pixel value, but it is recommended to reference design tokens. |