Summit
ComponentsDisplay

Avatar

An Avatar shows users someone’s image or, when no image loads, their initials.

When to Use

  • to show someone next to their name, such as in the Sidebar’s account button, in a Table row, or on a Message
  • as an AvatarGroup, for everyone on one record, with AvatarGroupCount for those who don’t fit, such as “+3”
  • for a mark on the Avatar’s corner, like a check, with AvatarBadge

When Not to Use

  • for an image with a fixed ratio, like a cover photo (use an Aspect Ratio)
  • for a status with a label (use a Badge)

Anatomy

CR
CR
CRJM
+3
ElementUsage
Image*Optional
ContainerRequired
BadgeOptional
Fallback*Optional
GroupOptional
CountOptional

* An Avatar has an image, a fallback, or both.

Shapes

To set the corner, pass shape. By default, it is round.

Sizes

SizeWidth and HeightPlacement
sm24pxA Table row, a menu, or a Field
default32pxThe Sidebar and a comment
lg40pxNext to a page title

In a Table, the Avatar sets the height of its row.

DoUse sm in a Table row; each row is 40px tall.
Don’tWhen lg is used in a Table row, each row grows to 56px, and users see fewer records in the Table.

Behavior

An Avatar is a square with a fixed size, and it doesn’t shrink in a flex row.

Loading

AvatarImage isn’t rendered until its image has loaded. Until then, and when the image fails or has no src, AvatarFallback is shown. If you want to delay the fallback, set delay on it to a number of milliseconds. Users then don’t see the initials flash before an image that loads sooner.

DoAdd a fallback to every Avatar; the initials are shown until the image loads and when it fails.
Don’tWhen the fallback is missing and the image fails, users see an empty ring and can’t tell who it represents.

Badge

AvatarBadge contains an icon and no text, and the icon is hidden at sm.

Content

StringRuleExampleCounterexample
FallbackThe person’s initials“CR”“Camille”
alt of the imageThe person’s name“Camille Roy”“Avatar”
CountA plus sign and the number of Avatars not shown“+3”“3 more”

Accessibility

An Avatar isn’t focusable and has no role. Screen readers read the alt of the image or, when no image is shown, the text of the fallback.

An AvatarImage needs alt so that screen readers can announce who the image shows, as WCAG 2.2 SC 1.1.1 Non-text Content requires. Use the person’s name. If the name is shown next to the Avatar, set alt="" so that it isn’t read twice.

An AvatarBadge has no text, so a status that it marks must also be stated in words for screen reader users, as WCAG 2.2 SC 1.1.1 Non-text Content requires. Place the words next to the Avatar or in sr-only text inside the badge, and set aria-hidden on the icon.

Installation

npx shadcn@latest add @summit/avatar

Usage

import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';

<Avatar>
    <AvatarImage src="/camille-roy.jpg" alt="Camille Roy" />
    <AvatarFallback>CR</AvatarFallback>
</Avatar>;

Initials Only

To show only the initials, omit AvatarImage.

Initials Only
<Avatar size="sm">
    <AvatarFallback>CR</AvatarFallback>
</Avatar>

Square

Set shape="square".

Square
<Avatar shape="square">
    <AvatarFallback>CR</AvatarFallback>
</Avatar>

With a Badge

Place AvatarBadge last in the Avatar, with one icon inside it.

With a Badge
import { AvatarBadge } from '@/components/ui/avatar';
import { CheckIcon } from '@phosphor-icons/react';

<Avatar>
    <AvatarImage src="/camille-roy.jpg" alt="Camille Roy" />
    <AvatarFallback>CR</AvatarFallback>
    <AvatarBadge>
        <CheckIcon aria-hidden />
    </AvatarBadge>
</Avatar>;

A Group

Use the same size and the same shape for all the Avatars in a group. AvatarGroupCount follows them.

A Group
import { AvatarGroup, AvatarGroupCount } from '@/components/ui/avatar';

<AvatarGroup>
    <Avatar>
        <AvatarImage src="/camille-roy.jpg" alt="Camille Roy" />
        <AvatarFallback>CR</AvatarFallback>
    </Avatar>
    <Avatar>
        <AvatarImage src="/jonas-meyer.jpg" alt="Jonas Meyer" />
        <AvatarFallback>JM</AvatarFallback>
    </Avatar>
    <AvatarGroupCount>+3</AvatarGroupCount>
</AvatarGroup>;

API Reference

Avatar, AvatarImage, and AvatarFallback accept the props of Avatar.Root, Avatar.Image, and Avatar.Fallback in Base UI. See the Base UI Avatar documentation for delay, keepMounted, and onLoadingStatusChange. The other three parts pass their props to their element.

Avatar

PropTypeDefaultDescription
size'default' | 'sm' | 'lg''default'The width and the height
shape'round' | 'square''round'The corner of the Avatar

On this page