Docs

Avatar

Avatar is a graphical representation of an object or entity, for example, a person or an organization.

Avatar is a graphical representation of an object or entity, for example, a person or an organization.

Open in a
new tab
<Avatar />

<Avatar name={`${person?.firstName} ${person?.lastName}`} />

<Avatar img={person?.pictureUrl} name={`${person?.firstName} ${person?.lastName}`} />
Note
Real-time collaboration
This component is optimized for use with Collaboration Kit — a simple way to build real-time collaboration into your app — but can also be used standalone as a regular component.

Content

Avatar has three properties: name, abbreviation, and image.

Name and Abbreviation

The name is shown on hover in a tooltip. When a name is set, Avatar auto-generates and display an abbreviation of the specified name. For example, “Allison Torres” becomes “AT”, “John Smith” becomes “JS”, and so on.

Open in a
new tab
<Avatar name={`${person?.firstName} ${person?.lastName}`} />

The abbreviation can also be set manually. Abbreviations should be kept to a maximum of 2–3 characters.

Open in a
new tab
<Avatar name="Augusta Ada King"></Avatar>

<Avatar name="Augusta Ada King" abbr="AK"></Avatar>

Image

Avatar can be used to display images, such as user profile pictures or company logos. Abbreviations aren’t shown when images are used.

Open in a
new tab
<Avatar img={person?.pictureUrl} name={`${person?.firstName} ${person?.lastName}`} />

<Avatar img={companyLogo} name="Company Inc." />

Avatar Group

Avatar Group is used to group multiple Avatars together. It can be used, for example, to show that there are multiple users viewing the same page or for listing members of a project.

Open in a
new tab
<AvatarGroup
  items={items.map((person) => ({
    name: `${person.firstName} ${person.lastName}`,
  }))}
/>

Maximum Number of Items

You can specify the maximum number of items an Avatar Group should display. Items that overflow are grouped into a single Avatar that displays the overflow count. The name of each hidden item is shown on hover in a tooltip. Clicking the overflow item displays the overflowing avatars and names in a list.

Open in a
new tab
<AvatarGroup
  maxItemsVisible={3}
  items={items.map((person) => ({
    name: `${person.firstName} ${person.lastName}`,
  }))}
/>

Background Color

By default, there are 7 different background colors you can use for Avatar. The background color is set using a color index.

Open in a
new tab
<AvatarGroup
  items={items.map((person, index) => ({
    name: `${person.firstName} ${person.lastName}`,
    colorIndex: index,
  }))}
/>

Using different background colors can be useful when you need to be able to distinguish between users, for example during collaborative work.

Internationalisation (i18n)

All texts in Avatar and Avatar Group are configurable:

Avatar Texts

Property Text Description

anonymous

"Anonymous"

Avatar’s default name. Shown on hover in a tooltip and announced by screen readers when the Avatar is focused.

Avatar Group Texts

Property Text Description

anonymous

"Anonymous"

Default name for all Avatars in the Avatar Group.

activeUsers.one

"Currently one active user"

Announced by screen readers when there is exactly one Avatar in an Avatar Group and the Avatar is focused. The name of the Avatar is read aloud first.

activeUsers.many

"Currently {count} active users"

Announced by screen readers when there are multiple Avatars in an Avatar Group and an Avatar is focused. The name of the focused Avatar is read aloud first.

*{count} is the Avatar Group item count.

joined

"{user} joined"

Announced by screen readers when an Avatar is added to the group.

*{user} is the Avatar’s name.

left

"{user} left"

Announced by screen readers when an Avatar is removed from the group.

*{user} is the Avatar’s name.

Open in a
new tab
const i18n: AvatarGroupI18n = {
  anonymous: 'Anonyymi',
  activeUsers: {
    one: 'Yksi käyttäjä aktiivisena',
    many: '{count} käyttäjää aktiivisena',
  },
  joined: 'liittyi',
  left: 'lähti',
};
  return <AvatarGroup i18n={i18n} items={items} />;

Size Variants

Avatar has four available size variants:

Open in a
new tab
<Avatar name={`${person?.firstName} ${person?.lastName}`} theme="xlarge" />

<Avatar name={`${person?.firstName} ${person?.lastName}`} theme="large" />

<Avatar name={`${person?.firstName} ${person?.lastName}`} theme="small" />

<Avatar name={`${person?.firstName} ${person?.lastName}`} theme="xsmall" />
Variant Theme name

Extra large

xlarge

Large

large

Small

small

Extra small

xsmall

Size variants should be used only in special cases. See <<https://vaadin.com/docs/styling/lumo/lumo-style-properties/size-space#,Size and Space>> for details on how to change the default Avatar size.

Use Cases

Avatar can be paired with Menu Bar to create a user account menu.

Open in a
new tab
// Workaround https://github.com/vaadin/react-components/issues/132
function menuComponent(component: React.ReactNode) {
  const container = document.createElement('div');
  createRoot(container).render(component);
  return container;
}

const menuBarItems = [
  {
    component: menuComponent(
      <Avatar name={`${person?.firstName} ${person?.lastName}`} img={person?.pictureUrl} />
    ),
    children: [
      {
        text: 'Profile',
      },
      {
        text: 'Settings',
      },
      {
        text: 'Help',
      },
      {
        text: 'Sign out',
      },
    ],
  },
];

return <MenuBar items={menuBarItems} theme="tertiary-inline" />;