Avatar
A person or a thing, at a glance. An image when there is one, initials when there is not.
Anatomy
╭────╮
│ AL │ ← initials, or the image, cropped to the shape
╰────╯
| Part | Token | Why |
|---|---|---|
| Fill | neutral-tint + on-neutral-tint | The badge tint pair, already contrast-checked in both themes by npm test. |
| Shape | radius-full, or radius-control when square | See below. |
| Image | object-cover | A portrait cropped to a circle is the point. contain letterboxes it against the tint. |
Sizes
xs (24px) | sm (32px) | md (40px) | lg (48px) | xl (64px, added in 2.0 for a profile page and avatar-upload)
A closed set of literal classes, not size-{$size} — see icon.md.
sm matches the 32px control-sm height, so an avatar sits level with a small
button in a table row without a nudge. md matches the sheet's row tile.
Round or square
Round by default. square is for a company, a project or a file — a circle
reads as a person, and a logo in a circle gets its corners eaten.
That is the only rule; there is no "brand" variant and no size-dependent shape.
Initials
Taken from the first and last word of name, not the first two — "Ada King
Lovelace" is AL, because the middle name is the part nobody uses.
Everything goes through mb_*. strtoupper corrupts a multi-byte first letter,
and a name is the single most likely place in an interface to meet one; mb_substr
also takes the first grapheme, so an accented letter or an emoji survives
instead of being cut in half.
initials overrides them, upper-cased, for a name the rule gets wrong ("UL"
for "Umbrella Labs" is the rule; "UMB" is a choice). It does not change alt.
With neither src nor name the component renders a placeholder mark rather
than an empty circle. A blank avatar is a bug the reader cannot report.
Status
status: online, away, busy or offline, a dot on the end-bottom corner sized
with the avatar and ringed in surface so it reads on the face and the
ground. Each is a shape as well as a colour (WCAG 1.4.1):
| Status | Shape | Colour |
|---|---|---|
| online | solid | success |
| away | half filled, bordered | warning |
| busy | solid with a bar | danger |
| offline | hollow ring | fg-muted |
The word follows as visually hidden text, so the avatar reads "Ada Lovelace,
away"; when decorative, it is hidden with the rest. Without status the
markup is byte-for-byte 1.x (tests/AvatarUnchangedTest.php).
Accessibility
- With
src, the image'saltisname. decorativehides the whole thing —aria-hidden, andalt=""on the image. Use it whenever the name is written beside the avatar, which is most of the time: a row that announces "Ada Lovelace, Ada Lovelace" is worse than one that announces it once.- No
nameand nodecorativestill hides it, because an avatar with nothing to announce has nothing to announce. - The initials carry
select-none, so dragging across a list of people does not produce "ALJSMK".
Do not
- Do not use it as a button. Wrap it in one. An avatar with a click handler has no focus ring, no hover state and no keyboard access.
- Do not derive the colour from the name. A hash-to-hue avatar is nine unmanaged colours arriving through the back door — the exact sprawl sheet.md removed from this system.
- Do not add a fifth status. The four are presence; anything else is words beside the avatar. (Until 2.0 this said not to put a dot here at all; presence-stack needed one, and a dot composed outside the avatar could not size or ring itself with it.)
- Do not stretch it. It is
shrink-0for a reason — in a flex row a squashed avatar is an ellipse, and nobody notices until it is in production.
From the package repo: edit this page on GitHub.