Avatar
avatarDisplays a user image with fallback content.
Usage
Picture with fallback
src Displays the image if loading is successful; falls back to fallback (initial letter/text) if failed or omitted.
ZSHu
tsx
<>
<Avatar src="/demo/avatar-12.jpg" alt="demo" fallback="ZS" />
<Avatar fallback="Hu" />
</>Size
size provides sm / md / lg / xl / 2xl in five diameters.
SMLXL2X
tsx
<>
<Avatar size="sm" fallback="S" />
<Avatar size="md" fallback="M" />
<Avatar size="lg" fallback="L" />
<Avatar size="xl" fallback="XL" />
<Avatar size="2xl" fallback="2X" />
</>Accent and ring
tone="brand" uses the accent's subtle background with accent text; ring adds a 2px outer ring whose color follows tone, and inside a primary card the neutral ring turns translucent white automatically.
LinLin
tsx
<Avatar tone="brand" ring fallback="Lin" />
<Card variant="primary">
<Avatar ring src="/demo/avatar-12.jpg" alt="Abel" fallback="A" />
</Card>When to use
Use Avatar for one person's image, with initials or other fallback content when the image is missing or fails. Use [User] for an avatar with a name and description, or AvatarCircles for an overlapping group.
Import
ts
import { Avatar } from "@hulianui/ui"Props
| Name | Type | Default | Description |
|---|---|---|---|
| size | "sm" | "md" | "lg" | "xl" | "2xl" | "md" | Preset circular diameter: 32 / 40 / 48 / 64 / 96px. |
| src | string | - | Image URL; failures reveal fallback. |
| alt | string | - | Alternative image text. |
| tone | "neutral" | "brand" | "neutral" | Placeholder background: neutral is a neutral gray; brand uses the accent's subtle background with accent text, for the brand's, system's, or AI's own avatar, or initials that should carry the theme color. A loaded image covers it. |
| ring | boolean | false | A 2px outer ring whose color follows tone (border for neutral, the accent's subtle border for brand). Use it over colored backgrounds or photos, or when stacking avatars. Inside a primary card the neutral ring becomes translucent white automatically. |
| className | string | - | Custom class name. |
Slots
| Slot | Type | Description |
|---|---|---|
| fallback | ReactNode | Content shown without a working image, usually initials. |
Pitfalls
- Base UI reveals
fallbackafter a missing or failedsrc; provide it to avoid an empty avatar. sizeaccepts only sm, md, and lg. Override dimensions throughclassNamefor a custom size.
Related
Sparkline · ImageViewer · LiveProductCard · DiffStat · ScoreRing · Badge
Playground
ZS
<Avatar size="md" src="/demo/avatar-12.jpg" fallback="ZS" />