Avatar
Shows a user image, or their initials when no image is available.
Selector: mui-avatar
import { Avatar } from '@mushilu-san/ui/primitives';Loading example…
Overview
src is set and loads. If the image is missing or fails to load, it falls back to the initials of name.
role="img" and an aria-label taken from label, or from name when label is empty. The image and initials inside are hidden from assistive technology so the name is announced once.
Examples
Sizes and shapes
square for organisations or products, circle for people.
Loading example…
Guidelines
Do
Pass nameeven when you also pass an image, so the fallback and the accessible name stay correct.Use labelwhen the visible name is not the full name, for example "Account of Dana Levi".
Don't
Do not pass untrusted or unvalidated image URLs. srcis sanitised by Angular, but the URL source is still your responsibility.Do not use an avatar as the only way to identify a user in a dense table. Show the name as text too.
Accessibility
Roles and attributes
| Element | Role | Notes |
|---|---|---|
host | img | aria-label comes from label, or from name when label is empty. |
image and initials | — | aria-hidden="true", so the name is read once. |
An avatar is not focusable. If it links somewhere, wrap it in a link and give the link the accessible name. Set labelwhen the visible text is an abbreviation or the name is not known.
API
Avatar
| Name | Type | Default | Description |
|---|---|---|---|
src | string | undefined | — | Image URL. Bound via `[src]`, so Angular's built-in URL sanitizer applies (e.g. `javascript:` URLs are neutralized). Consumers remain responsible for passing trusted/validated URLs, especially user-generated ones. |
name | string | '' | Full name. Used for the initials fallback and, when no `label` is set, the accessible name. |
label | string | '' | Accessible name. Overrides `name` for screen readers. |
size | 'sm' | 'md' | 'lg' | 'xs' | 'xl' | 'md' | Avatar size: `xs` to `xl`. Default `md`. |
shape | 'circle' | 'square' | 'circle' | Avatar shape: `circle` or `square`. Default `circle`. |
CSS parts
::part(root)
Tokens
--mui-color-surface--mui-color-text--mui-radius-full