Skip to Content
Cristal

Data

Avatar

Photo or initials of a person, with their status, alone or in a group.

<cr-avatar><cr-avatar-group>CrAvatarCrAvatarGroup

Example

cr-avatar shows a person's photo (src) or, without one, their initials: the first letter of the first and last words of name. If the photo fails to load, the initials replace it. The background colour comes from the name: the same person keeps the same colour everywhere. It is derived from the theme primary colour with a hue shift, dark enough for the white initials to keep a contrast of at least 4.5:1.

size sets the size (s 30px, m 40px, l 48px). status adds an availability badge: online (filled, with a check mark), away (a clock), busy (a bar), offline (an empty ring). The online badge pulses three times when it appears, then stops.

'use client';

import { CrAvatar, CrBox } from '@cristal-ui/react';

const photo = `data:image/svg+xml,${encodeURIComponent(
  '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40"><rect width="40" height="40" fill="#d6c8f5"/><circle cx="20" cy="16" r="7" fill="#4c1d95"/><path d="M7 40c1-9 7-13 13-13s12 4 13 13z" fill="#4c1d95"/></svg>',
)}`;

export default function AvatarBasic() {
  return (
    <CrBox display="flex" gap="lg" align="center" wrap>
      <CrAvatar name="Mary Smith" status="online" />
      <CrAvatar name="Karim Ali" src={photo} status="away" />
      <CrAvatar name="Lea Martin" status="busy" size="l" />
      <CrAvatar name="Tom Little" status="offline" size="s" />
    </CrBox>
  );
}

Group

cr-avatar-group overlaps the cr-avatar elements it contains; they fan out on hover, or when focus is inside the group. With max, only the first avatars are shown, and a "+N" badge sums up the others.

'use client';

import { CrAvatar, CrAvatarGroup } from '@cristal-ui/react';

const team = ['Mary Smith', 'Karim Ali', 'Lea Martin', 'Tom Little', 'Ines Moore', 'Hugo Brown'];

export default function AvatarGroup() {
  return (
    <CrAvatarGroup max={4}>
      {team.map((name) => (
        <CrAvatar key={name} name={name} />
      ))}
    </CrAvatarGroup>
  );
}

If the user asked their system to reduce motion, the online badge does not pulse and the avatars of a group spread without sliding.

Accessibility

  • Each avatar is an image named by the person, status included: "Mary Smith, online". The initials and the photo are not read on top of it.
  • The status does not rely on colour alone: each status has its own shape (check mark, clock, bar, empty ring), and it is part of the name read aloud.
  • The online badge pulse lasts less than 5 seconds, then stops: nothing moves continuously.
  • The "+N" badge of a group is an image named "2 more people"; hidden avatars are not read.

API

Properties

PropertyTypeDefaultDescription
name (obligatoire)string—Nom de la personne (obligatoire) : nom lu par les lecteurs d'écran, et initiales quand il n'y a pas de photo.
size"l" | "m" | "s"'m'Taille : s 30px, m 40px, l 48px.
srcstring—Adresse de la photo ; les initiales la remplacent si elle ne se charge pas.
status"away" | "busy" | "offline" | "online"—Disponibilité, ajoutée au nom lu (« Marie Dupont, en ligne ») et montrée par une pastille de forme différente pour chaque statut.

CSS parts

To style it from outside: cr-avatar::part(name) { … }

PartDescription
avatarLe disque de l'avatar.
imageLa photo.
statusLa pastille de statut.

API CrAvatarGroup

Properties

PropertyTypeDefaultDescription
maxnumber—Nombre maximal d'avatars affichés ; les autres sont résumés par « +N ». Tous par défaut.

Slots

SlotDescription
defaultLes cr-avatar.

CSS parts

To style it from outside: cr-avatar-group::part(name) { … }

PartDescription
moreLa pastille « +N ».

On this page