Unified UI

Avatar

A user identity component for displaying profile images, initials, or icon fallbacks with status indicators and group stacking.

Basic

A user identity component for displaying profile images, initials, or icon fallbacks. Supports status indicators, 5 sizes, 2 shapes, and group stacking.

ACBSCDDEEF
ACBSCDDE

Installation

Install the component via the CLI in one command.

npx @work-rjkashyap/unified-ui add avatar
pnpm dlx @work-rjkashyap/unified-ui add avatar
npx @work-rjkashyap/unified-ui add avatar
bunx @work-rjkashyap/unified-ui add avatar

If you haven't initialized your project yet, run npx @work-rjkashyap/unified-ui init first. See the CLI docs for details.

Or install the full package

Use this approach if you prefer to install the entire design system as a dependency instead of copying individual components.

npm install @work-rjkashyap/unified-ui
pnpm add @work-rjkashyap/unified-ui
yarn add @work-rjkashyap/unified-ui
bun add @work-rjkashyap/unified-ui

Anatomy

import {
	Avatar,
	AvatarGroup,
} from "@work-rjkashyap/unified-ui";

Basic Usage

The Avatar component displays a user image. When no src is provided (or the image fails to load), it falls back to initials derived from the name prop, or a default user icon.

// With image
<Avatar src="/photo.jpg" alt="Jane Doe" />

// With initials fallback
<Avatar name="Jane Doe" />

// Default icon fallback (no name or src)
<Avatar />

Sizes

Five sizes are available ranging from extra small (24px) to extra large (64px).

XSMLX
SizeDimensionsUse Case
xs24×24pxInline mentions, compact lists
sm32×32pxComment threads, table rows
md40×40pxDefault, navigation bars
lg48×48pxProfile cards, headers
xl64×64pxProfile pages, hero sections

Shapes

Two shapes are supported: circle (default) and square.

CS

Initials Fallback

When no src is provided (or the image fails to load), the component automatically generates initials from the name prop. It takes the first letter of the first and last words.

JDABS

Status Indicator

Add a status prop to display a small colored dot indicating the user's availability.

OBAO
StatusColorMeaning
onlineGreen (--success)User is active
busyRed (--danger)User is unavailable
awayYellow (--warning)User is idle
offlineGray (--muted)User is offline

Avatar Group

Use AvatarGroup to stack multiple avatars with a configurable overlap. When the number of avatars exceeds the max prop, a "+N" overflow indicator is shown.

ACBSCD+2

Group with Images

ABCD+2

Image Error Handling

When a src is provided but the image fails to load, the Avatar gracefully falls back to initials (if name is set) or the default icon.

JD

With Alt Text

Always provide descriptive alt text for images via the alt prop, or use the name prop which doubles as accessible text.

JDJD

Props

Avatar

PropTypeDefaultDescription
srcstringURL of the avatar image.
altstringAlt text for the image. Falls back to name if not provided.
namestringUser name used to generate initials fallback.
size"xs" | "sm" | "md" | "lg" | "xl""md"Size of the avatar.
shape"circle" | "square""circle"Shape of the avatar.
status"online" | "offline" | "busy" | "away"Status indicator dot.
classNamestringAdditional CSS classes.

AvatarGroup

PropTypeDefaultDescription
maxnumberMaximum number of avatars to display before showing "+N".
size"xs" | "sm" | "md" | "lg" | "xl""md"Size applied to all child avatars.
classNamestringAdditional CSS classes.

Accessibility

  • Images include an alt attribute (falls back to name if alt is not provided).
  • Initials fallback uses role="img" with an aria-label derived from name.
  • Status indicators have an aria-label describing the status (e.g., "online").
  • The status dot itself is decorative — the accessible label is on the parent element.
  • The "+N" overflow indicator in AvatarGroup is announced to screen readers.

Design Tokens

TokenUsage
--mutedInitials/icon fallback background
--successOnline status indicator
--dangerBusy status indicator
--warningAway status indicator
--radius-fullCircle shape
--radius-mdSquare shape border radius

On this page