Avatar Text
Avatar text is a <span> element rendered inside an Avatar as a fallback when no image is available or the image fails to load. It displays the user's initials or short text within the circular avatar frame.
Avatar text is a <span> element rendered inside an Avatar as a fallback when no image is available or the image fails to load. It displays the user's initials or short text within the circular avatar frame.
<span class="avatar-text">JD</span><script lang="ts">
import Avatar from '../Avatar/Avatar.svelte';
import AvatarText from './AvatarText.svelte';
</script>
<Avatar alt="Jane Doe">
<AvatarText>JD</AvatarText>
</Avatar>
// In your Svelte component:
import AvatarText from "lily-design-system-svelte-headless/components/AvatarText/AvatarText.svelte";
<AvatarText>
<!-- content -->
</AvatarText>
Initials fallback inside an Avatar:
<Avatar alt="Dr Sarah Mitchell">
<AvatarText>SM</AvatarText>
</Avatar>
Single-character initial for compact display:
<Avatar alt="Bob">
<AvatarText>B</AvatarText>
</Avatar>
Use AvatarText inside an Avatar to show initials when a photo is unavailable. The parent Avatar typically manages rendering this component automatically when the src is missing or fails. Common scenarios include placeholder avatars, anonymous users, and image load failures.
<AvatarText>JD</AvatarText>
| Prop | Type | Default | Description |
|---|---|---|---|
children | slot | (required) | Initials or short text to display |
...restProps | HTML attributes | Additional attributes spread onto the <span> element |
Various initials:
<Avatar alt="Alice Smith">
<AvatarText>AS</AvatarText>
</Avatar>
<Avatar alt="Bob">
<AvatarText>B</AvatarText>
</Avatar>
aria-hidden="true" when inside an Avatar, since the parent's aria-label already provides the accessible nameThis component provides a <span> element for displaying initials text with zero visual styling. The consumer is responsible for all CSS including font size, font weight, text color, text alignment, and positioning within the avatar container.
The consumer provides all CSS styling. The component renders with a .avatar-text class for targeting. No default styles are included — this is a fully headless component.
<span> element with class avatar-textaria-hidden="true" when inside an Avatar, since the parent's aria-label already provides the accessible namearia-hidden="true" to prevent duplicate announcements since the parent provides the accessible label.<span> element with class avatar-textrestProps onto the root element for consumer customizationAvatarText is a child component within the Avatar composition pattern:
role="img" and aria-label.<img> element for the user's photo (when available).<span> fallback displaying initials or short text.<Avatar alt="Jane Doe">
<AvatarText>JD</AvatarText>
</Avatar>
avatar — an avatar indicator that shows an avatar image or avatar textavatar-image — an avatar indicator inside image such as a user photoavatar-group — a group of avatar componentsGenerated from this component's canonical metadata — the machine-checked source the implementations are held to.
aria-hidden="true" when inside an Avatar, since the parent's aria-label already provides the accessible name| Prop | Type | Default | Description |
| -------------- | --------------- | ---------- | ------------------------------------------------------ |
| children | slot | (required) | Initials or short text to display |
| ...restProps | HTML attributes | | Additional attributes spread onto the <span> element |