Avatar
An identity chip: a photo when one loads, a tinted initials-or-icon fallback when it doesn't.
Live demo
Avatar presents a person or entity as a compact square or circle. Given a src, it shows the image, cover-cropped to fill; if the image is absent or fails to load, it falls back to initials derived from userName ("Ada Lovelace" → AL) on a soft, hue-tinted background.
Slot your own content to override those initials, or use the icon slot for a glyph instead. The prop is userName, not name, because name carries form-participation meaning on an element and an avatar is not a form control. The fallback tint follows tone, which accepts any of the six semantic roles or the twelve named hues, so a deterministic per-user color is a one-attribute choice. Four sizes (sm, md, lg, xl), two shapes (circle, square), and an optional corner status dot in any semantic tone round out the surface. alt names the image; userName names the avatar when there is no image, so it is announced either way.
When to use
How this component composes with the rest of the set.
Props
9 props, straight from the manifest.
| Prop | Type | Default | Bindings | Description |
|---|---|---|---|---|
Appearance
Variants
circle
Fully rounded, the default identity shape.
square
A rounded square, for entities and projects rather than people.
Sizes
sm
Compact, for dense lists.
md
Default.
lg
Large, for headers.
xl
Extra large, for profile hero.
States
fallback
No image: the tinted initials-or-icon stand-in fills the chip.
status
A corner dot conveys presence; its color is the chosen status tone, ringed in the surface.
pulse
With pulse, the status dot breathes on a soft opacity loop so the avatar reads as live, at a slow or fast cadence; held still under reduced-motion.
Anatomy
The named parts that make up the component, with their selectors.
avatar
The root chip carrying the size, shape, and tone classes; sizes the image and fallback and anchors the status dot.
image
The portrait image, cover-cropped to fill the chip and clipped to the chip's shape.
fallback
The initials-or-icon stand-in shown when no image is present, painted with the tone's soft tint.
status-dot
The optional corner indicator, ringed in the surface color so it reads against any background.
Tokens & coverage
What the component consumes, checked live against what the algorithm produces.
Live coverage check against the xtyle-default register
(derive(xtyleDefault, { anchors }) →
coverComponent(manifest, register)). Every token this component
consumes must be a key the algorithm produces.
--accent
--accent-2-bg
--accent-2-text
--accent-3-bg
--accent-3-text
--accent-4-bg
--accent-4-text
--accent-bg
--accent-text
--bg-1
--black-bg
--black-text
--blue-bg
--blue-text
--border-thick
--brown-bg
--brown-text
--cyan-bg
--cyan-text
--danger
--danger-bg
--danger-text
--font-sans
--gray-bg
--gray-text
--green-bg
--green-text
--info
--info-bg
--info-text
--leading-tight
--neutral
--neutral-bg
--neutral-text
--orange-bg
--orange-text
--pink-bg
--pink-text
--purple-bg
--purple-text
--radius-full
--radius-lg
--radius-md
--radius-sm
--red-bg
--red-text
--space-2
--space-4
--space-6
--space-7
--space-8
--success
--success-bg
--success-text
--text-body
--text-lg
--text-sm
--text-xs
--warn
--warn-bg
--warn-text
--weight-semibold
--white-bg
--white-text
--yellow-bg
--yellow-text
Slots
Custom fallback content shown when no image loads. Overrides the initials userName derives — leave it empty and those initials are what you get.
An icon fallback, used in place of initials when no image loads.
Accessibility
Code
Image, fallback, and status
A photo when one loads, tinted initials or an icon when it doesn't, with an optional presence dot.
<!-- a photo when one loads -->
<xtyle-avatar user-name="Ada Lovelace" alt="Ada Lovelace" src="/avatars/ada.jpg"></xtyle-avatar>
<!-- no image: the initials fall out of the name ("Grace Hopper" → GH) -->
<xtyle-avatar user-name="Grace Hopper" tone="info" size="lg"></xtyle-avatar>
<xtyle-avatar user-name="Katherine Johnson" tone="purple" shape="square" status="success" status-label="Online"></xtyle-avatar>
<!-- slot your own content to override the derived initials -->
<xtyle-avatar user-name="Project Apollo" tone="warn">🚀</xtyle-avatar>
<xtyle-avatar alt="Unknown user" size="xl">
<svg slot="icon" viewBox="0 0 24 24" aria-hidden="true">
<path fill="currentColor" d="M12 12a5 5 0 1 0 0-10 5 5 0 0 0 0 10Zm0 2c-5 0-9 2.5-9 6v2h18v-2c0-3.5-4-6-9-6Z" />
</svg>
</xtyle-avatar>
<script lang="ts">
import { Avatar } from "@xtyle/svelte";
</script>
<!-- a photo when one loads -->
<Avatar userName="Ada Lovelace" alt="Ada Lovelace" src="/avatars/ada.jpg" />
<!-- no image: the initials fall out of the name ("Grace Hopper" → GH) -->
<Avatar userName="Grace Hopper" tone="info" size="lg" />
<Avatar userName="Katherine Johnson" tone="purple" shape="square" status="success" statusLabel="Online" />
<!-- slot your own content to override the derived initials -->
<Avatar userName="Project Apollo" tone="warn">🚀</Avatar>
<Avatar alt="Unknown user" size="xl">
{#snippet icon()}
<svg viewBox="0 0 24 24" aria-hidden="true">
<path fill="currentColor" d="M12 12a5 5 0 1 0 0-10 5 5 0 0 0 0 10Zm0 2c-5 0-9 2.5-9 6v2h18v-2c0-3.5-4-6-9-6Z" />
</svg>
{/snippet}
</Avatar>
---
import { Avatar } from "@xtyle/astro";
---
<!-- a photo when one loads -->
<Avatar userName="Ada Lovelace" alt="Ada Lovelace" src="/avatars/ada.jpg" />
<!-- no image: the initials fall out of the name ("Grace Hopper" → GH) -->
<Avatar userName="Grace Hopper" tone="info" size="lg" />
<Avatar userName="Katherine Johnson" tone="purple" shape="square" status="success" statusLabel="Online" />
<!-- slot your own content to override the derived initials -->
<Avatar userName="Project Apollo" tone="warn">🚀</Avatar>
<Avatar alt="Unknown user" size="xl">
<svg slot="icon" viewBox="0 0 24 24" aria-hidden="true">
<path fill="currentColor" d="M12 12a5 5 0 1 0 0-10 5 5 0 0 0 0 10Zm0 2c-5 0-9 2.5-9 6v2h18v-2c0-3.5-4-6-9-6Z" />
</svg>
</Avatar>
Live presence
A pulsing status dot reads as online in real time; statusLabel carries the meaning for assistive tech.
<xtyle-avatar user-name="Grace Hopper" status="success" status-label="Online" pulse></xtyle-avatar>
<Avatar userName="Grace Hopper" status="success" statusLabel="Online" pulse />
<Avatar userName="Grace Hopper" status="success" statusLabel="Online" pulse />