Avatar
Circular avatar displaying an image, initials, or icon fallback. Supports four sizes and an optional status dot indicator.
import { Avatar } from "phoundry-ui";With Image
Loading interactive example…
View source
<script lang="ts"> import { Avatar } from "phoundry-ui";</script>
<Avatar src="https://i.pravatar.cc/80?u=1" alt="Jane Doe" />Initials
Loading interactive example…
View source
<script lang="ts"> import { Avatar } from "phoundry-ui";</script>
<div class="flex items-center gap-3"> <Avatar initials="JD" /> <Avatar initials="AB" /> <Avatar initials="XY" /></div>Icon Fallback
Loading interactive example…
View source
<script lang="ts"> import { Avatar } from "phoundry-ui"; import { PhiIcons } from "phoundry-ui";</script>
<p class="mb-2 text-xs text-txt-secondary"> Use any Iconify id or shared tokens from <code>PhiIcons</code> when there is no photo or initials.</p><div class="flex items-center gap-3"> <Avatar icon={PhiIcons.folder} /> <Avatar icon={PhiIcons.document} /></div>Image with status
Loading interactive example…
View source
<script lang="ts"> import { Avatar } from "phoundry-ui";</script>
<div class="flex items-center gap-3"> <Avatar src="https://i.pravatar.cc/80?u=7" alt="Team member" status="online" size="md" /> <Avatar src="https://i.pravatar.cc/80?u=8" alt="Away user" status="away" size="sm" /></div>Default user glyph
Loading interactive example…
View source
<script lang="ts"> import { Avatar } from "phoundry-ui";</script>
<div class="flex items-center gap-3"> <Avatar size="sm" /> <Avatar size="md" /></div>Sizes
Loading interactive example…
View source
<script lang="ts"> import { Avatar } from "phoundry-ui";</script>
<div class="flex items-center gap-3"> <Avatar initials="XS" size="xs" /> <Avatar initials="SM" size="sm" /> <Avatar initials="MD" size="md" /> <Avatar initials="LG" size="lg" /></div>Status Indicators
Loading interactive example…
View source
<script lang="ts"> import { Avatar } from "phoundry-ui";</script>
<div class="flex items-center gap-3"> <Avatar initials="ON" status="online" /> <Avatar initials="AW" status="away" /> <Avatar initials="BS" status="busy" /> <Avatar initials="OF" status="offline" /></div>API
From phoundry-ui@0.4.21
| Name | Type | Default | Description |
|---|---|---|---|
src | string | — | Image URL for the avatar. |
alt | string | '' | Alt text for the image. |
initials | string | — | Initials to display when no image is provided. |
icon | string | — | Iconify icon string used as fallback when no image or initials. |
size | "xs" | "sm" | "md" | "lg" | 'md' | Avatar size. |
status | "online" | "offline" | "away" | "busy" | — | Status dot indicator. |
class | ClassValue | — | Additional CSS classes. |
style | string | — | Inline styles on the stable component root. |
Usage tips
- The avatar falls back gracefully: image → initials → explicit
icon→ default user icon. - If the image fails to load, the component automatically switches to the initials or icon fallback.
- Provide meaningful
alttext wheneversrcis set; it defaults to an empty string. - Use
statusalongside user avatars in chat, team lists, or collaboration UIs.
Styling
.ph-avatar is the stable root hook. Consumer class values are additive, and style applies to that root. Styling uses vanilla CSS with semantic state attributes. Avatar intentionally retains its own scale: xs 1.5rem, sm 2rem, md 2.5rem, and lg 3.5rem. It does not consume the shared control-height tokens. Its initials, icon, and status-dot dimensions retain their previous proportions. The root emits data-size; the status part emits data-status. Image, initials, explicit icon, and default-user fallback precedence is unchanged. Internal part selectors and --_ph-* properties remain implementation details.