Create

General

Avatar

Copy page View as Markdown Open in ChatGPT Open in Claude

An image element with a fallback for representing the user.

Usage#

app.component.ts
import { WDS_AVATAR } from '@wds/angular/avatar';

Examples#

Default#

src sets the image and alt names the avatar. The content (initials) is the fallback, shown until the image loads.

OC

Fallback#

Without src, or when the image fails to load, the avatar shows its content: initials or an icon. With alt the avatar is still read by its name, not by the initials.

MS

Badge#

wds-avatar-badge adds a dot in the bottom corner; change its color with a background class. A badge is decorative, so put the status in alt as well.

CN

Badge with icon#

An icon inside the badge. On the sm avatar the icon is hidden.

PP

Avatar group#

wds-avatar-group overlaps the avatars and gives each a ring in the page background color.

OC LR ER

Avatar group count#

wds-avatar-group-count at the end of the group shows how many people are not shown.

OC LR ER +3

Avatar group with icon#

The count can hold an icon instead of a number; name it with aria-label.

OC LR ER

Size#

size is sm, default or lg. In a group, give wds-avatar-group-count the same size as the avatars. --wds-avatar-size sets any other size.

OC OC OC
OC LR +3

An avatar inside a wds-button as a wds-dropdown trigger. The button has the label, so the avatar does not need alt.

OC My account Profile Billing Settings Log out

API References#

wds-avatar#

An image that represents a user, with a fallback (initials or an icon) shown until the image loads or when it fails.

Attributes

AttributeTypeDefaultDescription
srcstring | undefinedImage address. Without it (or when it fails) the fallback is shown.
altstring''Alternative text: the name of the avatar for screen readers, also when the fallback is shown.
sizeWdsAvatarSize'default'Size: sm (24px), default (32px) or lg (40px).

Slots

SlotDescription
(default)Fallback: initials or an icon, shown without src, while the image loads and when it fails.
badgeA wds-avatar-badge in the bottom corner.

CSS parts (::part)

PartDescription
rootThe circle.
imageThe <img>.
fallbackThe fallback container.

CSS custom properties

PropertyDescription
--wds-avatar-sizeCustom size (instead of size).
--wds-avatar-font-sizeSize of the fallback text (with a custom --wds-avatar-size).
--wds-avatar-radiusCorner radius (default a circle), e.g. var(--wds-radius-lg) for a rounded square.

wds-avatar-badge#

A status dot in the bottom corner of wds-avatar (goes to its badge slot by itself). Change the color with a background class, e.g. bg-green-600. An icon inside is hidden on the sm avatar.

Slots

SlotDescription
(default)Optional icon (<svg>).

wds-avatar-group#

Overlapping avatars, each with a ring in the page background color. End it with wds-avatar-group-count.

Slots

SlotDescription
(default)wds-avatar elements and an optional wds-avatar-group-count.

CSS parts (::part)

PartDescription
baseThe container.

CSS custom properties

PropertyDescription
--wds-avatar-group-overlapHow much each avatar covers the previous one (default 8px).

wds-avatar-group-count#

The last circle of wds-avatar-group: the number of the remaining people (e.g. +3) or an icon.

Attributes

AttributeTypeDefaultDescription
sizeWdsAvatarSize'default'Size: match the avatars of the group.

Slots

SlotDescription
(default)Text or an icon (<svg>).

CSS parts (::part)

PartDescription
rootThe circle.

CSS custom properties

PropertyDescription
--wds-avatar-sizeCustom size (instead of size).
--wds-avatar-radiusCorner radius (default a circle).

Accessibility#

Screen reader#

With alt the avatar is one image (role="img") named by alt, both with the photo and with the fallback. Without alt screen readers read the fallback text (e.g. the initials).

Inside a named control (a button with label, a link with text) leave alt out, so the name is not read twice.

wds-avatar-badge is decorative: describe the status in alt, e.g. Mira Stone, online.

An icon in wds-avatar-group-count needs role="img" and aria-label; a number such as +3 is read as text.

Keyboard support#

Avatars are not focusable and have no keyboard interaction. Inside a button or a link they follow its keyboard support.

Footer