Avatar
A circle that stands for a person, team or workspace: their photo, or one or two initials on a hue pair when there is no photo or it fails to load. Soft by default; solid inside a Token or on a photo or gradient.
Preview
Usage
When to use
- Show who a piece of content belongs to: a comment author, an assignee, the members of a team.
- Stand in for a missing or slow photo with one or two initials on a soft hue.
When not to use
- A logo, a product image or a picture in content. Use a native img.
- A person picked as a value, such as a recipient in a field. Use Token with a leading avatar.
- A status such as online or busy. Use Badge next to the name.
- The only place a name appears in a list or comment. Write the name next to the avatar.
Platform support
What each platform has, from the spec. A selected platform is highlighted.
| Name | Web | iOS | Android | Note |
|---|---|---|---|---|
| variant | Yes | Yes | Yes | |
| color | Yes | Yes | Yes | |
| size | Yes | Yes | Yes | |
| src | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| alt | Yes | Yes | Yes | |
| shape | Yes | Yes | Yes | |
| name | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| delayMs | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| status | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| statusLabel | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| image | No | Yes | Yes | Only on iOS, Android. |
| icon | No | Yes | Yes | Only on iOS, Android. |
Variants
variant
soft: background-<hue> with text-<hue>, for lists and comment headers. solid: the <hue> solid with text-on-<hue>, inside a Token or on a photo or gradient where the soft fill would not stand out.
color
The hue pair behind the initials. Never the accent. To keep one person's color across a page, pick the hue from something stable, such as their user id.
size
xs 20px for dense lists, sm 24px for table rows, md 32px for comment headers and member lists, lg 40px, xl 48px for profile headers.
shape
circle for people; square (radius-element) for workspaces and orgs.
status
A dot on the bottom end edge: success, warning, danger or gray solid on a background-surface rim; away also takes a border-warning edge, since the warning fill is under 3:1 on light surfaces. Also added to the avatar's name ("Ada Lovelace, Online").
Examples
Default
With photo
The initials show until the photo loads, and stay if it fails.
Next to a name
The name is written next to the avatar, so alt is empty and the avatar is hidden from screen readers.
Without a name
An icon on the soft variant, for a guest or a deleted account.
From a name
Initials and a stable hue from the name.
Status
Square
Extra sizes
Do and don't
Do
- Pass the person's name as alt, or alt="" when the name is written next to the avatar.
- Always pass initials as children, even with src, so a slow or broken photo still shows something.
- Use solid inside a Token or on a photo or gradient; use soft everywhere else.
- Keep one hue per person across the page.
Don't
- Don't put an icon on a solid avatar; there is no icon token for a hue solid.
- Don't use the accent or a status color as the fill.
- Don't let the avatar replace a visible name in lists, comments or assignee fields.
- Don't use it for logos or product images; use a native img.
Props
| Name | Type | Values | Default | Description |
|---|---|---|---|---|
| variant | enum | soft | solid | soft | soft: background-<hue> with text-<hue>, for lists and comment headers. solid: the <hue> solid with text-on-<hue>, inside a Token or on a photo or gradient where the soft fill would not stand out. |
| color | enum | gray | red | orange | yellow | green | teal | blue | purple | pink | gray | The hue pair behind the initials. Never the accent. To keep one person's color across a page, pick the hue from something stable, such as their user id. |
| size | enum | xs | sm | md | lg | xl | md | xs 20px for dense lists, sm 24px for table rows, md 32px for comment headers and member lists, lg 40px, xl 48px for profile headers. |
| src | string | - | - | Photo URL. The initials show until it loads, and stay if it fails. Not generated for iOS and Android. |
| alt required | string | - | - | Name of the person, team or workspace: Ada Lovelace. Pass an empty string when the name is written next to the avatar. |
| shape | enum | circle | square | circle | circle for people; square (radius-element) for workspaces and orgs. |
| name | string | - | - | Derives the initials (one or two letters) when there are no children and, without color, a stable hue from the name. Not generated for iOS and Android. |
| delayMs | number | - | - | With src, milliseconds to wait before the fallback shows, so a fast photo never flashes the initials. Not generated for iOS and Android. |
| status | enum | online | away | busy | offline | - | A dot on the bottom end edge: success, warning, danger or gray solid on a background-surface rim; away also takes a border-warning edge, since the warning fill is under 3:1 on light surfaces. Also added to the avatar's name ("Ada Lovelace, Online"). Not generated for iOS and Android. |
| statusLabel | string | - | - | The status word read out; defaults to Online, Away, Busy or Offline. Translate it here. Not generated for iOS and Android. |
| image | node | - | - | Native only: the photo, a view you supply. It is drawn over the fallback and clipped to the shape. Remote loading is up to the app. Only on iOS, Android. |
| icon | node | - | - | Native only: an icon shown in the circle on the soft variant, sized by the avatar. Pass it instead of the initials for someone without a name. Only on iOS, Android. |
Slots
| Name | Required | Description |
|---|---|---|
| fallback | yes | One or two initials, such as AL. On the soft variant, an icon for someone without a name. |
Anatomy
| Part | Description |
|---|---|
| root | The circle: radius-full, the hue fill, and the name of the avatar. 24, 32 or 40px. |
| image | The photo, cropped to fill the circle. Rendered only once it has loaded, then it fades in with duration-medium (no fade under reduced motion). |
| fallback | The children: one or two initials in medium weight, shown until the photo loads and when it fails or is missing. |
| icon | Optional Tabler icon as the fallback on the soft variant, 12px in sm, 16px in md, 20px in lg. |
| status | Optional presence dot, data-slot avatar-status, aria-hidden, on a background-surface rim; the status is in the root's name, or in visually hidden text when alt is "". |
Accessibility
Role: img
- alt names the avatar on the root (role img with aria-label), so the name is the same whether the photo loads or the initials show, and the initials are never read out letter by letter. The type requires alt.
- When the name is written next to the avatar, as in a comment header or a member list, pass alt="": the avatar is hidden from screen readers, so the name is not read twice.
- Avatar is not interactive. To open a profile, put the avatar and the name inside one link, and name the link.
- The hue is decoration. Never let it carry meaning such as a role or a status on its own.
- Solid initials use text-on-<hue>, which meets 4.5:1 on every hue in both modes. There is no icon token for a hue solid, so an icon fallback is for the soft variant only.
- The status dot is never the only signal: its word is part of the avatar's aria-label. With alt="" the avatar is not hidden; the word is read from visually hidden text.
Install
npx werewolf-ui add avatarRun npx werewolf-ui init once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See Installation for requirements and the alternative registry setup.