Avatar
Introduction
Section titled “Introduction”A picture of a person or entity with fallbacks: the image, then initials from the name, then an optional icon. Avatar is one image to assistive technology (role="img"), named after the person and, when shown, their presence status (“Ada Lovelace, Away”). Set decorative when the name is printed next to it. The component never fetches anything itself; only its image element loads src.
- Image with fallbackShows the photo, then initials, then an icon if the image fails.
- Presence statusOnline, away, busy, and offline indicators with accessible text.
- Sizes and shapesFive sizes in circle or square shape.
- Decorative modeHide it from assistive technology when the name is already shown.
Use it for
- Identifying people in lists, comments, assignments, and headers.
- Showing presence (online, away, busy, offline) next to a person.
Use something else for
- Several people on one record: use Avatar Group.
- Content images or logos that are not identities: use an img element.
Anatomy
<span class="aui-avatar aui-avatar--{size} aui-avatar--{shape} aui-avatar--{image|initials|icon}" role="img" aria-label="name[, status]"> <span class="aui-avatar__visual" aria-hidden="true"> <img class="aui-avatar__image" alt=""> | initials | icon </span> <span class="aui-avatar__status" aria-hidden="true"></span> (presence dot, optional)</span>Live example
Section titled “Live example”Use the bar above each frame to switch theme, density, direction, and locale.
Avatar in the Team profile showcase
Section titled “Avatar in the Team profile showcase”The part of the Team profile showcase that uses Avatar. Change its options, use it with the keyboard, and watch the event log; the link in the frame opens the full showcase. The bar above the frame switches theme, density, direction, and locale.
Showcase source
// Layout and content showcase: a team profile page built with the layout primitives, cards,// typography, badges, keyboard keys, avatars, an avatar group, and a tag group.import { Avatar } from '@absoluteui/components/avatar';import { AvatarGroup } from '@absoluteui/components/avatar-group';import { Badge } from '@absoluteui/components/badge';import { Card } from '@absoluteui/components/card';import { Kbd } from '@absoluteui/components/kbd';import { Container, Divider, Flex, Grid, Stack } from '@absoluteui/components/layout';import { TagGroup, type TagGroupChangeDetail } from '@absoluteui/components/tag-group';import { Heading, Link, Text } from '@absoluteui/components/typography';import { annotate, choice, createShowcase, hostIn, toggle } from './kit.js';
const sc = createShowcase({ title: 'Team profile', description: 'Layout primitives and content components composing a real page. Resize the frame: the grid reflows.',});
const page = hostIn(sc.stage);Container.apply(page, { size: 'lg' });const stack = Stack.apply(page, { gap: 6 });
// Each block of the page declares its components (focus mode shows a component's own blocks).// Header.const header = annotate(hostIn(page), ['layout', 'avatar', 'typography', 'badge']);const headerFlex = Flex.apply(header, { gap: 4, align: 'center', wrap: true });const avatar = Avatar.create(hostIn(header), { name: 'Platform Engineering', size: 'xl', shape: 'square', icon: 'code' });const titles = hostIn(header);Stack.apply(titles, { gap: 1 });titles.append(Heading.create(2, 'Platform Engineering', { size: 3 }), Text.create('Builds and runs the internal developer platform.', { tone: 'muted' }));const badges = hostIn(titles);Flex.apply(badges, { gap: 2, wrap: true });const badgeList = [ Badge.create(hostIn(badges), { label: 'Hiring', tone: 'success', dot: true }), Badge.create(hostIn(badges), { label: '14 members', tone: 'neutral' }), Badge.create(hostIn(badges), { label: 'On call', tone: 'warning', variant: 'outline', icon: 'clock' }),];
// Members grid of cards.const members = annotate(hostIn(page), ['layout', 'card', 'avatar', 'typography']);Stack.apply(members, { gap: 4 });members.append(Divider.create({ label: 'Members' }));const grid = hostIn(members);const gridLayout = Grid.apply(grid, { columns: 'auto', minColumnWidth: '14rem', gap: 4 });const MEMBERS = [ { name: 'Ada Kowalski', role: 'Engineering lead', status: 'online' }, { name: 'Bruno Silva', role: 'Site reliability', status: 'busy' }, { name: 'Chen Wei', role: 'Backend engineer', status: 'away' }, { name: 'Divya Nair', role: 'Frontend engineer', status: 'offline' },] as const;const cards = MEMBERS.map((m) => { const content = document.createElement('div'); Flex.apply(content, { gap: 3, align: 'center' }); Avatar.create(hostIn(content), { name: m.name, status: m.status, size: 'md' }); const who = document.createElement('div'); who.append(Text.create(m.name, { strong: true }), Text.create(m.role, { tone: 'muted', size: 'sm' })); content.append(who); return Card.create(hostIn(grid), { content, variant: 'raised', headingLevel: 3 });});
// Skills and shortcuts.const details = hostIn(page);Grid.apply(details, { columns: 'auto', minColumnWidth: '16rem', gap: 4 });const skillsBody = document.createElement('div');const tags = TagGroup.create(hostIn(skillsBody), { label: 'Team skills', removable: true, selection: 'multiple', value: ['kubernetes'], items: [ { value: 'kubernetes', label: 'Kubernetes' }, { value: 'terraform', label: 'Terraform' }, { value: 'go', label: 'Go' }, { value: 'observability', label: 'Observability' }, { value: 'security', label: 'Security' }, ],});annotate(Card.create(hostIn(details), { title: 'Skills', content: skillsBody, headingLevel: 3 }).host, ['layout', 'card', 'tag-group']);
const shortcutsBody = document.createElement('dl');shortcutsBody.className = 'sc-shortcuts';for (const [keys, text] of [ ['Mod+K', 'Search'], ['Mod+Shift+P', 'Command palette'], ['?', 'Show shortcuts'],] as const) { const dt = document.createElement('dt'); Kbd.create(dt, { hotkey: keys }); const dd = document.createElement('dd'); dd.textContent = text; shortcutsBody.append(dt, dd);}annotate(Card.create(hostIn(details), { title: 'Shortcuts', content: shortcutsBody, headingLevel: 3 }).host, ['layout', 'card', 'kbd']);
const footer = annotate(hostIn(page), ['layout', 'avatar-group', 'typography']);Flex.apply(footer, { gap: 3, align: 'center', justify: 'between', wrap: true });const group = AvatarGroup.create(hostIn(footer), { label: 'Recently active', max: 4, items: ['Ada Kowalski', 'Bruno Silva', 'Chen Wei', 'Divya Nair', 'Emeka Obi', 'Farah Haddad', 'Grace Liu'].map((name) => ({ name })) });footer.append(Link.create({ href: 'https://example.com/platform', text: 'Team handbook', external: true }));
sc.listen(tags.host, ['aui-change', 'aui-remove'], 'tags');tags.host.addEventListener('aui-change', (e) => { sc.log('selected skills', (e as CustomEvent<TagGroupChangeDetail>).detail.value);});
choice( sc, 'Spacing', [ { value: '4', label: 'Compact' }, { value: '6', label: 'Comfortable' }, { value: '10', label: 'Spacious' }, ], '6', (g) => { const gap = Number(g) as 4 | 6 | 10; stack.update({ gap }); gridLayout.update({ gap: gap === 10 ? 8 : 4 }); headerFlex.update({ gap: gap === 10 ? 6 : 4 }); }, ['layout'],);choice( sc, 'Avatar shape', [ { value: 'square', label: 'Square' }, { value: 'circle', label: 'Circle' }, ], 'square', (shape) => { avatar.update({ shape }); group.update({ shape }); }, ['avatar', 'avatar-group'],);toggle(sc, 'Outline badges', false, (outline) => { for (const b of badgeList) b.update({ variant: outline ? 'outline' : 'subtle' });}, ['badge']);toggle(sc, 'Sunken cards', false, (sunken) => { for (const c of cards) c.update({ variant: sunken ? 'sunken' : 'raised' });}, ['card']);Initials, presence, sizes, and shapes
Section titled “Initials, presence, sizes, and shapes”import { Avatar, type AvatarSize } from '@absoluteui/components/avatar';
const row = document.createElement('p');document.body.append(row);const people: [string, AvatarSize][] = [['Ada Lovelace', 'xs'], ['Grace Hopper', 'sm'], ['Alan Turing', 'md'], ['Barbara Liskov', 'lg'], ['Edsger Dijkstra', 'xl']];for (const [name, size] of people) { const host = document.createElement('span'); row.append(host, ' '); Avatar.create(host, { name, size, status: size === 'md' ? 'online' : null });}const team = document.createElement('span');row.append(team);Avatar.create(team, { name: 'Platform team', shape: 'square', status: 'busy' });Decorative avatar next to a printed name
Section titled “Decorative avatar next to a printed name”import { Avatar } from '@absoluteui/components/avatar';
const author = document.createElement('p');const picture = document.createElement('span');author.append(picture, ' Grace Hopper commented');document.body.append(author);// The name is printed next to the avatar, so the avatar is not announced again.Avatar.create(picture, { name: 'Grace Hopper', size: 'sm', decorative: true });Install and start
Section titled “Install and start”npm install @absoluteui/components @absoluteui/core @absoluteui/themeRegistry setup, the theme stylesheet, and the Content Security Policy are covered in Installation.
import { Avatar } from '@absoluteui/components/avatar';import '@absoluteui/components/avatar/style.css';First use
Section titled “First use”import { Avatar } from '@absoluteui/components/avatar';import '@absoluteui/components/avatar/style.css';
const host = document.querySelector<HTMLElement>('#me');if (host) Avatar.create(host, { name: 'Grace Hopper', size: 'sm', status: 'busy' });More usage
import { Avatar } from '@absoluteui/components/avatar';
const host = document.querySelector<HTMLElement>('#owner');if (host) { const owner = Avatar.create(host, { name: 'Ada Lovelace', src: '/avatars/ada.webp', status: 'online' }); owner.update({ status: 'away' });}Using Angular? See Avatar for Angular.
API reference
Section titled “API reference”Factory
Section titled “Factory”Avatar.create(host: HTMLElement, options: AvatarOptions): AvatarGlobal configuration key: avatar (see Configuration).
Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
name |
string |
Accessible name and source of the initials. Required. | |
src |
string | null |
Image URL: http(s), relative, blob:, or a base64 PNG, JPEG, GIF, WebP, or AVIF data URL. | |
icon |
IconRef | null |
Icon shown when the name yields no initials. | |
status |
'online' | 'away' | 'busy' | 'offline' | null |
Presence dot; its name is part of the accessible name. | |
decorative |
boolean |
"false" |
Hide from assistive technology when the name is shown next to it. |
size |
'xs' | 'sm' | 'md' | 'lg' | 'xl' |
"md" |
Avatar size. Globally configurable. |
shape |
'circle' | 'square' |
"circle" |
Avatar shape. Globally configurable. |
locale |
string |
"en-US" |
Locale of status names and initials casing. Globally configurable. Inherited from common configuration. |
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
host |
HTMLElement |
The host element (receives role, label, and classes). |
name |
string |
Current name. |
shows |
'image' | 'initials' | 'icon' |
What is currently shown. |
options |
Readonly<AvatarOptions> |
Current options. |
Methods
Section titled “Methods”| Method | Description |
|---|---|
update(options: Partial<AvatarOptions>): void |
Merge and apply options; a new src is loaded again even after a failure. |
destroy(): void |
Remove rendering, attributes, classes, and subscriptions. |
CSS classes
Section titled “CSS classes”All rules live in the aui.components cascade layer, so application styles override them without specificity battles.
| Class | Purpose |
|---|---|
aui-avatar |
Host. |
aui-avatar--xs | --sm | --md | --lg | --xl |
Size modifiers. |
aui-avatar--circle | --square |
Shape modifiers. |
aui-avatar--image | --initials | --icon |
What is shown. |
aui-avatar--status-online | -away | -busy | -offline |
Presence modifiers. |
aui-avatar__visual |
Image, initials, or icon (aria-hidden). |
aui-avatar__image |
The img element. |
aui-avatar__status |
Presence dot (aria-hidden). |
Design tokens
Section titled “Design tokens”Tokens this stylesheet reads (verified in CI). Override them in a theme or with the Theme Designer.
--aui-border-width | --aui-color-error-fg | --aui-color-success-fg | --aui-color-surface | --aui-color-surface-sunken | --aui-color-text | --aui-color-text-muted | --aui-color-warning-fg | --aui-font-family-sans | --aui-font-weight-semibold | --aui-radius-md | --aui-radius-pill
TypeScript definitions
type AvatarSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';type AvatarShape = 'circle' | 'square';type AvatarStatus = 'online' | 'away' | 'busy' | 'offline';interface AvatarConfig { size: AvatarSize; shape: AvatarShape }interface AvatarOptions extends Partial<AvatarConfig> { name: string; src?: string | null; icon?: IconRef | null; status?: AvatarStatus | null; decorative?: boolean; locale?: string;}function avatarInitials(name: string, locale?: string): string;function isSafeImageSrc(value: unknown): value is string;Accessibility and performance
Section titled “Accessibility and performance”Accessibility
Section titled “Accessibility”Pattern: Image with a text alternative: role=img on the host, aria-label with the name and presence status.
Checked on every docs build: the showcase passes axe (WCAG 2.2 A and AA rules) in the default, dark, and high-contrast themes and right to left; the playground loads without errors and passes axe before and after every on/off option is switched, with no Content Security Policy violations.
Keyboard
Section titled “Keyboard”| Key | Context | Action |
|---|---|---|
| None | Any | Not focusable; read in document order by assistive technology. |
| Element | Role |
|---|---|
| host | img (absent when decorative) |
| visual and status dot | none (aria-hidden=true) |
| img | presentation (alt is empty; the host carries the name) |
ARIA attributes
Section titled “ARIA attributes”| Attribute | Element | Value |
|---|---|---|
aria-label |
host | the name, or ‘name, status’ when a status is shown |
aria-hidden |
host when decorative; visual and status dot always | true |
Never receives or moves focus.
WCAG 2.2 success criteria addressed
Section titled “WCAG 2.2 success criteria addressed”| Criterion | Level | Note |
|---|---|---|
| 1.1.1 Non-text Content | A | |
| 1.4.1 Use of Color | A | |
| 1.4.3 Contrast (Minimum) | AA | |
| 1.4.11 Non-text Contrast | AA |
Automated test results: Accessibility and compliance.
Notes and known caveats
Section titled “Notes and known caveats”- Presence is part of the accessible name and has a distinct shape per status, not only a color.
- Set decorative when the person’s name is printed next to the avatar, so it is not read twice.
- Manual screen-reader verification (NVDA, JAWS, VoiceOver) is pending.
Performance
Section titled “Performance”| Import cost | Minified | gzip | brotli | CSS brotli |
|---|---|---|---|---|
@absoluteui/components/avatar |
33.9 kB | 11.9 kB | 10.5 kB | 0.6 kB |
Measured at build time, including every AbsoluteUI module the component pulls in. No third-party runtime dependencies.
| Budget (enforced in CI) | Limit |
|---|---|
| Avatar.create, per instance | < 1 ms average in headless Chromium |
Tested scale: Unit-tested per instance; one avatar per row in lists of thousands is expected.
Constant work per render. Images load lazily and decode asynchronously.
Measured run times: Performance.
Details
Section titled “Details”States
Shows image, initials, or icon; five sizes; circle or square; presence online, away, busy, offline; decorative.
State transitions
| From | Trigger | To |
|---|---|---|
| image | the image fails to load | initials (or icon); the same URL is not retried |
| any | update({ src }) with a new URL |
image |
| any | update({ status }) |
new dot and accessible name |
| any | destroy() |
host restored to empty |
Accessibility notes
- Presence is in the accessible name and each status has its own dot shape (busy has a bar, offline is hollow), so it does not depend on color.
- Set
decorativewhen the name is printed beside the avatar, so screen readers do not read it twice. - The e2e axe run covers three themes; manual screen-reader verification is pending.
Responsive behavior
Fixed size per size step; initials and the dot scale with it.
Right-to-left
The status dot sits at the bottom inline-end corner, mirrored in RTL.
Theming
Initials pair --aui-avatar-fg with --aui-avatar-bg (contrast gate). Forced-colors mode draws a CanvasText boundary and dot.
Global configuration
configureAbsoluteUI({ components: { avatar: { size: 'sm', shape: 'square' } } });Component configuration
Instance options override global and theme configuration; configuration changes re-render existing avatars.
Icons
icon: any registered icon, shown only when the name has no letters or digits.
Security
src is validated with isSafeImageSrc: http(s), relative, blob:, or base64 data URLs of raster images. javascript:, SVG data URLs, and other schemes are rejected with AVATAR_OPTIONS. The image loads lazily with referrerpolicy="no-referrer". The name is rendered with textContent.
Data handling
Only the image element loads src, without a referrer. No persistence, other network access, or telemetry.
Supported data scale
One avatar per row in lists of thousands of rows (with virtualization where the list itself needs it).
Edge cases
- Initials take the first letter or digit of the first and last word (“Jean-Luc Picard” gives JP); a single word gives one initial.
- A name without letters or digits shows the icon, or else its first character.
- A failed image is not retried until
srcchanges. - Safe in renderers that discard nodes without calling
destroy(), such as Data Table cells: the configuration subscription holds the instance weakly, so a discarded avatar is released.
Errors
| Code | Category | Cause |
|---|---|---|
AVATAR_OPTIONS |
configuration | Missing or blank name, unsafe src, unknown status, or non-boolean decorative. |
ICON_UNKNOWN |
configuration | Unknown icon. |
CFG_INVALID_VALUE / CFG_UNKNOWN_OPTION |
configuration | Invalid size, shape, or locale configuration. |
Invalid options throw before the host is modified; an invalid update() leaves the previous state intact.
Known limitations
- Initials follow word order; names written family-name-first show those initials in that order.
- Manual screen-reader verification is pending.
Unsupported scenarios
- Uploading or cropping images.
- Clickable avatars: wrap the avatar in a link or button that carries the name.
(c) 2026 Kasadara Technology Solutions Pvt Ltd. AbsoluteUI is free to use under the AbsoluteUI Free Use License; it is not open source.