Avatar
A small image or initials that stand for a person or account.
In Accessible first
See it live
npm run storybookWhen to use it
In Accessible first: Beside a name, to show who is signed in. Not the only way to tell people apart; words come first.
- Use it when: Showing who wrote, owns or is signed in, next to their name.
- Not when: The only way to tell people apart, or decoration with no person behind it.
Instead:
- Badge: A status or count, not a person.
Words
- Use common words. Explain any term you must use.
- One idea per sentence. Put the action first.
- Never blame the person.
- Use: Continue, Change, Start, You. Avoid: Invalid, Utilise, Submit, Error code.
The labels components use, from the voice tokens:
content.action.commit: Continuecontent.action.cancel: Go backcontent.action.destroy: Deletecontent.action.retry: Try againcontent.action.empty-action: Start a new application
See Voice and tone for the whole voice.
Accessibility and keyboard
Test before you ship:
- The person's name is in text nearby or in the image's alternative text; initials alone are not a name. undefined
Use it in code
npx open-ds add avatar
The component reads only component keys and semantic tokens, so it follows the brand and mode on <html>.
Tokens it reads
Avatar reads 19 tokens of its own, each an alias of a semantic token. Each row is one part: its own token, the semantic it aliases, and the value it ends at. Change a semantic and every component that reads it follows; override one of Avatar's tokens to change Avatar alone.
Accessible first decides what changes when you switch theme. Here a switch changes colors only, so the marked rows differ between light and dark; everything else holds steady.
| Part | Its token and the semantic it aliases | Value |
|---|---|---|
| Avatar | ||
| Size | component.avatar.sizesize.control.defaultvar(--avatar-size) | size.52:3.25rem |
| Corner | component.avatar.radiusradius.roundvar(--avatar-radius) | radius.full:9999px |
| Fallback | ||
| Corner | component.avatar.fallback.radiusradius.roundvar(--avatar-fallback-radius) | radius.full:9999px |
| Fill Changes with theme | component.avatar.fallback.backgroundcolor.surface.sunkenvar(--avatar-fallback-background) | Lightgray.light.100:#EDEDEDDarkgray.dark.100:#222222 |
| Text size | component.avatar.fallback.font-sizetype.body.font-sizevar(--avatar-fallback-font-size) | font.size.19:1.1875rem |
| Text Changes with theme | component.avatar.fallback.labelcolor.text.mutedvar(--avatar-fallback-label) | Lightgray.light.500:#595959Darkgray.dark.500:#949494 |
| Font size 2 | component.avatar.fallback.font-size-2type.caption.font-sizevar(--avatar-fallback-font-size-2) | font.size.16:1rem |
| Badge | ||
| Corner | component.avatar.badge.radiusradius.roundvar(--avatar-badge-radius) | radius.full:9999px |
| Fill Changes with theme | component.avatar.badge.backgroundcolor.action.primaryvar(--avatar-badge-background) | Lightblue.light.600:#0B4FC0Darkblue.dark.600:#8AB4F8 |
| Text Changes with theme | component.avatar.badge.labelcolor.text.on-actionvar(--avatar-badge-label) | Lightgray.light.0:#FFFFFFDarkgray.light.900:#141414 |
| Focus ring Changes with theme | component.avatar.badge.focus-ringcolor.surface.canvasvar(--avatar-badge-focus-ring) | Lightgray.light.50:#F7F7F7Darkgray.dark.0:#0A0A0A |
| Group | ||
| Focus ring Changes with theme | component.avatar.group.focus-ringcolor.surface.canvasvar(--avatar-group-focus-ring) | Lightgray.light.50:#F7F7F7Darkgray.dark.0:#0A0A0A |
| Count size | component.avatar.group.count.sizesize.control.defaultvar(--avatar-group-count-size) | size.52:3.25rem |
| Count radius | component.avatar.group.count.radiusradius.roundvar(--avatar-group-count-radius) | radius.full:9999px |
| Count background Changes with theme | component.avatar.group.count.backgroundcolor.surface.sunkenvar(--avatar-group-count-background) | Lightgray.light.100:#EDEDEDDarkgray.dark.100:#222222 |
| Count font size | component.avatar.group.count.font-sizetype.body.font-sizevar(--avatar-group-count-font-size) | font.size.19:1.1875rem |
| Count label Changes with theme | component.avatar.group.count.labelcolor.text.mutedvar(--avatar-group-count-label) | Lightgray.light.500:#595959Darkgray.dark.500:#949494 |
| Count focus ring Changes with theme | component.avatar.group.count.focus-ringcolor.surface.canvasvar(--avatar-group-count-focus-ring) | Lightgray.light.50:#F7F7F7Darkgray.dark.0:#0A0A0A |
| Count icon size | component.avatar.group.count.icon-sizesize.iconvar(--avatar-group-count-icon-size) | size.20:1.25rem |