← Components

Communication

Avatar

A person or agent. Status dot, a speaking ring for agents, and a group that fans out on hover.

Examples and variants

Sizes, status, speaking

sm, md, lg.

PPALAI
Example
function AvatarSizes() {
  return (
    <div className="flex items-center gap-4">
      <Avatar size="sm">
        <AvatarFallback>PP</AvatarFallback>
      </Avatar>
      <Avatar size="md" status="online">
        <AvatarFallback>AL</AvatarFallback>
      </Avatar>
      <Avatar size="lg" speaking>
        <AvatarFallback>AI</AvatarFallback>
      </Avatar>
    </div>
  )
}

Group

Hover to fan out.

PPALMKJS+3 more
Example
function AvatarStack() {
  return (
    <AvatarGroup more={3}>
      {["PP", "AL", "MK", "JS"].map((initials) => (
        <Avatar key={initials}>
          <AvatarFallback>{initials}</AvatarFallback>
        </Avatar>
      ))}
    </AvatarGroup>
  )
}

Spec drawing

Measured from the live component at default density. Each code maps to the token that sets it; change the token and the drawing follows.

Install

With the CLI

The shadcn CLI only delivers files: it copies our code from the Isotopi registry into your project and installs the packages it uses. Add the foundation once, then the component.

Terminal
npx shadcn@latest add https://isotopi.com/r/minimal.json
npx shadcn@latest add https://isotopi.com/r/avatar.json

By hand

No CLI needed. Add the foundation once (see Getting started), then follow these steps. They include every component this one builds on.

  1. Install the packages it uses.

    Terminal
    npm install @base-ui/react cn
  2. Copy this file to the same paths in your project. Imports use the @/ alias for your project root.

    • components/ui/avatar.tsxavatar
      components/ui/avatar.tsx
      "use client"
      
      import * as React from "react"
      import { Avatar as AvatarPrimitive } from "@base-ui/react/avatar"
      import { cn } from "cn"
      
      /*
        Avatar: a person or agent. The image fades in over the tinted initials (no
        flash). `status` shows a dot that pops when it changes; `speaking` gives
        agent avatars a ring that breathes while they talk. AvatarGroup fans out on
        hover and the hovered avatar comes forward.
      */
      const sizes = { sm: "size-(--size-avatar-sm) text-[0.625rem]", md: "size-(--size-avatar-md) text-xs", lg: "size-(--size-avatar-lg) text-sm" }
      
      function Avatar({
        className,
        size = "md",
        status,
        speaking = false,
        children,
        ...props
      }: AvatarPrimitive.Root.Props & {
        size?: keyof typeof sizes
        status?: "online" | "away" | "busy" | "offline"
        speaking?: boolean
      }) {
        return (
          <span data-slot="avatar-wrap" data-speaking={speaking || undefined} className="avatar-wrap relative inline-flex shrink-0">
            <AvatarPrimitive.Root
              data-slot="avatar"
              className={cn(
                "relative inline-flex shrink-0 items-center justify-center overflow-hidden rounded-(--avatar-corner) bg-(--avatar-container) font-medium text-muted-foreground select-none",
                sizes[size],
                className
              )}
              {...props}
            >
              {children}
            </AvatarPrimitive.Root>
            {status ? (
              <span
                key={status}
                role="img"
                aria-label={status}
                data-status={status}
                className="avatar-status absolute right-0 bottom-0 size-2.5 rounded-full shadow-[0_0_0_2px_var(--color-bg-canvas)]"
              />
            ) : null}
          </span>
        )
      }
      
      function AvatarImage({ className, ...props }: AvatarPrimitive.Image.Props) {
        return <AvatarPrimitive.Image data-slot="avatar-image" className={cn("avatar-image absolute inset-0 size-full object-cover", className)} {...props} />
      }
      
      function AvatarFallback({ className, ...props }: AvatarPrimitive.Fallback.Props) {
        return <AvatarPrimitive.Fallback data-slot="avatar-fallback" className={cn("uppercase", className)} {...props} />
      }
      
      function AvatarGroup({ className, children, more, ...props }: React.ComponentProps<"div"> & { more?: number }) {
        return (
          <div data-slot="avatar-group" className={cn("avatar-group flex items-center", className)} {...props}>
            {children}
            {more ? (
              <span className="avatar-more relative inline-flex size-(--size-avatar-md) items-center justify-center rounded-full bg-surface-sunken text-xs text-muted-foreground shadow-[0_0_0_2px_var(--color-bg-canvas)]">
                +{more}
                <span className="sr-only"> more</span>
              </span>
            ) : null}
          </div>
        )
      }
      
      export { Avatar, AvatarImage, AvatarFallback, AvatarGroup }
      

