Pass initials to display a text fallback. With no image or initials, a user icon is shown.
<c-ui.avatar initials="JD" />
<c-ui.avatar />
{% cotton ui.avatar initials="JD" /%}
{% cotton ui.avatar /%}
Provide a src to render a photo. Always include an alt for accessibility.
<c-ui.avatar src="https://i.pravatar.cc/100?img=5" alt="Jane Doe" />
{% cotton ui.avatar src="https://i.pravatar.cc/100?img=5" alt="Jane Doe" /%}
Avatars come in sizes from size="xs" to size="xl", defaulting to md.
<c-ui.avatar size="xs" initials="XS" />
<c-ui.avatar size="sm" initials="SM" />
<c-ui.avatar size="md" initials="MD" />
<c-ui.avatar size="lg" initials="LG" />
<c-ui.avatar size="xl" initials="XL" />
{% cotton ui.avatar size="xs" initials="XS" /%}
{% cotton ui.avatar size="sm" initials="SM" /%}
{% cotton ui.avatar size="md" initials="MD" /%}
{% cotton ui.avatar size="lg" initials="LG" /%}
{% cotton ui.avatar size="xl" initials="XL" /%}
Set color to a Tailwind family for a solid background, or color="auto" to derive a stable colour from the initials.
{# manually coloured #}
<c-ui.avatar initials="JD" color="blue" />
<c-ui.avatar initials="AB" color="rose" />
<c-ui.avatar initials="CT" color="teal" />
{# auto, derived from the initials #}
<c-ui.avatar initials="SK" color="auto" />
<c-ui.avatar initials="TC" color="auto" />
<c-ui.avatar initials="BL" color="auto" />
<c-ui.avatar initials="KP" color="auto" />
<c-ui.avatar initials="NV" color="auto" />
{# manually coloured #}
{% cotton ui.avatar initials="JD" color="blue" /%}
{% cotton ui.avatar initials="AB" color="rose" /%}
{% cotton ui.avatar initials="CT" color="teal" /%}
{# auto, derived from the initials #}
{% cotton ui.avatar initials="SK" color="auto" /%}
{% cotton ui.avatar initials="TC" color="auto" /%}
{% cotton ui.avatar initials="BL" color="auto" /%}
{% cotton ui.avatar initials="KP" color="auto" /%}
{% cotton ui.avatar initials="NV" color="auto" /%}
Wrap avatars in <c-ui.avatar.group> to stack them with an overlapping ring. Add a trailing avatar to show an overflow count.
<c-ui.avatar.group>
<c-ui.avatar src="https://i.pravatar.cc/100?img=5" alt="Jane Doe" />
<c-ui.avatar initials="AB" />
<c-ui.avatar src="https://i.pravatar.cc/100?img=12" alt="Sam Lee" />
<c-ui.avatar initials="+3" />
</c-ui.avatar.group>
{% cotton ui.avatar.group %}
{% cotton ui.avatar src="https://i.pravatar.cc/100?img=5" alt="Jane Doe" /%}
{% cotton ui.avatar initials="AB" /%}
{% cotton ui.avatar src="https://i.pravatar.cc/100?img=12" alt="Sam Lee" /%}
{% cotton ui.avatar initials="+3" /%}
{% endcotton %}
The default slot renders on top of the avatar, so you can position a status indicator over it.
<c-ui.avatar src="https://i.pravatar.cc/100?img=8" alt="Online user">
<span class="absolute bottom-0 right-0 size-2.5 rounded-full bg-green-500 ring-2 ring-white dark:ring-zinc-900"></span>
</c-ui.avatar>
{% cotton ui.avatar src="https://i.pravatar.cc/100?img=8" alt="Online user" %}
<span class="absolute bottom-0 right-0 size-2.5 rounded-full bg-green-500 ring-2 ring-white dark:ring-zinc-900"></span>
{% endcotton %}
| Name | Description | Type | Options | Default |
|---|---|---|---|---|
src |
Image URL. When set, the avatar renders the image. | str | — | |
alt |
Alternative text for the image. | str | — | |
initials |
Text fallback shown when no image is provided. | str | — | |
size |
Avatar size from xs to xl. | str |
xssmmdlgxl
|
md |
color |
Solid background: a Tailwind family (e.g. blue) or 'auto' to derive one from the initials. Empty for neutral. | str | — | |
class |
Additional classes merged onto the avatar element. | str | — |
| Name | Description | Type | Options | Default |
|---|---|---|---|---|
slot (default) |
Rendered on top of the avatar, useful for a status dot or overlay. | — | — |
| Name | Description | Type | Options | Default |
|---|---|---|---|---|
class |
Additional classes merged onto the group wrapper. | str | — | |
slot (default) |
The avatars to stack. | — | — |