Avatar v0.1.0 Data display

Image avatar with automatic initials fallback when the image is missing or fails to load.

import { Avatar } from "latticeui-react";

Examples

Sizes and fallback

When src is missing or fails to load, initials derived from name are shown.

ALGHATBroken Image
Show code
<Avatar name="Ada Lovelace" size="sm" />
<Avatar name="Grace Hopper" />
<Avatar name="Alan Turing" size="lg" />
<Avatar name="Broken Image" src="/does-not-exist.png" />

Anatomy

These data-part attributes are a versioned public API - style and test against them; they will not change in a minor release.

PartElementStable selector
rootspan[data-scope="avatar"][data-part="root"]
imageimg[data-scope="avatar"][data-part="image"]
fallbackspan[data-scope="avatar"][data-part="fallback"]

Props

PropTypeDefaultDescription
name *stringUsed for alt text and fallback initials.
srcstring
size"sm" | "md" | "lg""md"

Accessibility

Roles: img (fallback)

Styling

Override styles by targeting the stable selectors below from any unlayered CSS - it always beats the library's @layer latticeui styles, no !important needed.

[data-scope="avatar"][data-part="root"] {
  /* your overrides */
}

Component tokens: --avatar-size

State attributes: data-size