UI.MD

Avatar

An image element with a text fallback for representing a user or entity.

Installation

$
npx shadcn@latest add https://ui.mattdowney.com/r/avatar.json

Usage

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

Examples

Default

Image with a text fallback, plus an optional status dot.

MDUI
SC

Sizes

Four sizes from one prop. The fallback text scales with the box.

MDMDMDMD

Group

Overlap with -space-x-2 and a ring-background outline; cap with a +N tile.

MDSCUI+3

API Reference

PropTypeDefaultDescription
sizeAvatar"sm" | "default" | "lg" | "xl""default"The avatar size: sm (24px), default (32px), lg (40px), or xl (48px). The fallback text scales with it, so you never set two classes.
srcAvatarImagestring-Image source URL. The image only renders once it has loaded; the fallback shows until then.
onLoadingStatusChangeAvatarImage(status: "idle" | "loading" | "loaded" | "error") => void-Called when the image's loading status changes.
delayMsAvatarFallbacknumber-Delay in milliseconds before the fallback renders, avoiding a flash when the image loads quickly.