Skip to content
Blobz docs

Avatar

Familiar shadcn avatar primitives, with a generated face whenever an image is unavailable.

Rounded

Rounded is the default. Compose Avatar with an AvatarFallback to give every profile a deterministic face.

Janaki Ammal avatarVikram Sarabhai avatarKalpana Chawla avatar
View code
avatar-example.tsx
import { Avatar, AvatarFallback } from "@/components/ui/avatar";

const BLUE_PALETTE = ["#dff4ff", "#38bdf8"] as const;

export function AvatarExample() {
	return (
		<div className="flex items-end gap-5">
			<Avatar size="lg">
				<AvatarFallback
					alt={`${"Janaki Ammal"} avatar`}
					name={"Janaki"}
					palette={BLUE_PALETTE}
				/>
			</Avatar>
			<Avatar size="xl" variant="outline">
				<AvatarFallback
					alt={`${"Vikram Sarabhai"} avatar`}
					name={"Vikram"}
					palette={BLUE_PALETTE}
				/>
			</Avatar>
			<Avatar size="lg" variant="elevated">
				<AvatarFallback
					alt={`${"Kalpana Chawla"} avatar`}
					name={"Kalpana"}
					palette={BLUE_PALETTE}
				/>
			</Avatar>
		</div>
	);
}

Installation

npx shadcn@latest add @blobz/avatar

This installs the avatar at your configured shadcn UI path, along with its dependencies. If you already have a shadcn avatar, review the CLI diff and replace it with this implementation to enable generated fallbacks.

Usage

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

<Avatar>
  <AvatarImage alt="Lirena" src="https://www.lirena.in/favicon.jpg" />
  <AvatarFallback name="Lirena" />
</Avatar>

AvatarImage displays the supplied image. AvatarFallback renders a Blobz face while the image loads, when it fails, or when no image is supplied. The same name always generates the same face. Existing text fallbacks, such as <AvatarFallback>LR</AvatarFallback>, work too.

Use alt="" on both the image and fallback when a visible name beside the avatar already identifies the person.

Images and fallbacks

The first avatar uses the Lirena image. The second has no image, and the third demonstrates a failed image. All three use the same fallback name.

Blob avatar for lirenaImage
Blob avatar for lirenaGenerated
Blob avatar for lirenaImage unavailable
View code
avatar-image-example.tsx
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";

export function AvatarImageExample() {
	return (
		<div className="flex flex-wrap justify-center gap-8 sm:gap-12">
			<div className="flex flex-col items-center gap-3">
				<Avatar size="xl">
					<AvatarImage alt="Lirena" src="https://www.lirena.in/favicon.jpg" />
					<AvatarFallback name="Lirena" />
				</Avatar>
				<span className="text-muted-foreground text-xs">Image</span>
			</div>
			<div className="flex flex-col items-center gap-3">
				<Avatar size="xl">
					<AvatarFallback name="Lirena" />
				</Avatar>
				<span className="text-muted-foreground text-xs">Generated</span>
			</div>
			<div className="flex flex-col items-center gap-3">
				<Avatar size="xl">
					<AvatarImage alt="Lirena" src="data:image/png;base64,invalid" />
					<AvatarFallback name="Lirena" />
				</Avatar>
				<span className="text-muted-foreground text-xs">Image unavailable</span>
			</div>
		</div>
	);
}

Circle

Use frame="circle" for a circular crop. The image and generated fallback inherit the same frame.

Janaki Ammal avatarVikram Sarabhai avatar
View code
avatar-circle-example.tsx
import { Avatar, AvatarFallback } from "@/components/ui/avatar";

const BLUE_PALETTE = ["#dff4ff", "#38bdf8"] as const;

export function AvatarCircleExample() {
	return (
		<div className="flex items-center gap-5">
			<Avatar frame="circle" size="xl">
				<AvatarFallback
					alt={`${"Janaki Ammal"} avatar`}
					name={"Janaki"}
					palette={BLUE_PALETTE}
				/>
			</Avatar>
			<Avatar frame="circle" size="xl" variant="outline">
				<AvatarFallback
					alt={`${"Vikram Sarabhai"} avatar`}
					name={"Vikram"}
					palette={BLUE_PALETTE}
				/>
			</Avatar>
		</div>
	);
}

