Avatar

Represents a person or an organization with an image, their initials or an icon. Use it in lists, comments, menus and headers next to the name it stands for.

  • vig-avatar
Import
import { Avatar } from '@vigdx/ui/avatar';

Image, initials and icon

Pass src with an alt ; without an image the avatar shows the initials of name (first and last word), and with neither it shows the user icon.

Ada Lovelace

Sizes

size runs from xs to xl and is relative to the font size, so an avatar also scales with the text around it.

Shapes and variants

shape="square" suits organizations and projects; its corners follow --radius-avatar . variant tints the initials or icon fallback; icon swaps the fallback glyph.

Image fallback

When src fails to load the avatar falls back to the initials, then to the icon. A new src retries the image.

Image fails → initials of nameDeleted user No name → icon

Groups and profiles

Overlap avatars in a list for a member stack, with a ring in the page color to separate them. Next to a visible name, give the image an empty alt so the name is not read twice.

  • Ada Lovelace
  • Grace Hopper
  • Alan Turing
  • and 4 more members
Ada Lovelace[email protected]

Styling hooks

Internal elements carry a stable data-part and the component's data-scope; both are public API, so removing one is a breaking change. Select a part by both, e.g. [data-scope="avatar"][data-part="image"] { … }: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through aria-* and, where listed, a data-state; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other data-* attributes listed below (such as data-opening while an overlay animates) are API too. See Customizing.

Scope: [data-scope="avatar"]

Avatar styling hooks
Part Element data-state
image The <img> . —
initials The initials fallback. —
icon The icon fallback. —

Accessibility

  • With an image, alt is the accessible name: pass the person's name, or "" when the name is already shown next to the avatar. In dev mode the avatar warns when src has no alt.
  • The initials and icon fallbacks are exposed as role="img" labelled with the full name (or alt), never with the bare initials.
  • An avatar with neither image nor name is decorative and hidden from assistive technology.
  • Avatars are not interactive. To make one a link or menu trigger, wrap it in an <a> or <button> with its own accessible name.

API

Avatar

vig-avatar component

Image of a person or entity, falling back to initials from name and then to an icon when the image is missing or fails to load.

Avatar props
Name Type Default Description
altstring | undefinedundefined

Image alternative text — required with src ('' marks it decorative).

iconstring'user'

Registered icon shown when there is neither an image nor a name.

namestring | undefinedundefined

Full name: initials fallback and accessible name when no image shows.

shapeAvatarShape'circle'
—
sizeAvatarSize'md'
—
srcstring | undefinedundefined

Image URL; when missing or broken the avatar falls back to initials.

variantAvatarVariant'secondary'

Tone of the initials/icon fallback background.

Are you sure?