Pittaya UI
Pittaya UI
Links

Search Components

Search for components by name, description, category or tags

Componentsstable

Avatar

An accessible avatar component with support for images, fallbacks, groups, and multiple sizes.

Basic Avatar@pittaya-uiPU
Avatar Group
User 1U1
User 2U2
User 3U3
+2

Installation

Install the component directly into your project using the Pittaya CLI.

npx pittaya@latest add avatar

When to use

Use the Avatar component to represent users or entities visually in your application. It's ideal for profile pictures, user lists, comment sections, and team member displays.

The component automatically handles image loading failures by displaying a fallback, ensuring a consistent user experience even when images fail to load.

Best practices

  • Always provide meaningful fallback text (usually initials) for accessibility and when images fail to load.
  • Use appropriate sizes for different contexts: small for compact lists, large for profile pages.
  • When using AvatarGroup, limit the number of visible avatars (3-5) to maintain clarity and show a count for additional members.
  • Include alt text for images to improve accessibility and SEO.
  • Consider adding status indicators (online/offline/busy) for real-time communication interfaces.

Accessibility

The Avatar component is built on top of Radix UI's Avatar primitive, ensuring robust accessibility features:

  • Automatically handles image loading states and fallback rendering.
  • Always provide descriptive alt attributes for images to assist screen reader users.
  • Fallback text should be meaningful and concise (typically 1-3 characters).
  • The component maintains proper semantic structure and supports keyboard navigation when interactive.

Variations

Sizes

The Avatar component supports four size variants: sm, md, lg, and xl. Choose the appropriate size based on your layout and use case.

AvatarGroup

Use AvatarGroup to display multiple avatars in an overlapping stack. It automatically handles overflow by showing a count badge for additional members beyond the max limit.

Custom Styles

Customize the appearance using className props on Avatar, AvatarImage, or AvatarFallback. You can modify borders, background colors, border radius, and more.

Examples

Combine variants and sizes to meet your needs.

Basic usage

A simple avatar with an image and fallback text. The fallback is only shown if the image fails to load.

@pittaya-uiPU

Avatar sizes

Avatars support four size variants: sm (32px), md (40px), lg (48px), and xl (64px).

@pittaya-uiPU@pittaya-uiPU@pittaya-uiPU@pittaya-uiPU

Fallback only

Avatars can display fallback content when no image is provided or when the image fails to load. You can customize the fallback styling.

InvalidJDABXY

Avatar group

Display multiple avatars in an overlapping group. Use the max prop to limit visible avatars and show a count for the rest.

User 1U1
User 2U2
User 3U3
+2

Avatar group sizes

AvatarGroup supports the same size variants as Avatar, applying the size to all children automatically.

Small

User 1U1
User 2U2
U3
+1

Medium

User 1U1
User 2U2
U3
+1

Large

User 1U1
User 2U2
U3
+1

Avatar with status indicator

Add status indicators (online, away, offline) by positioning a small badge using absolute positioning.

@pittaya-uiPU
@vercelVC
@reactRC

Properties

TSX interface that combines variants and default attributes.

PropTypeDefaultDescription
size
'sm' | 'md' | 'lg' | 'xl''md'Controls the size of the avatar. Small (32px), Medium (40px), Large (48px), Extra Large (64px).
className
stringAdditional CSS classes to apply to the avatar root element.
src
stringThe image source URL to display in the avatar.
alt
stringAlternative text for the image, important for accessibility.
onLoadingStatusChange
(status: 'loading' | 'loaded' | 'error') => voidCallback fired when the image loading status changes.
max
number3Maximum number of avatars to display before showing a count badge.
count
numberThe number to display in the count badge.