Skip to content
loseta

Components / Surfaces

Avatar

Displays an image or fallback initials representing a user.

Status stable
CN
<span class="avatar"><span data-slot="fallback">CN</span></span>

Installation

pnpm dlx loseta add avatar
npx loseta add avatar

Examples

Basic

Ada Lovelace
<span class="avatar">
  <img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' fill='%23cbd5e1'/%3E%3Ccircle cx='32' cy='24' r='11' fill='%23475569'/%3E%3Cpath d='M10 64c0-12 10-22 22-22s22 10 22 22z' fill='%23475569'/%3E%3C/svg%3E" alt="Ada Lovelace" />
  <span data-slot="fallback" aria-hidden="true">AL</span>
</span>

Sizes

SM AV LG
<div style="display: flex; align-items: center; gap: 0.75rem">
  <span class="avatar" data-size="sm"><span data-slot="fallback">SM</span></span>
  <span class="avatar"><span data-slot="fallback">AV</span></span>
  <span class="avatar" data-size="lg"><span data-slot="fallback">LG</span></span>
</div>

Badge

Ada Lovelace
<span class="avatar">
  <img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' fill='%23cbd5e1'/%3E%3Ccircle cx='32' cy='24' r='11' fill='%23475569'/%3E%3Cpath d='M10 64c0-12 10-22 22-22s22 10 22 22z' fill='%23475569'/%3E%3C/svg%3E" alt="Ada Lovelace" />
  <span data-slot="fallback" aria-hidden="true">AL</span>
  <span data-slot="badge" aria-hidden="true"></span>
</span>

Badge with icon

Ada Lovelace
<span class="avatar" data-size="lg">
  <img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' fill='%23cbd5e1'/%3E%3Ccircle cx='32' cy='24' r='11' fill='%23475569'/%3E%3Cpath d='M10 64c0-12 10-22 22-22s22 10 22 22z' fill='%23475569'/%3E%3C/svg%3E" alt="Ada Lovelace" />
  <span data-slot="fallback" aria-hidden="true">AL</span>
  <span data-slot="badge" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14"/><path d="M12 5v14"/></svg></span>
</span>

Group

AL GR TS
<div class="avatar-group" role="group" aria-label="Project contributors">
  <span class="avatar"><span data-slot="fallback">AL</span></span>
  <span class="avatar"><span data-slot="fallback">GR</span></span>
  <span class="avatar"><span data-slot="fallback">TS</span></span>
</div>

Group count

AL GR TS 3 more contributors
<div class="avatar-group" role="group" aria-label="Project contributors">
  <span class="avatar"><span data-slot="fallback">AL</span></span>
  <span class="avatar"><span data-slot="fallback">GR</span></span>
  <span class="avatar"><span data-slot="fallback">TS</span></span>
  <span data-slot="count"><span aria-hidden="true">+3</span><span class="sr-only">3 more contributors</span></span>
</div>

Group with icon

AL GR TS 3 more contributors
<div class="avatar-group" role="group" aria-label="Project contributors">
  <span class="avatar"><span data-slot="fallback">AL</span></span>
  <span class="avatar"><span data-slot="fallback">GR</span></span>
  <span class="avatar"><span data-slot="fallback">TS</span></span>
  <span data-slot="count"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14"/><path d="M12 5v14"/></svg><span class="sr-only">3 more contributors</span></span>
</div>

Right-to-left

ع
أح سم لي ٣ أعضاء آخرون
<div style="display: flex; flex-wrap: wrap; align-items: center; gap: 1rem" dir="rtl" lang="ar">
  <span class="avatar" data-size="lg">
    <span data-slot="fallback">ع</span>
    <span data-slot="badge" aria-hidden="true"></span>
  </span>
  <div class="avatar-group" role="group" aria-label="أعضاء الفريق">
    <span class="avatar" data-size="lg"><span data-slot="fallback">أح</span></span>
    <span class="avatar" data-size="lg"><span data-slot="fallback">سم</span></span>
    <span class="avatar" data-size="lg"><span data-slot="fallback">لي</span></span>
    <span data-slot="count"><span aria-hidden="true">+٣</span><span class="sr-only">٣ أعضاء آخرون</span></span>
  </div>
</div>

Accessibility and behavior

  • Render the fallback under the image. CSS cannot detect a broken image, so hide the img (or omit it) when loading fails. Use alt text for img and aria-hidden on fallback initials and decorative badges. Give .avatar-group role="group" and an accessible name; [data-slot="count"] follows the group size and needs sr-only text when its visual is an icon.

Files

components/avatar.cssbase
styles/nova/avatar.cssstyle

Install contract

The CLI writes the base file under components/, the visual file for the selected style under styles/<name>/, and any primitive dependency underprimitives/. The generated index.css imports them in the right layer order.

← Back to components

loseta is MIT licensed. Built with native CSS, no runtime. Inspired byshadcn/ui.