Avatar
Avatar — a person or entity's picture, with initials as the fallback.
Examples
<span class="avatar">
<span class="avatar-initials" aria-hidden="true">AL</span>
</span>
<span class="avatar avatar-lg">
<span class="avatar-initials" aria-hidden="true">GH</span>
</span>
<span class="avatar-group">
<span class="avatar"><span class="avatar-initials" aria-hidden="true">AL</span></span>
<span class="avatar"><span class="avatar-initials" aria-hidden="true">GH</span></span>
<span class="avatar"><span class="avatar-initials" aria-hidden="true">+3</span></span>
</span>Beside the person’s name, write alt="" — otherwise the name is read twice.
Standing alone, write alt="Ada Lovelace", because the avatar is then the only mention of them. Never alt="Avatar": it describes the widget in the one place the widget is irrelevant.
Tokens 13
Level 2, declared on .avatar itself. Set any of them on that selector to restyle this component without touching the skin.
| Token | Default |
|---|---|
| --avatar-bg | var(--color-surface-sunken) |
| --avatar-color | var(--color-on-surface) |
| --avatar-overlap | calc(var(--avatar-size) * 0.25) |
| --avatar-ring-width | 0px |
| --avatar-size | 2.5rem |
| --avatar-status-color | var(--color-on-surface-subtle) |
| --avatar-status-size | calc(var(--avatar-size) * 0.28) |
| --avatar-font-family | var(--font-secondary) |
| --avatar-font-size | calc(var(--avatar-size) * 0.4) |
| --avatar-font-weight | var(--font-weight-semibold) |
| --avatar-border-color | var(--color-border) |
| --avatar-border-width | var(--border-width) |
| --avatar-radius | var(--radius-full) |
Variants and states
Variants
.avatar-lg.avatar-more.avatar-sm.avatar-square.avatar-status-away.avatar-status-busy.avatar-status-online.avatar-xl
Inside it
.avatar-group.avatar-status.avatar-img.avatar-initials
State it reads
None.
Before you ship it
What you have to do 4 requirements
- Decide the
altper context. Beside the person's name, writealt=""— the picture adds nothing andalt="Ada Lovelace"makes the name be read twice. Standing alone, write the name. Neveralt="Avatar". - Keep
.avatar-initialsaria-hidden="true". It is a visual shorthand, never a name. - Name the root once where the avatar stands alone with initials rather than a photograph:
role="img"plusaria-label. - Wrap it in a
<button>or<a>if it does something. The avatar is not a control and has no focus ring of its own.
src/css/components/avatar.css · npx mostlycss add avatar