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.
Installation
Install the component via the CLI in one command.
npx @work-rjkashyap/unified-ui add avatarpnpm dlx @work-rjkashyap/unified-ui add avatarnpx @work-rjkashyap/unified-ui add avatarbunx @work-rjkashyap/unified-ui add avatarIf 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-uipnpm add @work-rjkashyap/unified-uiyarn add @work-rjkashyap/unified-uibun add @work-rjkashyap/unified-uiAnatomy
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).
| Size | Dimensions | Use Case |
|---|---|---|
xs | 24×24px | Inline mentions, compact lists |
sm | 32×32px | Comment threads, table rows |
md | 40×40px | Default, navigation bars |
lg | 48×48px | Profile cards, headers |
xl | 64×64px | Profile pages, hero sections |
Shapes
Two shapes are supported: circle (default) and square.
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.
Status Indicator
Add a status prop to display a small colored dot indicating the user's availability.
| Status | Color | Meaning |
|---|---|---|
online | Green (--success) | User is active |
busy | Red (--danger) | User is unavailable |
away | Yellow (--warning) | User is idle |
offline | Gray (--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.
Group with Images
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.
With Alt Text
Always provide descriptive alt text for images via the alt prop, or use the name prop which doubles as accessible text.
Props
Avatar
| Prop | Type | Default | Description |
|---|---|---|---|
src | string | — | URL of the avatar image. |
alt | string | — | Alt text for the image. Falls back to name if not provided. |
name | string | — | User 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. |
className | string | — | Additional CSS classes. |
AvatarGroup
| Prop | Type | Default | Description |
|---|---|---|---|
max | number | — | Maximum number of avatars to display before showing "+N". |
size | "xs" | "sm" | "md" | "lg" | "xl" | "md" | Size applied to all child avatars. |
className | string | — | Additional CSS classes. |
Accessibility
- Images include an
altattribute (falls back tonameifaltis not provided). - Initials fallback uses
role="img"with anaria-labelderived fromname. - Status indicators have an
aria-labeldescribing the status (e.g.,"online"). - The status dot itself is decorative — the accessible label is on the parent element.
- The "+N" overflow indicator in
AvatarGroupis announced to screen readers.
Design Tokens
| Token | Usage |
|---|---|
--muted | Initials/icon fallback background |
--success | Online status indicator |
--danger | Busy status indicator |
--warning | Away status indicator |
--radius-full | Circle shape |
--radius-md | Square shape border radius |
Badge
A compact label component for categorization, status indicators, metadata display, and interactive tags. Supports 8 semantic variants, dot indicators, avatars, icons, dismissible state, and optional Framer Motion animation.
Card
A versatile container for grouping related content and actions with slot-based composition.