Square

Use frame="square" for an edge-to-edge square crop.

Kalpana Chawla avatarSrinivasa Ramanujan avatar
View code
avatar-square-example.tsx
import { Avatar, AvatarFallback } from "@/components/ui/avatar";

const BLUE_PALETTE = ["#dff4ff", "#38bdf8"] as const;

export function AvatarSquareExample() {
	return (
		<div className="flex items-center gap-5">
			<Avatar frame="square" size="xl">
				<AvatarFallback
					alt={`${"Kalpana Chawla"} avatar`}
					name={"Kalpana"}
					palette={BLUE_PALETTE}
				/>
			</Avatar>
			<Avatar frame="square" size="xl" variant="outline">
				<AvatarFallback
					alt={`${"Srinivasa Ramanujan"} avatar`}
					name={"Srinivasa"}
					palette={BLUE_PALETTE}
				/>
			</Avatar>
		</div>
	);
}

Sizes

Choose sm, default, lg, or xl. Use className when your layout needs a custom size.

Blob avatar for janakism
Blob avatar for janakidefault
Blob avatar for janakilg
Blob avatar for janakixl
View code
avatar-sizes-example.tsx
import { Avatar, AvatarFallback } from "@/components/ui/avatar";

const SIZES = ["sm", "default", "lg", "xl"] as const;

export function AvatarSizesExample() {
	return (
		<div className="flex flex-wrap items-end justify-center gap-7">
			{SIZES.map((size) => (
				<div className="flex flex-col items-center gap-3" key={size}>
					<Avatar size={size}>
						<AvatarFallback name="Janaki" />
					</Avatar>
					<span className="text-muted-foreground text-xs">{size}</span>
				</div>
			))}
		</div>
	);
}

Surfaces

Default displays the avatar without a border. Outline adds a contrasting ring with a small gap. Elevated places the image inside a padded card frame with a shadow. Every frame follows the same proportional crop as the generated image, including at custom sizes.

Generated
Blob avatar for vikramdefault
Blob avatar for vikramoutline
Blob avatar for vikramelevated
Image
Blob avatar for lirenadefault
Blob avatar for lirenaoutline
Blob avatar for lirenaelevated
View code
avatar-surfaces-example.tsx
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";

const SURFACES = ["default", "outline", "elevated"] as const;
const SOURCES = [
	{ label: "Generated", name: "Vikram", src: undefined },
	{ label: "Image", name: "Lirena", src: "https://www.lirena.in/favicon.jpg" },
] as const;

export function AvatarSurfacesExample() {
	return (
		<div className="flex flex-col gap-8">
			{SOURCES.map(({ label, name, src }) => (
				<div className="flex flex-col gap-4" key={label}>
					<span className="text-muted-foreground text-xs">{label}</span>
					<div className="grid grid-cols-3 gap-6 sm:gap-10">
						{SURFACES.map((variant) => (
							<div className="flex flex-col items-center gap-3" key={variant}>
								<Avatar size="xl" variant={variant}>
									<AvatarImage alt={name} src={src} />
									<AvatarFallback name={name} />
								</Avatar>
								<span className="text-muted-foreground text-xs">{variant}</span>
							</div>
						))}
					</div>
				</div>
			))}
		</div>
	);
}

Status

Add an AvatarBadge inside the avatar. Online, away, busy, and offline include accessible status labels. Override aria-label for your product's terminology.

Janaki Ammal avatarVikram Sarabhai avatarKalpana Chawla avatarSrinivasa Ramanujan avatar
View code
avatar-status-example.tsx
import { Avatar, AvatarBadge, AvatarFallback } from "@/components/ui/avatar";

const BLUE_PALETTE = ["#dff4ff", "#38bdf8"] as const;

