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, and an optional name/email label group.

Random Person
random@example.com

Installation

Install the component using the Tailgrids CLI.

npx @tailgrids/cli add avatar

Anatomy

Import the component and pass the required props.

import { Avatar } from "@/registry/core/avatar";

export const AvatarExample = () => (
  <Avatar
    src="path/to/image.jpg"
    alt="Profile picture of Random Person"
    fallback="JD"
    size="md"
    status="online"
    label={{
      title: "Johurul Haque",
      subtitle: "johurul@pimjo.com"
    }}
  />
);

Examples

Sizes

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

Johurul Haque
Johurul Haque
Johurul Haque
Johurul Haque
Johurul Haque
Johurul Haque

Status

Show predefined status indicator with none, online, offline, and busy.

Johurul Haque
Johurul Haque
Johurul Haque
Johurul Haque

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

Label

The label prop accepts an object with name and email to display descriptive text next to the avatar.

Random Person
random@example.com

Avatar Group

Multiple avatars can be displayed in a group using the AvatarGroup component.

Johurul Haque
James Lue
David Lorin

Note: The AvatarGroup component implements an overlapping effect using negative margin (-space-x-2) and adjusts the z-index of each avatar via inline styles to ensure the correct stacking order.

API Reference

Avatar

PropTypeDefaultDescription
size'xs', 'sm', 'md', 'lg', 'xl', 'xxl''md'Sets the size of the avatar
srcstring-Image URL. If not provided, the fallback is shown
altstring-Image alt text for accessibility
fallbackstring-Initials or short text shown when src is not provided Required.
status'none', 'online', 'offline', 'busy''none'Displays a status indicator at the bottom-right corner
label{ title: string, subtitle: string }-Optional object containing title and subtitle displayed next to the avatar
classNamestring-Additional CSS classes to apply to the avatar

AvatarGroup

PropTypeDefaultDescription
size'xs', 'sm', 'md''md'Sets the size of avatars in the group
dataArray<{ src: string, alt: string }>-Array of avatar data objects to display
classNamestring-Additional CSS classes to apply to the group container

Accessibility

  • Alt Text: The alt prop is used for the image, allowing screen readers to announce the avatar content.
  • Fallback: When no image is present, the fallback initials are visually clear and provide context.
  • Semantic HTML: The component uses a <figure> and <img> (or <span> for fallback) for semantic correctness.