Avatar
Represents a person or an organization with a photo, and falls back to initials when there is no image.
MS
When to use
- To show who owns, reviewed or created something: the reviewer of a task, the author of a comment.
- Next to a name in lists, tables and menus, to make people easier to scan.
- To identify an organization, such as a cliente, with the
squaretype.
When not to use
- Status or category. Use Tag or Badge.
- A count of unread items. Use Notification badge.
- A product or brand mark. Use the Logo components.
- A generic icon. Use a Lucide icon. An avatar always stands for a specific person or entity.
Sizes
MSxsm · 24px
MSsm · 36px
MSmd · 48px
MSlg · 80px
MSxl · 96px
| Size | Dimensions | Use for |
|---|---|---|
xsm |
24px | Dense tables and stacked groups. |
sm |
36px | Lists and comments. |
md |
48px | Default. Cards and menus. |
lg |
80px | Profile headers. |
xl |
96px | Profile pages. |
Size sets the width, the height and the text size of the fallback together.
Types
BAcircular
BAsquare
| Type | Use for |
|---|---|
circular |
People. The default. |
square |
Organizations, such as a cliente or a vara. |
States
Image and fallback
AvatarImage shows the photo. While it loads or if it fails, AvatarFallback shows instead. Always render both.
MS
Fallback initials
A string child becomes initials: a full name gives the first letter of the first two words, a single name gives one letter, and exactly two letters are kept as written.
MSNome completo
RUm nome
TCIniciais
Content
- Pass the full name to
AvatarFallback, not hand-made initials: “Camila Ribeiro”, not “CR”. - Write the
altofAvatarImageas the person’s name. If the name is already visible next to the avatar, usealt="". - Do not use an avatar without a name nearby, unless a tooltip or an accessible name gives it.
Do and don’t
RARafael Almeida
RBRenata Barros
RRafael
RRenata
Accessibility
- Built on Radix Avatar: the image only mounts once it loads, and the fallback shows until then or when it fails.
- The root is a plain
spanwith no role. Initials in the fallback are read as text, so a name written next to the avatar is read twice. In that case addaria-hiddento the avatar. - Give
AvatarImageanaltthat names the person, oralt=""when the name is visible beside it. - An avatar that opens a menu or profile must be wrapped in a button with an
aria-label. The avatar itself is not interactive. - Do not rely on the image or the color alone to tell people apart.
Code
import { Avatar, AvatarFallback, AvatarImage } from "@repo/ui/avatar";
<Avatar size="sm">
<AvatarImage alt="Foto de Mariana Souza" src={photoUrl} />
<AvatarFallback>Mariana Souza</AvatarFallback>
</Avatar>;
Props
Avatar| Prop | Type | Default | Description |
|---|---|---|---|
size | "lg" | "md" | "sm" | "xl" | "xsm" | md | Width, height and fallback text size |
type | "circular" | "square" | circular | Circular for people, square for organizations |
AvatarImage| Prop | Type | Default | Description |
|---|---|---|---|
src | string | — | URL of the photo. If it fails to load, the fallback shows. |
alt | string | — | Accessible description. Use the person's name, or an empty string if the name is visible nearby. |
AvatarFallback| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | A string is shortened to initials. Any other node is rendered as is. |
delayMs | number | — | Waits this many milliseconds before showing the fallback, to avoid a flash while the photo loads. |
Known issues
| Issue | Effect |
|---|---|
The xsm fallback uses text-[0.625rem] (10px). |
Initials are hard to read on older monitors. |
| The initials take the first letter of the first two words, particles included. | “Maria da Silva” becomes “MD”. Pass the two letters you want, such as “MS”. |
The fallback is not aria-hidden and the root has no role. |
Initials are announced as letters next to a visible name. |
AvatarFallback checks two letters with /^[A-Za-z]{2}$/. |
Two-letter names with accents (for example “Éd”) are reduced to one letter. |