Liking cljdoc? Tell your friends :D

x-avatar

A themeable, accessible avatar component. Displays a user photo, derived or explicit initials, or a fallback glyph. Supports shape, size, and variant tokens, a status indicator dot, and a badge slot for overlays.


Tag

<x-avatar></x-avatar>

Attributes

AttributeTypeDefaultDescription
srcstringImage URL
altstringImage alt text; also used as aria-label on the host
namestringPerson's name; used for initials derivation and aria-label when alt is absent
initialsstringExplicit initials (1–3 chars). Overrides name-derived initials
sizeenum"md"Avatar dimension: xs sm md lg xl
shapeenum"circle"Border shape: circle square rounded
variantenum"neutral"Colour variant: neutral brand subtle
statusenumStatus indicator: online offline busy away. Absent = no dot
disabledbooleanfalseDims the avatar; sets aria-disabled="true"

Properties

PropertyTypeReflects attribute
srcstring | nullsrc
altstring | nullalt
namestring | nullname
initialsstring | nullinitials
sizestringsize
shapestringshape
variantstringvariant
statusstring | nullstatus
disabledbooleandisabled

Events

None. x-avatar is a display-only component.


Slots

SlotDescription
badgeOverlay element (e.g. notification count, icon). Positioned at top-right corner of the host.
<x-avatar name="Alice Bob">
  <span slot="badge" class="badge">3</span>
</x-avatar>

Parts

PartDescription
rootAvatar circle/square — overflow:hidden
image<img> element
initialsInitials <span>
fallbackFallback glyph <span> (?)
statusStatus indicator dot <span>
badgeBadge wrapper <span>

CSS Custom Properties

Dimensions

VariableDefaultDescription
--x-avatar-sizeOverride avatar size completely
--x-avatar-size-xs20pxxs size token
--x-avatar-size-sm24pxsm size token
--x-avatar-size-md32pxmd size token
--x-avatar-size-lg40pxlg size token
--x-avatar-size-xl48pxxl size token
--x-avatar-radius10pxBorder radius for shape="rounded"

Colour tokens (light mode defaults)

VariableDefault
--x-avatar-bgrgba(0,0,0,0.06)
--x-avatar-borderrgba(0,0,0,0.14)
--x-avatar-colorrgba(0,0,0,0.86)
--x-avatar-ring#ffffff
--x-avatar-disabled-opacity0.55
--x-avatar-status-onlinergba(16,140,72,0.95)
--x-avatar-status-offlinergba(0,0,0,0.45)
--x-avatar-status-busyrgba(190,20,40,0.95)
--x-avatar-status-awayrgba(204,120,0,0.95)

Dark-mode variants are set automatically via @media (prefers-color-scheme: dark).


Accessibility

  • When alt or name is present: host gets role="img" and aria-label.
  • When neither is present: host gets aria-hidden="true" (decorative).
  • When disabled: host gets aria-disabled="true".
  • The [part=image] alt attribute is always empty — the host carries the accessible name.

Display mode priority

ConditionDisplayed
src set and image loadedPhoto
src set but load failedInitials or ?
No src, initials attributeExplicit initials
No src, name attributeDerived initials
None of the above? glyph

Initials derivation: split name on whitespace, take the first character of the first two words, uppercase.


Examples

Sizes

<x-avatar size="xs" name="Alice Bob"></x-avatar>
<x-avatar size="sm" name="Alice Bob"></x-avatar>
<x-avatar size="md" name="Alice Bob"></x-avatar>
<x-avatar size="lg" name="Alice Bob"></x-avatar>
<x-avatar size="xl" name="Alice Bob"></x-avatar>

Shapes

<x-avatar shape="circle"  name="Alice Bob"></x-avatar>
<x-avatar shape="rounded" name="Alice Bob"></x-avatar>
<x-avatar shape="square"  name="Alice Bob"></x-avatar>

Variants

<x-avatar variant="neutral" name="Alice Bob"></x-avatar>
<x-avatar variant="brand"   name="Alice Bob"></x-avatar>
<x-avatar variant="subtle"  name="Alice Bob"></x-avatar>

Status indicators

<x-avatar name="Alice" status="online"></x-avatar>
<x-avatar name="Bob"   status="busy"></x-avatar>
<x-avatar name="Carol" status="away"></x-avatar>
<x-avatar name="Dave"  status="offline"></x-avatar>

Badge slot

<x-avatar name="Alice Bob">
  <span slot="badge" style="
    background:#ef4444; color:#fff;
    font-size:10px; font-weight:700;
    min-width:16px; height:16px;
    border-radius:999px; padding:0 4px;
    display:inline-flex; align-items:center; justify-content:center;
  ">3</span>
</x-avatar>

Image with fallback

<x-avatar src="https://example.com/photo.jpg"
          alt="Alice's profile photo"
          name="Alice Bob">
</x-avatar>

If the image fails to load, initials AB are shown.

ClojureScript (hiccup renderer)

[:x-avatar {:name "Alice Bob" :size "lg" :status "online"}]

[:x-avatar {:src     "https://example.com/photo.jpg"
            :alt     "Alice's profile photo"
            :variant "brand"
            :shape   "rounded"}]

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close