Avatar
A circular picture of a person: their image, an icon, or the initials of their name.
- **Image**: image (URL string, element or { src, alt } object) or src. If the image fails to load, the avatar falls back to icon, the initials or a person glyph, with their background; a new image is tried again. A server-rendered image that failed before hydration is detected after mount (settled without a natural size, confirmed by decode()).
- **Accessible name**: an image uses name (whitespace collapsed) as its alt, or '' when the name is blank. Without an image (none given, or it failed to load) the avatar is role="img" with aria-label={name} (without a name: the image slot's own alt) and the initials/icon are hidden; without either (and without aria-label/aria-labelledby) it is decorative (aria-hidden). A consumer aria-label, aria-labelledby or role (other than presentation/none) puts the name on the avatar visual, and an image inside it gets alt="". decorative hides it in every mode. aria-describedby, aria-description and aria-details go to the element that carries the name: the <img> when a non-blank alt names it, otherwise the avatar visual (never an alt="" image).
- **Badge**: badge renders at the bottom end corner (logical, RTL-safe) as a sibling of the avatar visual, so a PresenceBadge keeps its own name. With a badge, ref, className and the rest props go to the outer wrapper.
Examples
Default
export const Default: Story = {};With Image
export const WithImage: Story = {
args: {
src: 'data:image/svg+xml,%3Csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20viewBox=%270%200%2064%2064%27%3E%3Crect%20width=%2764%27%20height=%2764%27%20fill=%27%23c8c6c4%27/%3E%3Ccircle%20cx=%2732%27%20cy=%2725%27%20r=%2711%27%20fill=%27%23605e5c%27/%3E%3Cpath%20d=%27M12%2064a20%2020%200%200%201%2040%200z%27%20fill=%27%23605e5c%27/%3E%3C/svg%3E',
},
};Image Fallback
export const ImageFallback: Story = {
args: {
src: 'data:image/png;base64,broken',
},
};With Name
export const WithName: Story = {
args: {
name: 'John Smith',
size: 'large',
},
};With Icon
export const WithIcon: Story = {
args: {
name: undefined,
icon: <PersonGlyph />,
'aria-label': 'Guest',
},
};With Badge
export const WithBadge: Story = {
args: {
size: 'large',
badge: <PresenceBadge status="available" />,
},
};Sizes
export const Sizes: Story = {
render: (args) => (
<div className="flex items-center gap-2">
{SIZES.map((size) => (
<Avatar key={size} {...args} size={size} />
))}
</div>
),
};Numeric Sizes
export const NumericSizes: Story = {
render: (args) => (
<div className="flex items-end gap-2">
{NUMERIC_SIZES.map((size) => (
<Avatar key={size} {...args} size={size} aria-label={`${args.name}, ${size} pixels`} />
))}
</div>
),
};Shapes
export const Shapes: Story = {
args: { size: 56, badge: <PresenceBadge status="busy" /> },
render: (args) => (
<div className="flex items-center gap-3">
<Avatar {...args} shape="circular" aria-label="Jane Doe, circular" />
<Avatar {...args} shape="square" aria-label="Jane Doe, square" />
</div>
),
};Colors
export const Colors: Story = {
render: (args) => (
<div className="flex flex-wrap items-center gap-2">
<Avatar {...args} color="neutral" aria-label="Neutral" />
<Avatar {...args} color="brand" aria-label="Brand" />
{NAMED_COLORS.map((color) => (
<Avatar key={color} {...args} color={color} aria-label={color} />
))}
</div>
),
};Colorful From Name Or Id
export const ColorfulFromNameOrId: Story = {
render: (args) => (
<div className="flex items-center gap-2">
{PEOPLE.map((name) => (
<Avatar key={name} {...args} name={name} color="colorful" />
))}
<Avatar {...args} name="Renamed Person" color="colorful" idForColor="user-1042" />
</div>
),
};Active And Inactive
export const ActiveAndInactive: Story = {
args: { size: 56 },
render: (args) => (
<div className="flex items-center gap-4">
{(['ring', 'ring-shadow', 'shadow', 'glow'] as const).map((appearance) => (
<Avatar
key={appearance}
{...args}
active="active"
activeAppearance={appearance}
aria-label={`Active, ${appearance}`}
/>
))}
<Avatar {...args} active="inactive" aria-label="Inactive" />
</div>
),
};Initials
export const Initials: Story = {
render: (args) => (
<div className="flex items-center gap-2">
{['Ada Lovelace', 'Plato', 'Mary-Jane O’Neil', 'Ola Nordmann (UiO)'].map((name) => (
<Avatar key={name} {...args} name={name} color="colorful" />
))}
<Avatar {...args} name="Custom" initials="XY" />
</div>
),
};Props
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
src | string | No | URL of the avatar image. When it fails to load (also before hydration, for server-rendered markup), the avatar falls back to its icon or initials; a new | |
name | string | No | Full name of the person. It names the avatar for assistive technology (the image | |
size | 'extra-small' | 'small' | 'medium' | 'large' | 'extra-large' | 16 | 20 | 24 | 28 | 32 | 36 | 40 | 48 | 56 | 64 | 72 | 96 | 120 | 128 | No | 'medium' | Size of the avatar: a named size ( |
shape | 'circular' | 'square' | No | 'circular' | Shape of the avatar. Without it, an Avatar in the |
color | 'neutral' | 'brand' | 'colorful' | 'red' | 'pumpkin' | 'gold' | 'forest' | 'teal' | 'blue' | 'navy' | 'lavender' | 'purple' | 'magenta' | 'brown' | 'steel' | No | 'brand' | Color of the avatar when it shows initials: |
active | 'active' | 'inactive' | 'unset' | No | 'unset' | Whether the person is active: |
activeAppearance | 'ring' | 'ring-shadow' | 'shadow' | 'glow' | No | 'ring' | How an |
idForColor | string | No | A stable id (a user id, say) that picks the color of | |
initials | Slot<'span'> | No | The initials shown when there is no image and no icon, instead of the ones computed from | |
icon | Slot<'span'> | No | Icon shown instead of the initials when there is no image. Rendered in an | |
image | Slot<'img'> | No | Custom image. Accepts a URL string (treated like | |
badge | Slot<'span'> | No | Badge shown at the bottom end corner, e.g. | |
decorative | boolean | No | false | Hides the avatar visual from assistive technology ( |
ref | React.Ref<HTMLSpanElement> | No | Ref to the root | |
slotProps | { visual?: SlotPart<'span'> } | No | Props for the element the avatar draws, by part, merged into the part's own: your classes after the part's (yours win a conflict), your styles over its styles, your attributes and handlers added (yours run first), your ref beside its ref, and your ids added to its |
Any other prop is passed to the element it renders (HTMLSpanElement).
Parts
visual
Stable class names
| Part | Class |
|---|---|
root | wave-avatar |
visual | wave-avatar__visual |
image | wave-avatar__image |
icon | wave-avatar__icon |
initials | wave-avatar__initials |
badge | wave-avatar__badge |