Skip to main content

Avatar

A small image or initials that stand for a person or account.

In Dense data

See it live​

Start Storybook to see it live: npm run storybook

When to use it​

In Dense data: Next to a user's name when assigning an alert or picking a user. Not without the name beside it, and not as decoration.

  • 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​

  • Lead with the object, then the state: "Alert 2041 contained."
  • Use numbers, not words for numbers.
  • One verb per button. No "please", no exclamation marks.
  • Use: Investigate, Filter, Assign, Escalated, Resolved. Avoid: Oops, Awesome, Please, Simply.

The labels components use, from the voice tokens:

  • content.action.commit: Save
  • content.action.cancel: Cancel
  • content.action.destroy: Delete
  • content.action.retry: Retry
  • content.action.empty-action: Change filters

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.

Changes with theme

Dense data 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.

PartIts token and the semantic it aliasesValue
Avatar
Sizecomponent.avatar.sizesize.control.defaultvar(--avatar-size)size.32:2rem
Cornercomponent.avatar.radiusradius.roundvar(--avatar-radius)radius.full:9999px
Fallback
Cornercomponent.avatar.fallback.radiusradius.roundvar(--avatar-fallback-radius)radius.full:9999px
Fill
Changes with theme
component.avatar.fallback.backgroundcolor.surface.sunkenvar(--avatar-fallback-background)Lightslate.light.100:#EEF1F5Darkslate.dark.100:#262D38
Text sizecomponent.avatar.fallback.font-sizetype.body.font-sizevar(--avatar-fallback-font-size)font.size.14:0.875rem
Text
Changes with theme
component.avatar.fallback.labelcolor.text.mutedvar(--avatar-fallback-label)Lightslate.light.600:#535D6DDarkslate.dark.400:#969FAD
Font size 2component.avatar.fallback.font-size-2type.caption.font-sizevar(--avatar-fallback-font-size-2)font.size.12:0.75rem
Badge
Cornercomponent.avatar.badge.radiusradius.roundvar(--avatar-badge-radius)radius.full:9999px
Fill
Changes with theme
component.avatar.badge.backgroundcolor.action.primaryvar(--avatar-badge-background)Lightviolet.light.600:#4B3FD9Darkviolet.dark.600:#A9A3F6
Text
Changes with theme
component.avatar.badge.labelcolor.text.on-actionvar(--avatar-badge-label)Lightslate.light.0:#FFFFFFDarkslate.light.900:#161B23
Focus ring
Changes with theme
component.avatar.badge.focus-ringcolor.surface.canvasvar(--avatar-badge-focus-ring)Lightslate.light.50:#F7F8FADarkslate.dark.0:#0D1117
Group
Focus ring
Changes with theme
component.avatar.group.focus-ringcolor.surface.canvasvar(--avatar-group-focus-ring)Lightslate.light.50:#F7F8FADarkslate.dark.0:#0D1117
Count sizecomponent.avatar.group.count.sizesize.control.defaultvar(--avatar-group-count-size)size.32:2rem
Count radiuscomponent.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)Lightslate.light.100:#EEF1F5Darkslate.dark.100:#262D38
Count font sizecomponent.avatar.group.count.font-sizetype.body.font-sizevar(--avatar-group-count-font-size)font.size.14:0.875rem
Count label
Changes with theme
component.avatar.group.count.labelcolor.text.mutedvar(--avatar-group-count-label)Lightslate.light.600:#535D6DDarkslate.dark.400:#969FAD
Count focus ring
Changes with theme
component.avatar.group.count.focus-ringcolor.surface.canvasvar(--avatar-group-count-focus-ring)Lightslate.light.50:#F7F8FADarkslate.dark.0:#0D1117
Count icon sizecomponent.avatar.group.count.icon-sizesize.iconvar(--avatar-group-count-icon-size)size.16:1rem