Display
Avatar
User avatar that shows an image and falls back to colored initials, with size, shape and presence status.
<script>
import { Avatar } from "@codeatlasdev/ui";
</script>
<Avatar src="/ana.jpg" alt="Ana Lima" size="lg" status="online" />
Without src, or when the image fails to load, the avatar shows initials derived from alt (or fallback). fallback also takes a snippet, for an icon on groups, channels and bots that have no meaningful initials. The photo is a real <img>: pass loading="lazy" in long lists and referrerpolicy="no-referrer" for CDNs that reject a cross-origin Referer; onerror fires when it fails so you can refetch a signed URL. The background color is generated from the name, so the same person always gets the same color.
With image
Loads a real image URL and falls back to initials if it fails.
Reference #107 · Pick in the gallery
Code
Initials fallback
No `src`: initials come from `alt`, or from `fallback` when set.
Reference #108 · Pick in the gallery
Code
Icon fallback
`fallback` as a snippet: an icon instead of initials, with `loading` and `referrerpolicy` passed to the `<img>`.
Code
Sizes
Named sizes `xs` to `xl`, or any number in pixels.
Reference #110 · Pick in the gallery
Code
Shape and status
`shape="rounded"` and the presence dot.
Reference #109 · Pick in the gallery
Code
Avatar stack
Overlap pattern common in collaboration UIs.
Reference #111 · Pick in the gallery
Code
Props
| Prop | Type | Default | Description |
|---|---|---|---|
src | string | undefined | Image URL, rendered as a real `<img>`. The fallback shows beneath it while it loads and when it fails. |
alt | string | '' | Alt text. Initials are derived from it when no `fallback` is set. |
fallback | string | Snippet | undefined | Explicit initials (string) or an icon/any content (snippet). Overrides the initials derived from `alt`. |
size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | number | 'md' | Named size (20, 28, 36, 48, 64px) or a diameter in pixels. |
shape | 'circle' | 'rounded' | 'circle' | Avatar outline. |
status | 'online' | 'offline' | 'busy' | 'away' | undefined | Shows a presence dot in the bottom-right corner. |
loading | 'lazy' | 'eager' | undefined | Passed to the `<img>`. Use `lazy` in long lists so off-screen photos are not fetched. |
referrerpolicy | ReferrerPolicy | undefined | Passed to the `<img>`, e.g. `no-referrer` for CDNs that reject a cross-origin `Referer`. |
crossorigin | 'anonymous' | 'use-credentials' | undefined | Passed to the `<img>`. |
onerror | (event: Event) => void | undefined | Called when the image fails to load; the fallback shows. Refetch a signed URL here. |
skeleton | boolean | false | Loading placeholder with the exact avatar size; no image request is made. See Skeleton. |
class | string | '' | Extra class names. |