components / display
Avatar
A round profile picture with a fallback for when the image is missing.
383 B gzip client componentbase ui · avatar
DIABJD
avatar-default.tsx
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
export default function AvatarDefault() {
return (
<div className="flex items-center gap-3">
<Avatar>
<AvatarImage alt="di0rio" src="https://github.com/di0rio.png" />
<AvatarFallback>DI</AvatarFallback>
</Avatar>
<Avatar className="size-12">
<AvatarImage alt="" src="/missing-image.png" />
<AvatarFallback>AB</AvatarFallback>
</Avatar>
<Avatar className="size-8">
<AvatarFallback>JD</AvatarFallback>
</Avatar>
</div>
);
}Installation
$ npx shadcn@latest add https://cd-ui.vercel.app/r/avatar.jsonfirst time? set up components.json and the theme first: see installation.
Usage
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
<Avatar>
<AvatarImage alt="Ada Lovelace" src="/ada.png" />
<AvatarFallback>AL</AvatarFallback>
</Avatar>API
Avatar
Base UI · Avatar.RootRound container, 40px by default. Change the size with className (e.g. size-12).
| prop | type | default |
|---|---|---|
classNameExtra classes, merged with | string | - |
AvatarImage
Base UI · Avatar.ImageThe picture. It only shows after loading successfully.
| prop | type | default |
|---|---|---|
altGive | string | - |
classNameExtra classes, merged with | string | - |
AvatarFallback
Base UI · Avatar.FallbackShown while the image loads or if it fails (usually initials).
| prop | type | default |
|---|---|---|
delayWait (ms) before showing, to avoid a flash on fast loads. | number | - |
classNameExtra classes, merged with | string | - |
Accessibility
- Give
AvatarImageanaltwith the person's name, or an emptyaltwhen the name is written next to it.