Skip to content

GhostAvatar ​

GhostAvatar shows a person or entity as a photo, with initials or slot content as the fallback when the photo is missing or fails to load. Import it from @ghostvue/themes for the default circular treatment. To style your own avatar, see Advanced: headless composition.

Team roster ​

Team roster

Member list showing a loaded photo, initials after a failed or missing photo, and an icon fallback, with role badges.

Core maintainers4 members
  • Ada LovelaceDesign Systems
    Owner
  • Grace HopperPlatform Infrastructure
    Maintainer
  • Alan TuringAccessibility QA
    Reviewer
  • Release botPublishes tagged builds
    Automation

Each row pairs a themed GhostAvatar from @ghostvue/themes with the member's name and a role GhostBadge. The four rows cover each fallback case:

  • Ada Lovelace has a photo that loads, so the avatar swaps to the <img>.
  • Grace Hopper has a photo URL that fails, so the initials stay.
  • Alan Turing has no photo, so the initials show from the first paint.
  • Release bot uses the fallback slot to show an icon instead of initials.

Rows stack on narrow previews and align on one line from 24rem, using @container ghost-demo.

Initials ​

Provide name to derive fallback initials, up to two characters ("Alan Turing" becomes "AT"). With no src, the fallback is shown immediately and the root has no data-state.

Loaded image ​

When src is set, the server and the first client paint show the fallback with data-state="loading". After mount, the component probes the URL. It swaps to the <img> and sets data-state="loaded" when the load succeeds, or keeps the fallback and sets data-state="error" when it fails, as for Grace Hopper above.

Set alt for the image's accessible name, or rely on name. Use alt="" when visible text, a parent link or a heading already names the person. The roster prints each name beside its avatar, so it marks the whole avatar aria-hidden="true" with alt="". That way neither the photo nor the fallback initials are read before the name.

Custom fallback ​

Use the fallback slot when initials are not enough, such as for a service account or a team. Hide decorative icon content with aria-hidden="true" and keep a real name nearby, as the release bot row does. If no visible name is nearby, put the name in visually hidden text.

Sizes ​

Themed

Size hooks on the @ghostvue/themes wrapper.

AKBOCN

@ghostvue/themes adds these to the headless GhostAvatar API, which it forwards:

PropTypeDefaultDescription
size'sm' | 'md' | 'lg'"md"Square dimensions. Default omits data-size.

Default md omits data-size.

Accessibility ​

The loaded <img> uses alt. Fallback initials are ordinary text. Do not add aria-label on the root when text or alt already names the entity. Wrap the avatar in a link or button when it should activate something.

SSR ​

SSR and hydration render the fallback first when src is set, avoiding mismatches from client-only load state. See avatar-spec.

When not to use it ​

  • As a button or link. Wrap with GhostButton or a native <a>.
  • For presence or counts. Compose badges outside the avatar.

Advanced: headless composition ​

For teams that bring their own design system, the headless GhostAvatar from @ghostvue/vue has the same image probe and fallback behavior with no visuals. These examples render unstyled; size, shape and color are your CSS.

Headless initials ​

Initials Headless

Fallback initials from name without an image URL.

JD

Headless image ​

Loaded image Headless

Client image probe after SSR-safe loading fallback.

IS

Headless fallback slot ​

Fallback slot Headless

Custom fallback when src is missing or fails to load.

Composable ​

useGhostAvatar returns rootProps, imageProps, initials, showImage and showFallback for a host you render yourself. The GhostAvatar reference page renders the avatar/composable example with its source.

deriveGhostAvatarInitials(name) is exported for tests and custom hosts.

Styling ​

  • class ghost-avatar
  • data-part: root, image, fallback
  • data-state: loading, loaded, error (omitted without src)
  • themed data-size: sm, md, lg

API ​

PropTypeDefaultDescription
altstring—img accessible name; defaults to name.
asGhostAvatarElement"span"Root host.
namestring—Initials source and default alt.
srcstring—Image URL. Load is confirmed after mount on the client.
SlotSlot propsDescription
fallback—Shown when the image is not displayed.

Template ref: element (HTMLElement | null).