Imports

What the examples on this page import:

Imports
import { Avatar, AvatarFallback, AvatarGroup } from "@/components/ui/avatar"

Anatomy

  1. 1Container · --avatar-size-*, --avatar-corner, --avatar-container.
  2. 2Image / fallback · Image fades in over the initials.
  3. 3Status dot · online, away, busy, offline.
  4. 4Speaking ring · --avatar-ring.

Props

PropTypeDefaultDescription
size"sm" | "md" | "lg""md"Diameter.
status"online" | "away" | "busy" | "offline"—Dot.
speakingboolean—Breathing ring.
AvatarGroup morenumber—Shows +N.

Tokens

Every visual spec is a component token in styles/tokens/components.css, pointing at a semantic token. Change a token to restyle the component; themes change the semantic layer.

TokenPoints toLightDark
--avatar-size-smvar(--size-avatar-sm)24pxsame
--avatar-size-mdvar(--size-avatar-md)32pxsame
--avatar-size-lgvar(--size-avatar-lg)40pxsame
--avatar-cornervar(--shape-full)999pxsame
--avatar-containervar(--color-bg-hover)oklch(0.965 0.005 95)oklch(0.22 0 0)
--avatar-ringvar(--stroke-color-focus)oklch(0.6 0.17 248)oklch(0.72 0.14 245)
--avatar-gap-strokevar(--surface-container-lowest)oklch(1 0 0)oklch(0.14 0 0)

Motion

TriggerWhat happensTokens
Hover group / speakFans out on a spring; ring breathes while speaking.--spring-snappy, --duration-pulse

Calm keeps the motion without overshoot. Still (and reduced motion) keeps a designed frame with no movement.

Accessibility

  • Give alt text or the person's name.
  • Status has a text label.

Usage

Do

  • Use for people and agents.

Don’t

  • Don't use for company logos.

Code

components/ui/avatar.tsx
"use client"

import * as React from "react"
import { Avatar as AvatarPrimitive } from "@base-ui/react/avatar"
import { cn } from "cn"

/*
  Avatar: a person or agent. The image fades in over the tinted initials (no
  flash). `status` shows a dot that pops when it changes; `speaking` gives
  agent avatars a ring that breathes while they talk. AvatarGroup fans out on
  hover and the hovered avatar comes forward.
*/
const sizes = { sm: "size-(--size-avatar-sm) text-[0.625rem]", md: "size-(--size-avatar-md) text-xs", lg: "size-(--size-avatar-lg) text-sm" }

function Avatar({
  className,
  size = "md",
  status,
  speaking = false,
  children,
  ...props
}: AvatarPrimitive.Root.Props & {
  size?: keyof typeof sizes
  status?: "online" | "away" | "busy" | "offline"
  speaking?: boolean
}) {
  return (
    <span data-slot="avatar-wrap" data-speaking={speaking || undefined} className="avatar-wrap relative inline-flex shrink-0">
      <AvatarPrimitive.Root
        data-slot="avatar"
        className={cn(
          "relative inline-flex shrink-0 items-center justify-center overflow-hidden rounded-(--avatar-corner) bg-(--avatar-container) font-medium text-muted-foreground select-none",
          sizes[size],
          className
        )}
        {...props}
      >
        {children}
      </AvatarPrimitive.Root>
      {status ? (
        <span
          key={status}
          role="img"
          aria-label={status}
          data-status={status}
          className="avatar-status absolute right-0 bottom-0 size-2.5 rounded-full shadow-[0_0_0_2px_var(--color-bg-canvas)]"
        />
      ) : null}
    </span>
  )
}

function AvatarImage({ className, ...props }: AvatarPrimitive.Image.Props) {
  return <AvatarPrimitive.Image data-slot="avatar-image" className={cn("avatar-image absolute inset-0 size-full object-cover", className)} {...props} />
}

function AvatarFallback({ className, ...props }: AvatarPrimitive.Fallback.Props) {
  return <AvatarPrimitive.Fallback data-slot="avatar-fallback" className={cn("uppercase", className)} {...props} />
}

function AvatarGroup({ className, children, more, ...props }: React.ComponentProps<"div"> & { more?: number }) {
  return (
    <div data-slot="avatar-group" className={cn("avatar-group flex items-center", className)} {...props}>
      {children}
      {more ? (
        <span className="avatar-more relative inline-flex size-(--size-avatar-md) items-center justify-center rounded-full bg-surface-sunken text-xs text-muted-foreground shadow-[0_0_0_2px_var(--color-bg-canvas)]">
          +{more}
          <span className="sr-only"> more</span>
        </span>
      ) : null}
    </div>
  )
}

export { Avatar, AvatarImage, AvatarFallback, AvatarGroup }