Avatar
An image element with a fallback for representing the user.
Installation
bash
npx shadcn@latest add @redpanda/avatarbash
pnpm dlx shadcn@latest add @redpanda/avatarbash
yarn dlx shadcn@latest add @redpanda/avatarbash
bunx shadcn@latest add @redpanda/avatarbash
nubx shadcn@latest add @redpanda/avatarbash
aube dlx shadcn@latest add @redpanda/avatarShape
Use shape="square" for rounded-square avatars. The default, shape="round", remains circular.
The image and fallback inherit the root radius, so loading an image does not change the shape.
tsx
<Avatar shape="square"> <AvatarImage src="/user.jpg" alt="Alex" /> <AvatarFallback>AL</AvatarFallback></Avatar>Sizes
Fallback only
Fallback variations
With status dot
With notification badge
Usage
Basic Example
tsx
import { Avatar, AvatarFallback, AvatarImage } from '@/components/redpanda-ui/avatar';
<Avatar> <AvatarImage src="https://github.com/malinskibeniamin.png" alt="@malinskibeniamin" /> <AvatarFallback>BM</AvatarFallback></Avatar>;Different Sizes
tsx
// Small avatar<Avatar className="h-6 w-6"> <AvatarImage src="/user-small.jpg" alt="User" /> <AvatarFallback className="text-xs">U</AvatarFallback></Avatar>
// Default avatar (32px)<Avatar> <AvatarImage src="/user-default.jpg" alt="User" /> <AvatarFallback>JD</AvatarFallback></Avatar>
// Large avatar<Avatar className="h-12 w-12"> <AvatarImage src="/user-large.jpg" alt="User" /> <AvatarFallback>JD</AvatarFallback></Avatar>
// Extra large avatar<Avatar className="h-16 w-16"> <AvatarImage src="/user-xl.jpg" alt="User" /> <AvatarFallback className="text-lg">JD</AvatarFallback></Avatar>Fallback Examples
tsx
// Text initials<Avatar> <AvatarImage src="/broken-link.jpg" alt="User" /> <AvatarFallback>JD</AvatarFallback></Avatar>
// Icon fallback<Avatar> <AvatarImage src="/broken-link.jpg" alt="User" /> <AvatarFallback> <User className="h-4 w-4" /> </AvatarFallback></Avatar>
// Custom background<Avatar> <AvatarImage src="/broken-link.jpg" alt="User" /> <AvatarFallback tone="brand">AD</AvatarFallback></Avatar>Status Indicators
tsx
<div className="relative"> <Avatar> <AvatarImage src="/user.jpg" alt="User" /> <AvatarFallback>JD</AvatarFallback> </Avatar> {/* Online status */} <span className="absolute bottom-0 right-0 block h-3 w-3 rounded-full bg-success-strong ring-2 ring-background" /></div>
<div className="relative"> <Avatar> <AvatarImage src="/user.jpg" alt="User" /> <AvatarFallback>JD</AvatarFallback> </Avatar> {/* Away status */} <span className="absolute bottom-0 right-0 block h-3 w-3 rounded-full bg-warning-strong ring-2 ring-background" /></div>When to use
Use Avatar to represent users or entities with their profile image and a fallback option:
Use Avatar when:
- Displaying user profile pictures in interfaces
- Showing author information in comments or posts
- Representing team members or contacts
- Building user lists or member directories
- Creating user account interfaces
Don’t use Avatar when:
- Displaying non-user related images (use Image instead)
- Building image galleries (use Image)
- Showing logos or brand images (use Image)
- The image doesn’t represent a person or entity
Anatomy
The Avatar component uses a layered approach with automatic fallback handling:
plaintext
Avatar Container (32px × 32px by default)┌─────────────────────────────────────────────────┐│ Avatar Root (relative, rounded-full) ││ ┌─────────────────────────────────────────────┐ ││ │ AvatarImage (absolute, fills container) │ ││ │ - Loads asynchronously │ ││ │ - Hidden if fails to load │ ││ └─────────────────────────────────────────────┘ ││ ┌─────────────────────────────────────────────┐ ││ │ AvatarFallback (backup content) │ ││ │ - Shows when image fails/loading │ ││ │ - Text initials or icon │ ││ │ - Centered content │ ││ └─────────────────────────────────────────────┘ │└─────────────────────────────────────────────────┘
Fallback Logic:1. Show AvatarImage if available and loads successfully2. Show AvatarFallback if image fails or while loading3. AvatarFallback always rendered but hidden when image loadsComponent Hierarchy:
- Avatar (Root): Container with circular shape and sizing
- AvatarImage: Primary image that loads asynchronously
- AvatarFallback: Backup content (initials, icon, or text)
Key Features:
- Automatic Fallback: Seamlessly switches between image and fallback
- Loading States: Handles image loading gracefully
- Responsive: Easily customizable sizes with CSS classes
- Accessible: Proper alt text and semantic structure
- Circular Shape: Default rounded-full styling
Common Patterns:
- User Initials: First letter of first and last name
- Icon Fallback: Generic user icon when no initials available
- Custom Colors: Different background colors for visual variety
- Status Indicators: Overlay elements for online/offline status
- Size Variants: Small (24px), Default (32px), Large (48px), XL (64px)
Owned identity appearance
AvatarFallback tone="default"preserves the neutral fallback.primary,success, andbrandown their corresponding fill/foreground pairs; do not restyle the fallback’s background or text. A tone is identity appearance, not an accessible online/offline status. Use a separately named status indicator when needed.AvatarImage monochromedesaturates only the photo. Its fallback and unrelated status indicators stay unchanged.- The static
AvatarGroupexported fromavataracceptsmonochrometo desaturate each direct avatar subtree, including fallback content. This is deliberately different from photo-only monochrome. Avatar frame="group"adds the owned background-colored separator border for overlapping identity images. The defaultframe="none"leaves existing geometry unchanged.
Props
Accessibility
- Always provide
altonAvatarImage— either the user’s display name for identification, oralt=""when the avatar is purely decorative next to a visible name. AvatarFallbackis rendered while the image is loading and when it fails; keep initials to 1–2 characters so they remain legible at small sizes.- No keyboard interactions —
Avataris purely presentational. Wrap it in an interactive element (link, button) if the user can click through.