Avatar

React Avatar components are used to display user profile images, initials, or general fallback content. They are commonly used in user profiles, comment lists, team members, and account menus.

This Avatar component is built with React and styled using Tailwind CSS, giving developers control over size, layout, and presentation. It supports various sizes, user status indicators, an optional name/email label group, and overlapping avatar groups.

J

Installation

Install the component using the Tailgrids CLI.

npx @tailgrids/cli add avatar

Anatomy

Import the component parts and combine them.

import {
  Avatar,
  AvatarImage,
  AvatarFallback,
  AvatarBadge
} from "@/components/tailgrids/core/avatar";

export const AvatarExample = () => (
  <Avatar size="md">
    <AvatarImage
      src="path/to/image.jpg"
      alt="Profile picture of Random Person"
    />
    <AvatarFallback>JD</AvatarFallback>
    <AvatarBadge status="online" />
  </Avatar>
);

Examples

Sizes

The Avatar component supports six predefined sizes: xs, sm, md, lg, xl, and xxl.

JHJHJHJHJHJH

Status

Show predefined status indicator with online, offline, and busy on <AvatarBadge>. Omit the badge to render an avatar without a status indicator.

JHJHJHJH

Note: The status indicator uses a white ring to visually separate it from the avatar's background.

Animated Status

Set ping on <AvatarBadge> to animate the status indicator.

J

Label

Wrap an <Avatar> with a name and subtitle inside a <figure> to associate the visual with descriptive text.

J

John Doe

Software Engineer

Avatar Group

Multiple avatars can be displayed in a group using the <AvatarGroup> component. Avatars overlap using negative margin and stack via a shared background ring.

JHJLDL

Group with Count

Use <AvatarGroupCount> to display an overflow indicator for the group.

JHJLDL
5+

API Reference

Avatar

The root container for an avatar. Wraps an image, fallback, and optional badge.

PropTypeDefaultDescription
size'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl''md'Sets the size of the avatar
classNamestring-Additional CSS classes to apply to the root
childrenReact.ReactNode-AvatarImage, AvatarFallback, AvatarBadge
Data AttributeValuesDescription
data-slot'avatar'Identifies the avatar root element
data-size'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl'Reflects the current size prop

AvatarImage

Renders the avatar's image. Falls back to AvatarFallback while loading or on error.

PropTypeDescription
classNamestringAdditional CSS classes
srcstringImage URL (passed to the underlying img)
altstringImage alt text for accessibility
Data AttributeValuesDescription
data-slot'avatar-image'Identifies the avatar image

AvatarFallback

Rendered when the image is loading or has failed. Typically holds initials.

PropTypeDescription
classNamestringAdditional CSS classes
childrenReact.ReactNodeFallback content (e.g. initials)
Data AttributeValuesDescription
data-slot'avatar-fallback'Identifies the avatar fallback

AvatarBadge

Displays a status indicator at the bottom-right corner of the avatar.

PropTypeDefaultDescription
status'online' | 'offline' | 'busy''online'Status color for the badge
size'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl''md'Sets the badge size; usually matches the parent avatar's size
livebooleanfalseWhen true, sets aria-live="polite" so status changes are announced
pingbooleanfalseWhen true, renders a ping animation around the badge
classNamestring-Additional CSS classes
Data AttributeValuesDescription
data-slot'avatar-badge'Identifies the avatar badge
data-status'online' | 'offline' | 'busy'Reflects the current status prop

AvatarGroup

Wraps a collection of avatars with an overlapping layout.

PropTypeDefaultDescription
classNamestring-Additional CSS classes
childrenReact.ReactNode-<Avatar> and/or <AvatarGroupCount> elements
Data AttributeValuesDescription
data-slot'avatar-group'Identifies the avatar group container

AvatarGroupCount

Displays an overflow indicator (e.g. 5+) inside an <AvatarGroup>.

PropTypeDefaultDescription
size'xs' | 'sm' | 'md''md'Sets the size of the count indicator
classNamestring-Additional CSS classes
childrenReact.ReactNode-Overflow content (e.g. 5+)
aria-labelstringderivedWhen children is a string, the default label is "${children} more". Pass a string to override.
Data AttributeValuesDescription
data-slot'avatar-group-count'Identifies the group count indicator
data-size'xs' | 'sm' | 'md'Reflects the current size prop

Accessibility

  • Accessible name: Pass alt to <AvatarImage> to give the avatar a label. The label is announced separately from the status badge.
  • Image alt text: When the avatar stands alone, give <AvatarImage> a descriptive alt. When it sits next to a text label (e.g. inside a <figure>/<figcaption>), pass alt="" so it's treated as decorative.
  • Status indicator: The badge is announced as a separate role="img" with an aria-label of the current status (online / offline / busy). Color is reinforced with a shape glyph (a dash for offline, a minus for busy) so the indicator is not color-only. Pass live to make the badge announce status changes via aria-live="polite".
  • Fallback: Initials are visually clear. When the image fails, you can pass aria-label to <AvatarFallback> to give the initials a name.
  • Group semantics: <AvatarGroup> renders as role="group". Pass aria-label (e.g. "Team members") to describe the collection. <AvatarGroupCount> derives an aria-label of "${children} more" by default and accepts an explicit aria-label override.
  • Semantic HTML: When pairing an avatar with a name/subtitle, wrap them in a <figure> with the text in a <figcaption>.