Skip to content

Now in the official shadcn registry directory.

Start free

Avatar

A radix-based avatar with 5 sizes and 2 shapes. AvatarFallback renders while the image loads or if it fails.

display
A free styled version is available
A2AI
A2AIB2+2

Installation

Run the following command

npx shadcn@latest add @ai2/avatar

Dependencies, the @ai2/tokens theme and the component file are installed together.

Usage

TS
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"

<Avatar size="lg" shape="rounded">
  <AvatarImage src="https://ai2.design/avatars/ai2-01.svg" alt="ai2" />
  <AvatarFallback>A2</AvatarFallback>
</Avatar>

Put AvatarImage and AvatarFallback inside Avatar. The fallback shows while the image loads and stays if it fails.

Examples

Sizes

XSSMMDLGXL

Shapes

A2A2

Fallback

AI

The image here is intentionally broken, so AvatarFallback takes over without any extra code.

Avatar group

Wrap several avatars in AvatarGroup to lay them out as an overlapping stack. Each avatar gets a ring in the background color so the overlaps stay crisp in both themes.

A2AIB2

Avatar group with max

Set max to cap how many avatars appear; the extras collapse into a +N tile that closes the stack. This group holds five avatars with max={3}.

A2AIB2+2

Props

The axes live on the root Avatar. All three parts also accept their radix primitive props (e.g. onLoadingStatusChange on AvatarImage, delayMs on AvatarFallback).

PropTypeDefaultDescription
size"xs" | "sm" | "md" | "lg" | "xl""md"Avatar dimensions; fallback text is scaled to match automatically.
shape"circle" | "rounded""circle"Fully round or rounded-square silhouette.

AvatarGroup wraps a set of avatars and accepts the standard div props plus one axis of its own.

PropTypeDefaultDescription
maxnumberundefinedCap the number of avatars shown; the remainder collapse into a +N tile. Omit to render every child.

ai2 Avatar: radix avatar with graceful fallback for React

The ai2 Avatar is a shadcn-compatible react avatar component, built on the radix-ui Avatar primitive and styled with Tailwind CSS v4. It shows a user image with an automatic text fallback, in 5 sizes and 2 shapes, for navbars, comment threads, member lists and team stacks. The broken image problem is solved at the primitive level: the fallback renders while the image loads and stays if it never arrives.

It ships through the shadcn registry format, so you install it with one CLI command, an MCP agent, or a copy-paste, and the TypeScript source lands in your own project. You own the file; there is no runtime dependency on ai2 itself. The live example above is the exact component you get.

What is the ai2 Avatar?

It is a three-part composition: Avatar, AvatarImage and AvatarFallback. The anatomy matches shadcn/ui exactly, so existing snippets, muscle memory and AI agents keep working. On top, the root adds two cva axes: size (xs, sm, md, lg, xl) and shape (circle, rounded). A fourth export, AvatarGroup, stacks avatars into an overlapping facepile and, with a max prop, collapses the extras into a +N tile.

The radix primitive tracks the image loading state internally: AvatarFallback renders until the image has actually loaded, then swaps seamlessly, and comes back if the src errors. Fallback text scales with the size axis automatically (from 0.6rem at xs to lg text at xl), and the background comes from the ai2 surface tokens, so avatars sit correctly on both light and dark themes.

Why use it

  • No broken-image icons, ever: The radix Avatar primitive only shows AvatarImage after it loads successfully. Slow networks, missing files and blocked trackers all degrade to your initials fallback instead of a broken glyph.
  • Five sizes with matched typography: Each size pairs the box dimension with a fallback font size, so initials stay proportional from a 24px table avatar to a 64px profile header.
  • Two shapes from one prop: shape="circle" for people, shape="rounded" for teams, workspaces and bots. One prop, no border-radius overrides.
  • Token-driven surface: The placeholder background uses the ai2 surface-3 token, so empty avatars blend with your theme instead of showing a hardcoded gray.
  • Agent-readable metadata: The registry item describes the parts and axes in plain words, so an MCP agent can find, inspect and install it without guessing.

Features

  • shadcn registry install: One command adds the component, its radix dependency and the @ai2/tokens theme to your project.
  • Automatic image fallback: AvatarFallback renders during loading and on error, driven by the radix loading-status machine, with zero code on your side.
  • 5 sizes, 2 shapes: The cva axes cover xs (24px) through xl (64px) and circle or rounded silhouettes; the default is a medium circle.
  • Radix props forwarded: AvatarImage accepts onLoadingStatusChange and AvatarFallback accepts delayMs, so you can delay the fallback to avoid a flash on fast connections.
  • Data attributes for styling: Every part exposes data-slot (avatar, avatar-image, avatar-fallback), so you can restyle parts from CSS without forking the component.
  • TypeScript source: The file you install is typed end to end, including the exported avatarVariants function for matching other elements to avatar sizing.

Production tips

  • Always provide a fallback: Render AvatarFallback with initials (one or two characters) in every avatar. Without it, users see an empty circle while the image loads or after it fails.
  • Set alt on AvatarImage: Use the person's name as alt text. When the image renders, that is what screen readers announce; when it fails, make sure the surrounding row also contains the visible name.
  • Use delayMs to avoid fallback flash: On fast connections the fallback can flash for a frame before the image loads. Pass delayMs={600} to AvatarFallback so it only appears when loading is actually slow.
  • Pick shape by entity type: A consistent convention (circles for humans, rounded squares for organizations and bots) lets users parse member lists faster than any label.
  • Reach for AvatarGroup for facepiles: Instead of hand-rolling a flex row, wrap avatars in AvatarGroup: it applies -space-x-2 and a ring in the page background color so overlapping edges stay crisp in both themes, and its max prop caps the stack with a +N tile.

Works with the rest of ai2

Avatars anchor identity across the registry. Pair one with an ai2 Badge for presence or role labels, put it inside an ai2 Dropdown Menu trigger for the classic account menu, or wrap it in an ai2 Tooltip to reveal the full name in compact facepiles.

In content, avatars lead ai2 Card headers for author bylines and sit in ai2 Table member columns at the xs size. Everything shares one token source, so the placeholder surface matches the rest of your theme in both modes.

FAQs

Get new components in your inbox

Component drops, new themes and release notes. No spam, and you can unsubscribe from any email.

© 2026 ai2 design system · MIT licensed · Built with its own components