Components / Display

Avatar02

A profile picture, or colorful initials when there's no picture. Stack them in a group and each one springs up when you point at it.

Avatar · PlaygroundLive
AL
size
src
JSX
<Avatar name="Ada Lovelace" />

Usage

TSX
import { Avatar } from "plonk-ui";

export function Author() {
  return <Avatar name="Ada Lovelace" src="/avatars/ada.svg" />;
}

name is required: it's the image's alt text and the source of the initials.

Fallback

Without src, or when the image fails to load, the avatar shows the first letters of the first and last name. The background color is picked from the name, so the same person always gets the same color.

Avatar · FallbackLive
Ada LovelaceKemal SunalL
TSX
import { Avatar } from "plonk-ui";

export default function Fallback() {
  return (
    <div className="flex flex-wrap items-center gap-4">
      <Avatar name="Ada Lovelace" src="/avatars/ada.svg" size="lg" />
      <Avatar name="Kemal Sunal" src="/avatars/missing.png" size="lg" />
      <Avatar name="Lin" size="lg" />
    </div>
  );
}

Group

AvatarGroup overlaps its avatars and sets one size for all of them. With max, the rest collapse into a "+N" bubble. Give the group an aria-label that says who these people are.

Avatar · GroupLive
Ada LovelaceKemal SunalLin ChenGH+2
Ada LovelaceKemal SunalLin Chen
TSX
import { Avatar, AvatarGroup } from "plonk-ui";

const TEAM = [
  { name: "Ada Lovelace", src: "/avatars/ada.svg" },
  { name: "Kemal Sunal", src: "/avatars/kemal.svg" },
  { name: "Lin Chen", src: "/avatars/lin.svg" },
  { name: "Grace Hopper" },
  { name: "Alan Turing" },
  { name: "Margaret Hamilton" },
];

export default function Group() {
  return (
    <div className="flex flex-col items-center gap-6">
      <AvatarGroup aria-label="Project team" max={4}>
        {TEAM.map((person) => (
          <Avatar key={person.name} {...person} />
        ))}
      </AvatarGroup>
      <AvatarGroup aria-label="Reviewers" size="sm">
        {TEAM.slice(0, 3).map((person) => (
          <Avatar key={person.name} {...person} />
        ))}
      </AvatarGroup>
    </div>
  );
}

The "+N" bubble is read as "2 more". Translate it with moreLabel:

TSX
<AvatarGroup max={4} moreLabel={(count) => `${count} kişi daha`}>
  …
</AvatarGroup>;

Personalities

The border and the initials' font follow the personality: chunky letters in Sticker, pixel letters in Retro, inked capitals in Comic and arcade capitals on Arcade's dark screen. In a group, avatars spring up under the pointer; Retro does it in steps.

Accessibility

  • Images use name as their alt text; initials are an image named name, so screen readers say the name, not the letters.
  • A group is a group role. Name it with aria-label.
  • The "+N" bubble has its own accessible name from moreLabel.

API

Avatar

All other <span> props are passed through.

PropTypeDefaultDescription
name*string—Person's name. Used as the image's alt text and for the initials fallback, whose color is picked from the name.
srcstring—Image URL. If it's missing or fails to load, the initials show instead.
size"sm" | "md" | "lg"—Size. Inside an AvatarGroup, the group's size is the default.

AvatarGroup

All other <div> props are passed through.

PropTypeDefaultDescription
maxnumber—Show at most this many avatars; the rest collapse into a “+N” bubble.
size"sm" | "md" | "lg""md"Size of every avatar in the group.
moreLabel(count: number) => string(count) => `${count} more`Accessible name of the “+N” bubble. Translate it for your app's language.