A component that displays a user's avatar, supporting images, Gravatar, and initials.

Importing

The component can be imported via:

import { Avatar } from '@customerio/pluma-components/react';
JD
<Avatar name="John Doe" />

Usage

The Avatar component can display user avatars in several ways, following a priority order:

  1. Custom image via src prop
  2. Gravatar image via email prop
  3. Text fallback using initials from name, email, or custom initials text

Basic Usage

JD
<Avatar name="John Doe" />

With email (Gravatar)

CN
<Avatar 
  name="Colin Nederkoorn" 
  email="colin@customer.io"
/>

With tooltip

If you place the avatar without any context around it, it is recommended to add a tooltip so that the user can understand which user the avatar represents.

JD
<Avatar 
  name="John Doe"
  withTooltip={true}
/>

Auto color

Use the autoColor prop to automatically generate a deterministic background and text color based on the user's name. This is useful for distinguishing users in lists when no image is available.

CD
IC
AW
TB
MS
DC
LG
BM
AF
GL
<Box display="flex" gap="100" flexWrap="wrap">
  <Avatar name="Cal Duke" autoColor />
  <Avatar name="Ivy Cox" autoColor />
  <Avatar name="Alice Wang" autoColor />
  <Avatar name="Tom Brady" autoColor />
  <Avatar name="Max Stone" autoColor />
  <Avatar name="Dan Cole" autoColor />
  <Avatar name="Leo Gray" autoColor />
  <Avatar name="Bob Martin" autoColor />
  <Avatar name="Ada Finn" autoColor />
  <Avatar name="Grace Liu" autoColor />
</Box>

Customizing

You should almost never need to customize the src, label, and initials. However, we do provide escape hatches for these cases.

JD
<Avatar 
  src="https://example.com/avatar.jpg"
  label="This is John Doe"
  initials="JD"
/>

Accessibility

The Avatar component follows accessibility best practices:

  • Uses appropriate ARIA labels based on the provided label, name, or email
  • Supports keyboard navigation when interactive elements tooltips are enabled

API

When true, automatically generates a deterministic background and text color based on the user's name or email. Useful for distinguishing users in lists when no image is available.

The email address of the user. If no src is provided, a gravatar will be used.

An icon to render instead of an image or initials.

The size of the icon. Only applies when icon is provided.

Initials to use if no image is provided. Max 2 characters.

The label for the avatar. Used for the tooltip and alt text.

The name of the user. Used to generate initials if no src is provided.

The source URL of the image. Takes precedence over email-based Gravatar images.

Whether to show a tooltip with the label.