Display user profile images with customizable fallback content.
Import
import { Avatar } from '@heroui/react';Usage
JDBJR
import { Avatar } from "@heroui/react";
export function Basic() {
return (
<div className="flex items-center gap-4">
<Avatar>
<Avatar.Image alt="John Doe" src="https://img.heroui.chat/image/avatar?w=400&h=400&u=3" />
<Avatar.Fallback>JD</Avatar.Fallback>
</Avatar>
<Avatar>
<Avatar.Image
alt="Blue"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg"
/>
<Avatar.Fallback>B</Avatar.Fallback>
</Avatar>
<Avatar>
<Avatar.Fallback>JR</Avatar.Fallback>
</Avatar>
</div>
);
}Anatomy
Import the Avatar component and access all parts using dot notation.
import { Avatar } from '@heroui/react';
export default () => (
<Avatar>
<Avatar.Image/>
<Avatar.Fallback/>
</Avatar>
)Sizes
SMMDLG
import { Avatar } from "@heroui/react";
export function Sizes() {
return (
<div className="flex items-center gap-4">
<Avatar size="sm">
<Avatar.Image
alt="Small Avatar"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg"
/>
<Avatar.Fallback>SM</Avatar.Fallback>
</Avatar>
<Avatar size="md">
<Avatar.Image
alt="Medium Avatar"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/purple.jpg"
/>
<Avatar.Fallback>MD</Avatar.Fallback>
</Avatar>
<Avatar size="lg">
<Avatar.Image
alt="Large Avatar"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/red.jpg"
/>
<Avatar.Fallback>LG</Avatar.Fallback>
</Avatar>
</div>
);
}Colors
DFACSCWRDG
import { Avatar } from "@heroui/react";
export function Colors() {
return (
<div className="flex items-center gap-4">
<Avatar>
<Avatar.Fallback>DF</Avatar.Fallback>
</Avatar>
<Avatar color="accent">
<Avatar.Fallback>AC</Avatar.Fallback>
</Avatar>
<Avatar color="success">
<Avatar.Fallback>SC</Avatar.Fallback>
</Avatar>
<Avatar color="warning">
<Avatar.Fallback>WR</Avatar.Fallback>
</Avatar>
<Avatar color="danger">
<Avatar.Fallback>DG</Avatar.Fallback>
</Avatar>
</div>
);
}Variants
DFACSCWRDG
import { Avatar } from "@heroui/react";
export function Variants() {
return (
<div className="flex items-center gap-4">
<Avatar variant="default">
<Avatar.Fallback>DF</Avatar.Fallback>
</Avatar>
<Avatar variant="soft" color="accent">
<Avatar.Fallback>AC</Avatar.Fallback>
</Avatar>
<Avatar variant="soft" color="success">
<Avatar.Fallback>SC</Avatar.Fallback>
</Avatar>
<Avatar variant="soft" color="warning">
<Avatar.Fallback>WR</Avatar.Fallback>
</Avatar>
<Avatar variant="soft" color="danger">
<Avatar.Fallback>DG</Avatar.Fallback>
</Avatar>
</div>
);
}Fallback Content
JD
GB
import { Avatar } from "@heroui/react";
export function Fallback() {
return (
<div className="flex items-center gap-4">
{/* Text fallback */}
<Avatar>
<Avatar.Fallback>JD</Avatar.Fallback>
</Avatar>
{/* Fallback with delay */}
<Avatar>
<Avatar.Image
alt="Delayed Avatar"
src="https://invalid-url-to-show-fallback.com/image.jpg"
/>
<Avatar.Fallback delayMs={600}>NA</Avatar.Fallback>
</Avatar>
{/* Custom styled fallback */}
<Avatar>
<Avatar.Fallback className="border-none bg-gradient-to-br from-pink-500 to-purple-500 text-white">
GB
</Avatar.Fallback>
</Avatar>
</div>
);
}Avatar Group
JDKWEC+2
import { Avatar } from "@heroui/react";
const users = [
{
id: 1,
image: "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg",
name: "John Doe",
},
{
id: 2,
image: "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg",
name: "Kate Wilson",
},
{
id: 3,
image: "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/purple.jpg",
name: "Emily Chen",
},
{
id: 4,
image: "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/orange.jpg",
name: "Michael Brown",
},
{
id: 5,
image: "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/red.jpg",
name: "Olivia Davis",
},
];
export function Group() {
return (
<div className="flex flex-col gap-6">
{/* Basic avatar group */}
<div className="flex -space-x-2">
{users.slice(0, 4).map((user) => (
<Avatar key={user.id} className="ring-2 ring-background">
<Avatar.Image alt={user.name} src={user.image} />
<Avatar.Fallback>
{user.name
.split(" ")
.map((n) => n[0])
.join("")}
</Avatar.Fallback>
</Avatar>
))}
</div>
{/* Avatar group with counter */}
<div className="flex -space-x-2">
{users.slice(0, 3).map((user) => (
<Avatar key={user.id} className="ring-2 ring-background">
<Avatar.Image alt={user.name} src={user.image} />
<Avatar.Fallback>
{user.name
.split(" ")
.map((n) => n[0])
.join("")}
</Avatar.Fallback>
</Avatar>
))}
<Avatar className="ring-2 ring-background">
<Avatar.Fallback className="text-xs">+{users.length - 3}</Avatar.Fallback>
</Avatar>
</div>
</div>
);
}Custom Styles
XLSQ
GB
import { Avatar } from "@heroui/react";
export function CustomStyles() {
return (
<div className="flex items-center gap-4">
{/* Custom size with Tailwind classes */}
<Avatar className="size-16">
<Avatar.Image
alt="Extra Large"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg"
/>
<Avatar.Fallback>XL</Avatar.Fallback>
</Avatar>
{/* Square avatar */}
<Avatar className="rounded-lg">
<Avatar.Image
alt="Square Avatar"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/purple.jpg"
/>
<Avatar.Fallback className="rounded-lg">SQ</Avatar.Fallback>
</Avatar>
{/* Gradient border */}
<Avatar className="bg-gradient-to-tr from-pink-500 to-yellow-500 p-0.5">
<div className="size-full rounded-full bg-background p-0.5">
<Avatar.Image
alt="Gradient Border"
className="rounded-full"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/red.jpg"
/>
<Avatar.Fallback className="border-none">GB</Avatar.Fallback>
</div>
</Avatar>
</div>
);
}Styling
Passing Tailwind CSS classes
import { Avatar } from '@heroui/react';
function CustomAvatar() {
return (
<Avatar className="size-20">
<Avatar.Image src="..." alt="..." />
<Avatar.Fallback>XL</Avatar.Fallback>
</Avatar>
);
}Customizing the component classes
To customize the Avatar component classes, you can use the @layer components directive.
@layer components {
.avatar {
@apply size-16 border-2 border-primary;
}
.avatar__fallback {
@apply bg-gradient-to-br from-purple-500 to-pink-500;
}
}HeroUI follows the BEM methodology to ensure component variants and states are reusable and easy to customize.
CSS Classes
The Avatar component uses these CSS classes:
Base Classes
.avatar— Base container with default size (size-10).avatar__image— Image element with aspect-square sizing.avatar__fallback— Fallback container with centered content
Size Modifiers
.avatar--sm— Small avatar (size-8).avatar--md— Medium avatar (default, no additional styles).avatar--lg— Large avatar (size-12)
Variant Modifiers
.avatar--soft— Soft variant with lighter background
Color Modifiers
.avatar__fallback--default— Default text color.avatar__fallback--accent— Accent text color.avatar__fallback--success— Success text color.avatar__fallback--warning— Warning text color.avatar__fallback--danger— Danger text color
API Reference
Avatar Props
| Prop | Type | Default | Description |
|---|---|---|---|
size | 'sm' | 'md' | 'lg' | 'md' | Avatar size |
color | 'default' | 'accent' | 'success' | 'warning' | 'danger' | 'default' | Fallback color theme |
variant | 'default' | 'soft' | 'default' | Visual style variant |
className | string | — | Additional CSS classes |