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
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.
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.
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
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.
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.
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
- ALAda LovelacePushed 3 commits to main
- GHGrace HopperOpened 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
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | — | Used for the initials, the title and the image alt fallback. |
src | string | — | Image to show instead of initials. |
alt | string | — | Image alt text; falls back to name. |
size | 'sm' | 'md' | 'lg' | 'md' | Diameter, and the font size of the initials. |
square | boolean | false | Rounded 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.