Avatar

Give an avatar a name and no src and it renders the initials instead of a broken image. That is the useful fallback for a contributor list where only some people have a photo.

Basic avatar

ALGHAT
stack({ direction: 'row', gap: 'md', align: 'center' },
  avatar({ name: 'Ada Lovelace' }),
  avatar({ name: 'Grace Hopper' }),
  avatar({ name: 'Alan Turing' }),
)

With an image

When src is set, alt falls back to the name — so an avatar is never an unlabelled image.

sitelositelo
stack({ direction: 'row', gap: 'md', align: 'center' },
  avatar({ src: '/logo.svg', alt: 'sitelo', style: 'background: var(--su-surface-2)' }),
  avatar({ src: '/logo.svg', name: 'sitelo', square: true, style: 'background: var(--su-surface-2)' }),
)

Sizes

The font size scales with the avatar, so initials stay proportionate.

SOMOLO
stack({ direction: 'row', gap: 'md', align: 'center' },
  avatar({ name: 'Small One', size: 'sm' }),
  avatar({ name: 'Medium One', size: 'md' }),
  avatar({ name: 'Large One', size: 'lg' }),
)

Square

PAPB
stack({ direction: 'row', gap: 'md', align: 'center' },
  avatar({ name: 'Project A', square: true }),
  avatar({ name: 'Project B', square: true, color: 'success' }),
)

Colors

An avatar with no image takes a soft palette background.

PNSWD
stack({ direction: 'row', gap: 'md', align: 'center', wrap: true },
  avatar({ name: 'Primary', color: 'primary' }),
  avatar({ name: 'Neutral', color: 'neutral' }),
  avatar({ name: 'Success', color: 'success' }),
  avatar({ name: 'Warning', color: 'warning' }),
  avatar({ name: 'Danger', color: 'danger' }),
)

Icons and other content

Children override the initials, for an icon or a single character.

?
stack({ direction: 'row', gap: 'md', align: 'center' },
  avatar({ color: 'neutral' },
    icon('user'),
  ),
  avatar({ color: 'primary' }, '?'),
)

Groups

avatarGroup() overlaps its children and collapses anything past max into a count.

ALGHAT
ALGHAT+3
ALGH+1
stack({ gap: 'md' },
  avatarGroup(
    avatar({ name: 'Ada Lovelace' }),
    avatar({ name: 'Grace Hopper' }),
    avatar({ name: 'Alan Turing' }),
  ),
  avatarGroup({ max: 3 },
    avatar({ name: 'Ada Lovelace' }),
    avatar({ name: 'Grace Hopper' }),
    avatar({ name: 'Alan Turing' }),
    avatar({ name: 'Katherine Johnson' }),
    avatar({ name: 'Barbara Liskov' }),
    avatar({ name: 'Margaret Hamilton' }),
  ),
  avatarGroup({ max: 2, size: 'sm' },
    avatar({ name: 'Ada Lovelace', size: 'sm' }),
    avatar({ name: 'Grace Hopper', size: 'sm' }),
    avatar({ name: 'Alan Turing', size: 'sm' }),
  ),
)

In a list

  • AL
    Ada Lovelace
    Pushed 3 commits to main
  • GH
    Grace Hopper
    Opened a pull request
list(
  listItem({
    start: avatar({ name: 'Ada Lovelace', size: 'sm' }),
    title: 'Ada Lovelace',
    description: 'Pushed 3 commits to main',
  }),
  listItem({
    start: avatar({ name: 'Grace Hopper', size: 'sm', color: 'success' }),
    title: 'Grace Hopper',
    description: 'Opened a pull request',
  }),
)

Props

PropTypeDefaultDescription
namestringUsed for the initials, the title and the image alt fallback.
srcstringImage to show instead of initials.
altstringImage alt text; falls back to name.
size'sm' | 'md' | 'lg''md'Diameter, and the font size of the initials.
squarebooleanfalseRounded rectangle instead of a circle.
color'primary' | 'neutral' | 'success' | 'warning' | 'danger'Palette for the initials background.

avatarGroup() takes max — how many to show before collapsing the rest into a count — and size, which is only used for that count.