export function AvatarStatusExample() {
	return (
		<div className="flex items-center gap-6">
			<Avatar size="xl">
				<AvatarFallback
					alt={`${"Janaki Ammal"} avatar`}
					name={"Janaki"}
					palette={BLUE_PALETTE}
				/>
				<AvatarBadge status="online" />
			</Avatar>
			<Avatar size="xl">
				<AvatarFallback
					alt={`${"Vikram Sarabhai"} avatar`}
					name={"Vikram"}
					palette={BLUE_PALETTE}
				/>
				<AvatarBadge status="away" />
			</Avatar>
			<Avatar size="xl">
				<AvatarFallback
					alt={`${"Kalpana Chawla"} avatar`}
					name={"Kalpana"}
					palette={BLUE_PALETTE}
				/>
				<AvatarBadge status="busy" />
			</Avatar>
			<Avatar size="xl">
				<AvatarFallback
					alt={`${"Srinivasa Ramanujan"} avatar`}
					name={"Srinivasa"}
					palette={BLUE_PALETTE}
				/>
				<AvatarBadge status="offline" />
			</Avatar>
		</div>
	);
}
<Avatar>
  <AvatarFallback name="Janaki" />
  <AvatarBadge status="online" />
</Avatar>

Import AvatarBadge from the same @/components/ui/avatar module.

Indicator positions

The position prop accepts four logical corners and follows the document direction.

Top start status positionTop start
Top end status positionTop end
Bottom start status positionBottom start
Bottom end status positionBottom end
View code
avatar-status-positions-example.tsx
import { Avatar, AvatarBadge, AvatarFallback } from "@/components/ui/avatar";

const BLUE_PALETTE = ["#dff4ff", "#38bdf8"] as const;
const POSITIONS = [
	{ label: "Top start", position: "top-start" },
	{ label: "Top end", position: "top-end" },
	{ label: "Bottom start", position: "bottom-start" },
	{ label: "Bottom end", position: "bottom-end" },
] as const;

export function AvatarStatusPositionsExample() {
	return (
		<div className="grid grid-cols-2 gap-x-10 gap-y-8 sm:grid-cols-4">
			{POSITIONS.map(({ label, position }) => (
				<div className="flex flex-col items-center gap-3" key={position}>
					<Avatar size="xl">
						<AvatarFallback
							alt={`${label} status position`}
							name={position}
							palette={BLUE_PALETTE}
						/>
						<AvatarBadge position={position} status="online" />
					</Avatar>
					<span className="text-muted-foreground text-xs">{label}</span>
				</div>
			))}
		</div>
	);
}

Unread counts

Use AvatarCount for unread messages, on its own or alongside a status badge. Counts above 99 display as 99+, while the accessible label announces the full count. Zero, negative, and non-finite counts are hidden.

Blob avatar for vikramBlob avatar for kalpana
View code
avatar-unread-example.tsx
import {
	Avatar,
	AvatarBadge,
	AvatarCount,
	AvatarFallback,
} from "@/components/ui/avatar";

export function AvatarUnreadExample() {
	return (
		<div className="flex flex-wrap items-center justify-center gap-10">
			<Avatar frame="circle" size="xl">
				<AvatarFallback name="Vikram" palette={["#fff0e2", "#fa9769"]} />
				<AvatarCount count={3} />
			</Avatar>
			<Avatar frame="circle" size="xl">
				<AvatarFallback name="Kalpana" palette={["#e7fbe8", "#9ce786"]} />
				<AvatarBadge status="online" />
				<AvatarCount count={128} />
			</Avatar>
		</div>
	);
}

For overlapping avatars and social proof, see Avatar Group.

API

Avatar

Accepts Base UI Avatar Root props, including ref, render, and className, plus:

Prop

Type

AvatarImage

Accepts Base UI Avatar Image props, including src, alt, keepMounted, loading, and onLoadingStatusChange. Image loading and error recovery are handled by Base UI, including when src changes.

AvatarFallback

Accepts Base UI Avatar Fallback props, including delay, ref, render, and children, plus:

Prop

Type

AvatarBadge and AvatarCount

AvatarBadge accepts span props, optional status (online, away, busy, offline), and position (top-start, top-end, bottom-start, bottom-end). The default position is bottom-end. Omit status to provide your own badge contents.

AvatarCount accepts span props and a required numeric count. It sits at the top end of the avatar; use aria-label to customize the announcement.