Avatar

A profile picture, initials, or icon.

LT

Anatomy

<UiAvatarRoot>
  <UiAvatarImage src="" />
  <UiAvatarFallback>LT</UiAvatarFallback>
</UiAvatarRoot>

Examples

Optimized and lazy-loaded images

By default, UiAvatarImage preloads src and renders the img only once it has loaded. That does not compose with <NuxtImg> or loading="lazy".

Pass keepMounted to render the image immediately and let it load in place. Only the image that is actually displayed is requested.

<UiAvatarRoot>
  <UiAvatarFallback>LT</UiAvatarFallback>
  <UiAvatarImage keep-mounted loading="lazy" src="/avatar.jpg" width="32" height="32" alt="" />
</UiAvatarRoot>
LT

Stacking

With keepMounted, the image and the fallback are both present until the image loads. The image is hidden from view until then (visibility, not display: none), so the fallback provides the visible initials.

Stack them in the same box and put UiAvatarImage after UiAvatarFallback. Both are positioned, so whichever comes later paints on top. Hide loading and failed images with data-loading and data-error. The second avatar below uses a missing file so the fallback stays.

LTLT

With keepMounted, the image is part of the server-rendered HTML and can start loading before hydration. A cached image shows immediately.

API reference

Root

The avatar frame. Renders a <span>. Pass color to tint the fallback wash and initials. The image is unchanged.

AttributeDescription
data-loadingPresent while the image is loading.
data-errorPresent when the image failed to load.

Root state imageLoadingStatus is idle, loading, loaded, or error.

Image

The picture. Renders an <img>. Preloads src unless keepMounted is set.

PropTypeDefaultDescription
srcstring—Image URL.
altstring''Accessible name. Prefer empty when the fallback already has initials.
widthnumber | string—Native width.
heightnumber | string—Native height.
keepMountedboolean—Keep the img in the DOM and load in place. Supports loading="lazy".

Emits loadingStatusChange with idle, loading, loaded, or error.

AttributeDescription
data-loadingPresent while the image is loading.
data-errorPresent when the image failed to load.
data-starting-stylePresent when the image begins animating in.
data-ending-stylePresent when the image is animating out.

Fallback

Shown when the image is missing, loading, or failed. Renders a <span>.

PropTypeDefaultDescription
delaynumber0Milliseconds to wait before showing the fallback.
AttributeDescription
data-loadingPresent while the image is loading.