Avatar <l-avatar>
Avatars are used to represent a user or entity with a profile image, initials, or icon fallback. Commonly used in headers, comments, contact lists, and user cards.
<l-avatar>Options
Image
Set src and name attributes. Falls back to initials if the image fails to load.
Code
<l-avatar
src="https://i.pravatar.cc/150?img=58"
name="John Doe"
></l-avatar>
<l-avatar
src="https://i.pravatar.cc/150?img=32"
name="Jane Smith"
></l-avatar>
<l-avatar
src="https://i.pravatar.cc/150?img=11"
name="Alex Chen"
></l-avatar>Initials
Set name to auto-extract initials, or slot custom text content.
Code
<l-avatar name="John Doe"></l-avatar>
<l-avatar name="Jane Smith"></l-avatar>
<l-avatar name="Alex"></l-avatar>
<l-avatar>+5</l-avatar>Custom colors
Set --color to a base color. Text is auto-derived via relative color syntax.
Code
<div class="flex items-end gap-3">
<l-avatar
style="--color: var(--color-red-200)"
name="Anna Bell"
></l-avatar>
<l-avatar
style="--color: var(--color-orange-200)"
name="Bob Chen"
></l-avatar>
<l-avatar
style="--color: var(--color-yellow-200)"
name="Cleo Dane"
></l-avatar>
<l-avatar
style="--color: var(--color-green-200)"
name="Dan Evans"
></l-avatar>
<l-avatar
style="--color: var(--color-blue-200)"
name="Eve Fox"
></l-avatar>
<l-avatar
style="--color: var(--color-purple-200)"
name="Fay Grant"
></l-avatar>
</div>Sizes
Add the size attribute: xs, sm, md (default), lg, or xl.
Code
<div class="flex items-end gap-3">
<l-avatar
size="xs"
name="John Doe"
></l-avatar>
<l-avatar
size="sm"
name="John Doe"
></l-avatar>
<l-avatar name="John Doe"></l-avatar>
<l-avatar
size="lg"
name="John Doe"
></l-avatar>
<l-avatar
size="xl"
name="John Doe"
></l-avatar>
</div>Circle
Set --appearance: circle for a fully circular shape. Default is a rounded square.
Code
<l-avatar
style="--appearance: circle"
src="https://i.pravatar.cc/150?img=58"
name="John Doe"
></l-avatar>
<l-avatar
style="--appearance: circle"
name="Jane Smith"
></l-avatar>
<l-avatar style="--appearance: circle"></l-avatar>Badge
Set badge to a number to show a count indicator at the bottom-right corner.
Code
<l-avatar
badge="3"
src="https://i.pravatar.cc/150?img=58"
name="John Doe"
></l-avatar>
<l-avatar
badge="25"
src="https://i.pravatar.cc/150?img=32"
name="Jane Smith"
></l-avatar>
<l-avatar
badge="99"
name="Alex Chen"
></l-avatar>Interactive
Add the interactive attribute to render the avatar as a <button>. Includes focus ring and hover state.
Code
<l-avatar
interactive
src="https://i.pravatar.cc/150?img=58"
name="John Doe"
></l-avatar>
<l-avatar
interactive
name="Jane Smith"
></l-avatar>
<l-avatar
interactive
style="--appearance: circle"
src="https://i.pravatar.cc/150?img=32"
name="Alex Chen"
></l-avatar>Group
Wrap avatars in .l-avatar-group for an overlapping stack with a surface-colored ring.
Code
<div class="grid gap-4">
<div class="l-avatar-group">
<l-avatar
src="https://i.pravatar.cc/150?img=58"
name="John Doe"
></l-avatar>
<l-avatar
src="https://i.pravatar.cc/150?img=32"
name="Jane Smith"
></l-avatar>
<l-avatar
src="https://i.pravatar.cc/150?img=12"
name="Alex Chen"
></l-avatar>
<l-avatar name="Sam Wilson"></l-avatar>
</div>
<div class="l-avatar-group">
<l-avatar
style="--appearance: circle"
src="https://i.pravatar.cc/150?img=58"
name="John Doe"
></l-avatar>
<l-avatar
style="--appearance: circle"
src="https://i.pravatar.cc/150?img=32"
name="Jane Smith"
></l-avatar>
<l-avatar
style="--appearance: circle"
src="https://i.pravatar.cc/150?img=12"
name="Alex Chen"
></l-avatar>
<l-avatar
style="--appearance: circle"
name="Sam Wilson"
></l-avatar>
</div>
</div>Accessibility
Criteria
- Interactive mode
When
interactiveis set, renders as a<button>with focus ring and hover statesWCAG2.4.7RGAA10.7- Decorative elements
Badge count is hidden from assistive tech with
aria-hidden="true"WCAG1.1.1- Image fallback
Falls back to initials (then default icon) if image fails to load
WCAG1.1.1
Keyboard interactions
When interactive is set:
API reference
Importing
import 'luxen-ui/avatar';Attributes & Properties
srcAttribute- Image URL for the avatar
nameAttribute- Full name used for initials extraction and
aria-label sizeAttribute- Avatar size:
xs(24px),sm(32px),md(40px, default),lg(48px),xl(56px) badgeAttribute- Number. Shows a count indicator at bottom-right
interactiveAttribute- Boolean. Renders as a
<button>with focus and hover states
CSS classes
.l-avatar-groupClass- Flex container with negative margins and surface-colored ring for overlapping avatars
CSS custom properties
--colorProperty- Base color for initials/icon background. Text color is auto-derived via relative color syntax
--appearanceProperty- Set to
circlefor a fully circular shape (default is rounded square)