NOCTA UI

Avatar

A versatile avatar component for displaying user profile images, initials, and status indicators with dark mode support

Installation

Install the Avatar component using the nocta-ui CLI:

Terminal
npx nocta-ui add avatar

Then import the component:

Import
import { Avatar } from '@/components/ui/avatar';

Basic Usage

Default Avatar

JD

Sizes

Six size options are available: xs, sm, md, lg, xl, and 2xl. The default size is md.

Variants

The Avatar component supports two shape variants: circle (default) and square.

JD
JD

Status Indicators

Add status indicators to show user presence: online, offline, away, or busy.

AB

Fallback Handling

The Avatar component gracefully handles image loading failures with multiple fallback options.

SC
AB

Avatar Groups

Stack multiple avatars to show groups or teams.

AB
+5

Customization

Custom Styling

The Avatar component accepts a className prop for custom styling:

JD

With Click Handlers

JS

API Reference

Avatar Props

PropTypeDefaultDescription
srcstring-The image source URL
altstring''Alt text for the image
fallbackstring-Text to generate initials from, or custom initials
size'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl''md'The size of the avatar
variant'circle' | 'square''circle'The shape variant
status'online' | 'offline' | 'away' | 'busy' | nullnullStatus indicator
classNamestring''Additional CSS classes to apply

The Avatar component also accepts all standard HTML div element props through the ...props spread operator.

Accessibility

The Avatar component is built with accessibility in mind:

  • Uses semantic HTML with proper alt attributes for images
  • Status indicators include aria-label for screen readers
  • Supports keyboard navigation when used with click handlers
  • Proper contrast ratios for text and status indicators
  • Fallback content for failed image loads

Size Reference

SizeDimensionsBest Use Case
xs24×24pxDense lists, small UI elements
sm32×32pxCompact interfaces, comments
md40×40pxDefault size, most common use
lg48×48pxUser cards, prominent displays
xl64×64pxProfile headers, large cards
2xl80×80pxProfile pages, hero sections