Skip to content

Avatar

A person's picture, with their initials when there's no picture. Same markup and props in every style: switch the style in the header to see it change.

Picture, initials and status

A picture, the initials fallback, a square avatar for teams and a presence dot. A picture that fails to load shows the initials underneath.

AL GH AI AT
avatar-basic.html
<span class="vin-avatar" role="img" aria-label="Ada Lovelace">
  <img class="vin-avatar__img" src="/ui/avatars/ada.svg" alt="">
  <span class="vin-avatar__fallback">AL</span>
</span>
<span class="vin-avatar" role="img" aria-label="Grace Hopper">
  <span class="vin-avatar__fallback">GH</span>
</span>
<span class="vin-avatar vin-avatar--square" role="img" aria-label="Acme Inc.">
  <span class="vin-avatar__fallback">AI</span>
</span>
<span class="vin-avatar" role="img" aria-label="Alan Turing (online)">
  <img class="vin-avatar__img" src="/ui/avatars/alan.svg" alt="">
  <span class="vin-avatar__fallback">AT</span>
  <span class="vin-avatar__status vin-avatar__status--online"></span>
</span>

Sizes

Small (28px), medium (36px) and large (48px). Initials scale with the size.

KJ KJ KJ GH GH GH
avatar-sizes.html
<span class="vin-avatar vin-avatar--sm" role="img" aria-label="Katherine Johnson">
  <img class="vin-avatar__img" src="/ui/avatars/kat.svg" alt="">
  <span class="vin-avatar__fallback">KJ</span>
</span>
<span class="vin-avatar" role="img" aria-label="Katherine Johnson">
  <img class="vin-avatar__img" src="/ui/avatars/kat.svg" alt="">
  <span class="vin-avatar__fallback">KJ</span>
</span>
<span class="vin-avatar vin-avatar--lg" role="img" aria-label="Katherine Johnson (busy)">
  <img class="vin-avatar__img" src="/ui/avatars/kat.svg" alt="">
  <span class="vin-avatar__fallback">KJ</span>
  <span class="vin-avatar__status vin-avatar__status--busy"></span>
</span>
<span class="vin-avatar vin-avatar--sm" role="img" aria-label="Grace Hopper">
  <span class="vin-avatar__fallback">GH</span>
</span>
<span class="vin-avatar" role="img" aria-label="Grace Hopper">
  <span class="vin-avatar__fallback">GH</span>
</span>
<span class="vin-avatar vin-avatar--lg" role="img" aria-label="Grace Hopper (away)">
  <span class="vin-avatar__fallback">GH</span>
  <span class="vin-avatar__status vin-avatar__status--away"></span>
</span>

Group

Avatars overlap with a ring in the background colour. End with a count for the rest.

AL AT GH KJ +3
avatar-group.html
<div class="vin-avatar-group" role="group" aria-label="Project members">
  <span class="vin-avatar" role="img" aria-label="Ada Lovelace">
    <img class="vin-avatar__img" src="/ui/avatars/ada.svg" alt="">
    <span class="vin-avatar__fallback">AL</span>
  </span>
  <span class="vin-avatar" role="img" aria-label="Alan Turing">
    <img class="vin-avatar__img" src="/ui/avatars/alan.svg" alt="">
    <span class="vin-avatar__fallback">AT</span>
  </span>
  <span class="vin-avatar" role="img" aria-label="Grace Hopper">
    <img class="vin-avatar__img" src="/ui/avatars/grace.svg" alt="">
    <span class="vin-avatar__fallback">GH</span>
  </span>
  <span class="vin-avatar" role="img" aria-label="Katherine Johnson">
    <img class="vin-avatar__img" src="/ui/avatars/kat.svg" alt="">
    <span class="vin-avatar__fallback">KJ</span>
  </span>
  <span class="vin-avatar" role="img" aria-label="3 more people">
    <span class="vin-avatar__fallback">+3</span>
  </span>
</div>

Installation

React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:

Terminal
npx @vinish/ui add avatar
React
import { Avatar, AvatarGroup, initials } from "@/components/vin/avatar";
Vue
import Avatar, { AvatarGroup, initials } from "@/components/vin/avatar.vue";
Svelte
import Avatar, { initials } from "$lib/components/vin/avatar.svelte";
import AvatarGroup from "$lib/components/vin/avatar-group.svelte";

The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.

Plain HTML: the classes come with the style's stylesheet. It needs no JavaScript.

API

From spec/avatar.json, which every framework version is tested against.

PropValuesDefaultIn HTML
name
Who it is. Becomes the accessible name, and the initials when there is no picture.
string—role="img" aria-label="…" on .vin-avatar, initials in .vin-avatar__fallback
src
Picture URL. If it fails to load, the initials show.
string—<img class="vin-avatar__img" alt="">
sizesmmdlgmdvin-avatar--{value}
shapecirclesquarecirclevin-avatar--square
status
A presence dot. Say it in the name too: "Ada Lovelace (online)".
onlinebusyaway—<span class="vin-avatar__status vin-avatar__status--{value}"></span>
AvatarGroup
Wrap avatars to overlap them.
children—.vin-avatar-group

Parts

React, Vue, SvelteHTML classes
<Avatar><AvatarGroup>.vin-avatar.vin-avatar--sm.vin-avatar--lg.vin-avatar--square.vin-avatar__img.vin-avatar__fallback.vin-avatar__status.vin-avatar__status--online.vin-avatar__status--busy.vin-avatar__status--away.vin-avatar-group

Accessibility

  • The avatar has role="img" and the person's name as its aria-label; the picture inside has alt="" so the name is read once.
  • The initials and the status dot are part of the image, so screen readers don't read them on their own. Put the status in the name.
  • Initials meet 4.5:1 contrast in every style and mode.
  • A "+3" counter gets a name like "3 more people".