Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Avatar

FreeNew

A picture with initials as its fallback, in five sizes and two shapes, with a presence dot cut out of the edge.

Installation

pnpm dlx shadcn@latest add @viewport/avatar

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above.

avatar-demo.tsx
import { Avatar } from "@/components/viewport/avatar";

const portrait = (hue: number) =>
  `data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" fill="oklch(0.86 0.06 ${hue})"/><circle cx="32" cy="25" r="11" fill="oklch(0.55 0.08 ${hue})"/><path d="M10 64c2-15 12-22 22-22s20 7 22 22z" fill="oklch(0.55 0.08 ${hue})"/></svg>`)}`;

export default function AvatarDemo() {
  return (
    <div className="flex flex-col items-center gap-6">
      <div className="flex items-end gap-4">
        <Avatar name="Mara Lindqvist" src={portrait(60)} size="xs" />
        <Avatar name="Theo Okafor" src={portrait(150)} size="sm" status="online" />
        <Avatar name="Inés Carvalho" src={portrait(250)} size="md" status="away" />
        <Avatar name="Jonas Weber" src={portrait(20)} size="lg" status="busy" />
        <Avatar name="Priya Raman" src={portrait(320)} size="xl" status="offline" />
      </div>
      <div className="flex items-center gap-4">
        <Avatar name="Kenji Watanabe" size="md" />
        <Avatar name="Amara Diallo" src="/missing-portrait.jpg" size="md" status="online" />
        <Avatar name="Northwind Trading" shape="rounded" size="md" />
        <Avatar name="Acme" shape="rounded" size="lg" src={portrait(90)} />
      </div>
    </div>
  );
}

Props

PropTypeDefault
name*string

The person's or team's name. It is the image's alt text and the source of the initials.

—
srcstring

The picture. Initials are shown while it loads and if it fails.

—
sizekeyof typeof sizes"md"
shape"circle" | "rounded"

`rounded` is for teams, companies and workspaces.

"circle"
statuskeyof typeof statuses

Adds a presence dot. Its meaning is also read out.

—
classNamestring—

Accessibility

  • The name is the image's alt text and the fallback's label.
  • Presence is read out as a word, not only shown as a color.
  • Initials hold the space while the image loads, so nothing shifts.