Data displayAvatar
Searchastronomic.dev# Avatar
To show a person next to their name, with initials when there is no photo.
Static: no JavaScript.
## Usage
```astro
import Avatar from "@astronomic-dev/ui/components/Avatar.astro";
```
## Examples
### Sizes and initials
```astro
---
import Avatar from "@astronomic-dev/ui/components/Avatar.astro";
---
<div class="flex flex-wrap items-center gap-3">
<Avatar name="Corinne Ashby" size="sm" />
<Avatar name="Jonas de Wit" />
<Avatar name="Sanne" size="lg" />
</div>
```
## Props
### Avatar
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `name` | `string` | None | The person's name. Required. Used for the initials and the accessible name. |
| `image` | `{ src, alt, width?, height? }` | None | A photo. Without one, the avatar shows the initials. |
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | The avatar's size. |
| `decorative` | `boolean` | `false` | Set when the name is shown next to the avatar: it is then hidden from assistive tech. |
| `class` | `string` | None | More classes, merged with cn(), so yours win on conflicts. |
| Slot | Description |
| --- | --- |
| `image` | Your own image element, used in place of image, for example an Astro <Image>. |
Any other attribute goes on the outer <span>.
## Accessibility
- Without a photo it is an image (role img) named by name, and its initials are not read out.
- With image set, the <img> gets alt from image.alt, or from name when that is empty.
- Set decorative when the name is shown next to it: the avatar is then hidden from screen readers.
- An empty name makes it decorative too: it never gets an empty label.
Avatar
FreeTo show a person next to their name, with initials when there is no photo.
- File
- Avatar.astro
- Group
- Data display
- Kind
- Static: no JavaScript
- Examples
- 1
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
Sizes and initials
CAJWSA
Force statemain.astro
examples/avatar/main.astro
---
import Avatar from "@astronomic-dev/ui/components/Avatar.astro";
---
<div class="flex flex-wrap items-center gap-3">
<Avatar name="Corinne Ashby" size="sm" />
<Avatar name="Jonas de Wit" />
<Avatar name="Sanne" size="lg" />
</div>Minimal · Light