Avatar

Material Design 3-styled avatar web component (lit-material-avatar): image, initials, or icon fallback.

  • 1.3 KB gzipped
  • @lit-material/avatar 0.0.3
  • Renders on the server

Example

Install

npm install @lit-material/avatar @lit-material/tokens
import "@lit-material/avatar";

Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide

API

<lit-material-avatar>

A user/entity avatar — an image, falling back to initials text, falling back to a slotted icon (or a built-in default person icon if nothing's slotted). Only one of those three actually renders at a time; there's no combining them.

Properties

PropertyAttributeTypeDefaultDescription
srcsrcstring""
altaltstring""Accessible name for what/who this avatar represents — also used as the image's alt text.
initialsinitialsstring""Short fallback text (typically 1-2 characters) shown when there's no image.
sizesizeAvatarSize"medium"
shapeshapeAvatarShape"circle"

Slots

SlotDescription
defaultA custom icon, shown when there's no src (or it failed to load) and no initials. Falls back to a default person icon if left empty.

CSS parts

PartDescription
avatarThe container (background, size, shape).
imageThe <img> element, when src is set and loads.
initialsThe initials text, when shown.

Source on GitHub npm