Avatar

Avatars are the digital faces of your users! Now with enhanced styling, status indicators, badges, and seamless internet image support. Perfect for user profiles, chat interfaces, and social features.

Preview
Code

Sizes

XS Avatar
SM Avatar
Default Avatar
LG Avatar
XL Avatar

Status Indicators

Online User
Away User
Busy User
Offline User

With Badges

User with Badge
3
User with Icon Badge

Fallback Examples

JD
AB
?

Interactive Avatar

Clickable Avatar

Installation

First, make sure you have the required dependencies:

npx @rajdevxd/aura-ui add avatar
yarn @rajdevxd/aura-ui add avatar
pnpm dlx @rajdevxd/aura-ui add avatar
bunx --bun @rajdevxd/aura-ui add avatar

Usage

Here's how to use the enhanced Avatar component with all its features:

import { Avatar } from "@/components/ui/avatar"

const MyComponent = () => {
  return (
    <div className="flex items-center space-x-4">
      {/* Basic avatar with internet image */}
      <Avatar
        src="https://images.unsplash.com/photo-1494790108755-2616b612b786?w=128&h=128&fit=crop&crop=face"
        alt="Sarah Johnson"
      />

      {/* Avatar with status indicator */}
      <Avatar
        src="https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=128&h=128&fit=crop&crop=face"
        alt="Mike Chen"
        status="online"
      />

      {/* Avatar with badge */}
      <Avatar
        src="https://images.unsplash.com/photo-1438761681033-6461ffad8d80?w=128&h=128&fit=crop&crop=face"
        alt="Emma Davis"
        badge={<span className="text-xs bg-red-500 text-white rounded-full px-1">3</span>}
        badgePosition="top-right"
      />

      {/* Avatar with custom fallback */}
      <Avatar
        fallback="JD"
        alt="John Doe"
        size="lg"
      />

      {/* Interactive avatar */}
      <Avatar
        src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?w=256&h=256&fit=crop&crop=face"
        alt="Alex Smith"
        onClick={() => console.log('Avatar clicked!')}
        size="xl"
      />

      {/* Avatar with away status */}
      <Avatar
        src="https://images.unsplash.com/photo-1544005313-94ddf0286df2?w=128&h=128&fit=crop&crop=face"
        alt="Lisa Wong"
        status="away"
        size="default"
      />
    </div>
  )
}

Props

PropTypeRequiredDescription
srcstringNoThe source URL of the avatar image (supports internet URLs)
altstringNoAlternative text for accessibility
fallbackstringNoCustom fallback text (defaults to initials from alt)
size"xs" | "sm" | "default" | "lg" | "xl" | "2xl"NoAvatar size variant
status"online" | "offline" | "away" | "busy" | "none"NoStatus indicator ring color
badgeReact.ReactNodeNoBadge content to display
badgePosition"top-left" | "top-right" | "bottom-left" | "bottom-right"NoPosition of the badge
onClick() => voidNoClick handler for interactive avatars
classNamestringNoAdditional CSS classes for custom styling

Features

  • 🌐 Internet Image Support: Load images directly from any URL
  • 📱 Multiple Sizes: 6 size variants from XS to 2XL
  • 🔴 Status Indicators: Online, offline, away, busy status rings
  • 🏷️ Badge Support: Custom badges with 4 positioning options
  • ⚡ Smart Fallbacks: Automatic initials generation from alt text
  • 🎨 Beautiful Shadows: Enhanced visual depth with hover effects
  • 🖱️ Interactive: Click handlers for user interactions
  • ⏳ Loading States: Smooth loading animations
  • ♿ Accessibility: Full ARIA support and keyboard navigation
  • 🎭 Theme Aware: Adapts to your design system

Common Issues

  1. "Image not showing!" - Check the image path and ensure it's accessible
  2. "Fallback text is too small!" - Add custom font-size classes to AvatarFallback
  3. "Avatar is not round!" - The component applies rounded-full by default

Contributing

Help us make avatars even better! Test with various image formats and fallback scenarios.

Avatars - because every user deserves a face in the digital world! 👤