Avatar

A circular image component for representing users or entities. Renders an image when a src is provided, or an empty placeholder when omitted.

User avatar
import { Avatar } from "@tenstorrent/vesper/avatar";

export default function AvatarDemo() {
  return (
    <Avatar
      size="lg"
      src="https://api.dicebear.com/10.x/initial-face/svg?seed=jane-doe"
      alt="User avatar"
    />
  );
}

Options

PropTypeDescriptionDefault
size"sm" | "md" | "lg"The size of the avatar."md"
srcstringThe image source URL. When not provided, renders as an empty placeholder.—
altstringThe alt text for the avatar image.""
asElementTypeThe root element type for polymorphic rendering."div"

Examples

Basic usage

By default, an Avatar will render at md size if the size prop is not specified:

Simon
import { Avatar } from "@tenstorrent/vesper/avatar";

export default function BasicAvatar() {
  return (
    <Avatar
      src="https://api.dicebear.com/10.x/initial-face/svg?seed=simon"
      alt="Simon"
    />
  );
}

Sizes

An Avatar can be rendered in one of three sizes: sm, md, and lg:

Simon
Mackenzie
Neesh
import { Avatar } from "@tenstorrent/vesper/avatar";

export default function AvatarSizes() {
  return (
    <div
      style={{
        display: "flex",
        alignItems: "center",
        gap: "var(--vesper-spacing-2)",
      }}
    >
      <Avatar
        src="https://api.dicebear.com/10.x/initial-face/svg?seed=simon"
        alt="Simon"
        size="sm"
      />
      <Avatar
        src="https://api.dicebear.com/10.x/initial-face/svg?seed=mackenzie"
        alt="Mackenzie"
        size="md"
      />
      <Avatar
        src="https://api.dicebear.com/10.x/initial-face/svg?seed=neesh"
        alt="Neesh"
        size="lg"
      />
    </div>
  );
}

Placeholder (no image)

Rendering an Avatar with no src prop will show an empty circle with a placeholder fill color:

import { Avatar } from "@tenstorrent/vesper/avatar";

export default function PlaceholderAvatar() {
  return <Avatar />;
}

Polymorphic usage

You can use the as prop to specify what underlying element to render. In this case, we are passing as="a" to render the Avatar as an anchor link. This is helpful for apps where clicking on an avatar may navigate to a user profile, for example:

Jane Doe
import { Avatar } from "@tenstorrent/vesper/avatar";

export default function AvatarAsLink() {
  return (
    <Avatar
      as="a"
      href="#polymorphic-usage"
      src="https://api.dicebear.com/10.x/initial-face/svg?seed=jane-doe"
      alt="Jane Doe"
      size="lg"
    />
  );
}