Avatar Shared Partial

1. Copy shared partial files

Download all 2 shared partial files as a ZIP file.

Download all files (ZIP)

After downloading, unzip and copy the avatar/ folder to your app/views/shared/components/ directory.

Copy these files to your app/views/shared/components/avatar/ directory:

2. Usage example

<!-- Basic avatar -->
<%= render "shared/components/avatar/avatar",
  src: "https://images.unsplash.com/photo-1494790108377-be9c29b29330?w=160&h=160&fit=crop&crop=face&auto=format&q=80",
  alt: "Olivia Martin",
  size: "lg" %>

<!-- Avatar with an accessible, pulsing online status -->
<%= render "shared/components/avatar/avatar",
  src: "https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=160&h=160&fit=crop&crop=face&auto=format&q=80",
  alt: "Noah Williams",
  size: "lg",
  status: "online",
  status_label: "Online" %>

<!-- Initials fallback -->
<%= render "shared/components/avatar/avatar", alt: "Avery Stone", size: "md" %>

<!-- Avatar group -->
<%= render "shared/components/avatar/avatar_group",
  avatars: [
    { src: "https://images.unsplash.com/photo-1494790108377-be9c29b29330?w=160&h=160&fit=crop&crop=face&auto=format&q=80", alt: "Olivia Martin" },
    { src: "https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=160&h=160&fit=crop&crop=face&auto=format&q=80", alt: "Noah Williams" },
    { src: "https://images.unsplash.com/photo-1438761681033-6461ffad8d80?w=160&h=160&fit=crop&crop=face&auto=format&q=80", alt: "Emma Davis" }
  ],
  size: "md",
  remaining_count: 3,
  label: "Project members" %>

<!-- Animated avatar group -->
<%= render "shared/components/avatar/avatar_group",
  avatars: [
    { src: "https://images.unsplash.com/photo-1494790108377-be9c29b29330?w=160&h=160&fit=crop&crop=face&auto=format&q=80", alt: "Olivia Martin" },
    { src: "https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=160&h=160&fit=crop&crop=face&auto=format&q=80", alt: "Noah Williams" },
    { src: "https://images.unsplash.com/photo-1438761681033-6461ffad8d80?w=160&h=160&fit=crop&crop=face&auto=format&q=80", alt: "Emma Davis" }
  ],
  size: "md",
  remaining_count: 3,
  label: "Project members",
  animated: true %>

Rendered usage example

Olivia Martin Noah Williams Online
Olivia Martin Noah Williams Emma Davis +3
Olivia Martin Noah Williams Emma Davis +3

Avatar ViewComponent

1. Ensure the gem is installed

gem "view_component", "~> 4.2"

2. Copy component files

Download all 4 component files as a ZIP file.

Download all files (ZIP)

After downloading, unzip and copy the avatar/ folder to your app/components/ directory.

Copy these files to your app/components/avatar/ directory:

3. Usage example

<!-- Basic avatar -->
<%= render Avatar::Component.new(
  src: "https://images.unsplash.com/photo-1494790108377-be9c29b29330?w=160&h=160&fit=crop&crop=face&auto=format&q=80",
  alt: "Olivia Martin",
  size: :lg
) %>

<!-- Avatar with an accessible, pulsing online status -->
<%= render Avatar::Component.new(
  src: "https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=160&h=160&fit=crop&crop=face&auto=format&q=80",
  alt: "Noah Williams",
  size: :lg,
  status: :online,
  status_label: "Online"
) %>

<!-- Initials fallback -->
<%= render Avatar::Component.new(alt: "Avery Stone", size: :md) %>

<!-- Avatar group -->
<%= render Avatar::GroupComponent.new(size: :md, remaining_count: 3, label: "Project members") do |group| %>
  <% group.with_avatar(src: "https://images.unsplash.com/photo-1494790108377-be9c29b29330?w=160&h=160&fit=crop&crop=face&auto=format&q=80", alt: "Olivia Martin") %>
  <% group.with_avatar(src: "https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=160&h=160&fit=crop&crop=face&auto=format&q=80", alt: "Noah Williams") %>
  <% group.with_avatar(src: "https://images.unsplash.com/photo-1438761681033-6461ffad8d80?w=160&h=160&fit=crop&crop=face&auto=format&q=80", alt: "Emma Davis") %>
<% end %>

<!-- Animated avatar group: compact at rest, normal overlap on hover -->
<%= render Avatar::GroupComponent.new(size: :md, remaining_count: 3, label: "Project members", animated: true) do |group| %>
  <% group.with_avatar(src: "https://images.unsplash.com/photo-1494790108377-be9c29b29330?w=160&h=160&fit=crop&crop=face&auto=format&q=80", alt: "Olivia Martin") %>
  <% group.with_avatar(src: "https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=160&h=160&fit=crop&crop=face&auto=format&q=80", alt: "Noah Williams") %>
  <% group.with_avatar(src: "https://images.unsplash.com/photo-1438761681033-6461ffad8d80?w=160&h=160&fit=crop&crop=face&auto=format&q=80", alt: "Emma Davis") %>
<% end %>

Rendered usage example

Olivia Martin Noah Williams Online
Olivia Martin Noah Williams Emma Davis +3
Olivia Martin Noah Williams Emma Davis +3

Avatar Rails Components

Avatars represent people or accounts with profile images, presence indicators, and compact groups.

Examples

Basic Avatar

A simple circular avatar with a profile image.

Portrait of Olivia Martin
<span class="relative inline-flex size-12 shrink-0 overflow-hidden rounded-full bg-neutral-100 after:pointer-events-none after:absolute after:inset-0 after:z-10 after:rounded-full after:content-[''] after:shadow-[inset_0_0_0_1px_rgb(0_0_0_/_10%)] dark:bg-neutral-800 dark:after:shadow-[inset_0_0_0_1px_rgb(255_255_255_/_10%)]">
  <img
    class="size-full object-cover"
    src="https://images.unsplash.com/photo-1494790108377-be9c29b29330?w=160&h=160&fit=crop&crop=face&auto=format&q=80"
    alt="Portrait of Olivia Martin">
</span>

Avatar with Status

An avatar with an online status indicator.

Portrait of Noah Williams Online
<span class="relative inline-flex size-12 shrink-0 rounded-full after:pointer-events-none after:absolute after:inset-0 after:z-10 after:rounded-full after:content-[''] after:shadow-[inset_0_0_0_1px_rgb(0_0_0_/_10%)] dark:after:shadow-[inset_0_0_0_1px_rgb(255_255_255_/_10%)]">
  <img
    class="size-full rounded-full object-cover"
    src="https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=160&h=160&fit=crop&crop=face&auto=format&q=80"
    alt="Portrait of Noah Williams">
  <span class="absolute right-0 bottom-0 z-20 flex size-3">
    <span class="absolute inline-flex size-full animate-ping rounded-full bg-green-400 opacity-75 dark:bg-green-300"></span>
    <span class="relative inline-flex size-3 rounded-full bg-green-500 ring-2 ring-white dark:bg-green-400 dark:ring-neutral-950"></span>
    <span class="sr-only">Online</span>
  </span>
</span>

Avatar Group

A compact group of overlapping avatars with a count for the remaining people.

Olivia Martin Noah Williams Emma Davis +3
<!-- Recommended group overlap: xs -space-x-2, sm -space-x-3, md -space-x-4, lg -space-x-5, xl -space-x-6 -->
<div class="flex w-fit -space-x-4 [&>*]:isolate" role="group" aria-label="Project members">
  <span class="relative inline-flex size-10 shrink-0 rounded-full after:pointer-events-none after:absolute after:inset-0 after:z-10 after:rounded-full after:content-[''] after:shadow-[inset_0_0_0_1px_rgb(0_0_0_/_10%)] dark:after:shadow-[inset_0_0_0_1px_rgb(255_255_255_/_10%)]">
    <img
      class="size-full rounded-full object-cover"
      src="https://images.unsplash.com/photo-1494790108377-be9c29b29330?w=160&h=160&fit=crop&crop=face&auto=format&q=80"
      alt="Olivia Martin">
  </span>
  <span class="relative inline-flex size-10 shrink-0 rounded-full after:pointer-events-none after:absolute after:inset-0 after:z-10 after:rounded-full after:content-[''] after:shadow-[inset_0_0_0_1px_rgb(0_0_0_/_10%)] dark:after:shadow-[inset_0_0_0_1px_rgb(255_255_255_/_10%)]">
    <img
      class="size-full rounded-full object-cover"
      src="https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=160&h=160&fit=crop&crop=face&auto=format&q=80"
      alt="Noah Williams">
  </span>
  <span class="relative inline-flex size-10 shrink-0 rounded-full after:pointer-events-none after:absolute after:inset-0 after:z-10 after:rounded-full after:content-[''] after:shadow-[inset_0_0_0_1px_rgb(0_0_0_/_10%)] dark:after:shadow-[inset_0_0_0_1px_rgb(255_255_255_/_10%)]">
    <img
      class="size-full rounded-full object-cover"
      src="https://images.unsplash.com/photo-1438761681033-6461ffad8d80?w=160&h=160&fit=crop&crop=face&auto=format&q=80"
      alt="Emma Davis">
  </span>
  <span class="relative inline-flex size-10 shrink-0 items-center justify-center rounded-full bg-neutral-100 text-xs font-medium text-neutral-600 after:pointer-events-none after:absolute after:inset-0 after:z-10 after:rounded-full after:content-[''] after:shadow-[inset_0_0_0_1px_rgb(0_0_0_/_10%)] dark:bg-neutral-800 dark:text-neutral-300 dark:after:shadow-[inset_0_0_0_1px_rgb(255_255_255_/_10%)]" aria-label="3 more project members">
    +3
  </span>
</div>

Avatar Sizes

Avatar sizes from extra small to extra large, with comments documenting dimensions and recommended group overlap: -space-x-2 for xs, -space-x-3 for sm, -space-x-4 for md, -space-x-5 for lg, and -space-x-6 for xl.

Portrait of Olivia Martin at extra-small size Portrait of Olivia Martin at small size Portrait of Olivia Martin at medium size Portrait of Olivia Martin at large size Portrait of Olivia Martin at extra-large size
<div class="flex flex-wrap items-end justify-center gap-6">
  <!-- Extra small (xs): 24px; recommended group overlap: -space-x-2 -->
  <span class="relative inline-flex size-6 shrink-0 overflow-hidden rounded-full bg-neutral-100 after:pointer-events-none after:absolute after:inset-0 after:z-10 after:rounded-full after:content-[''] after:shadow-[inset_0_0_0_1px_rgb(0_0_0_/_10%)] dark:bg-neutral-800 dark:after:shadow-[inset_0_0_0_1px_rgb(255_255_255_/_10%)]">
    <img
      class="size-full object-cover"
      src="https://images.unsplash.com/photo-1494790108377-be9c29b29330?w=160&h=160&fit=crop&crop=face&auto=format&q=80"
      alt="Portrait of Olivia Martin at extra-small size">
  </span>

  <!-- Small (sm): 32px; recommended group overlap: -space-x-3 -->
  <span class="relative inline-flex size-8 shrink-0 overflow-hidden rounded-full bg-neutral-100 after:pointer-events-none after:absolute after:inset-0 after:z-10 after:rounded-full after:content-[''] after:shadow-[inset_0_0_0_1px_rgb(0_0_0_/_10%)] dark:bg-neutral-800 dark:after:shadow-[inset_0_0_0_1px_rgb(255_255_255_/_10%)]">
    <img
      class="size-full object-cover"
      src="https://images.unsplash.com/photo-1494790108377-be9c29b29330?w=160&h=160&fit=crop&crop=face&auto=format&q=80"
      alt="Portrait of Olivia Martin at small size">
  </span>

  <!-- Medium (md): 40px; recommended group overlap: -space-x-4 -->
  <span class="relative inline-flex size-10 shrink-0 overflow-hidden rounded-full bg-neutral-100 after:pointer-events-none after:absolute after:inset-0 after:z-10 after:rounded-full after:content-[''] after:shadow-[inset_0_0_0_1px_rgb(0_0_0_/_10%)] dark:bg-neutral-800 dark:after:shadow-[inset_0_0_0_1px_rgb(255_255_255_/_10%)]">
    <img
      class="size-full object-cover"
      src="https://images.unsplash.com/photo-1494790108377-be9c29b29330?w=160&h=160&fit=crop&crop=face&auto=format&q=80"
      alt="Portrait of Olivia Martin at medium size">
  </span>

  <!-- Large (lg): 48px; recommended group overlap: -space-x-5 -->
  <span class="relative inline-flex size-12 shrink-0 overflow-hidden rounded-full bg-neutral-100 after:pointer-events-none after:absolute after:inset-0 after:z-10 after:rounded-full after:content-[''] after:shadow-[inset_0_0_0_1px_rgb(0_0_0_/_10%)] dark:bg-neutral-800 dark:after:shadow-[inset_0_0_0_1px_rgb(255_255_255_/_10%)]">
    <img
      class="size-full object-cover"
      src="https://images.unsplash.com/photo-1494790108377-be9c29b29330?w=160&h=160&fit=crop&crop=face&auto=format&q=80"
      alt="Portrait of Olivia Martin at large size">
  </span>

  <!-- Extra large (xl): 64px; recommended group overlap: -space-x-6 -->
  <span class="relative inline-flex size-16 shrink-0 overflow-hidden rounded-full bg-neutral-100 after:pointer-events-none after:absolute after:inset-0 after:z-10 after:rounded-full after:content-[''] after:shadow-[inset_0_0_0_1px_rgb(0_0_0_/_10%)] dark:bg-neutral-800 dark:after:shadow-[inset_0_0_0_1px_rgb(255_255_255_/_10%)]">
    <img
      class="size-full object-cover"
      src="https://images.unsplash.com/photo-1494790108377-be9c29b29330?w=160&h=160&fit=crop&crop=face&auto=format&q=80"
      alt="Portrait of Olivia Martin at extra-large size">
  </span>
</div>

Animated Avatar Group

A tightly stacked medium avatar group that smoothly expands to the recommended -space-x-4 overlap when hovering anywhere on the group.

Olivia Martin Noah Williams Emma Davis +3
<!-- Medium avatars normally use -space-x-4. This group rests at -space-x-6 and expands to the normal overlap on hover. -->
<div class="group flex w-fit -space-x-6 [&>*]:isolate" role="group" aria-label="Project members">
  <span class="relative inline-flex size-10 shrink-0 rounded-full transition-transform duration-200 ease-in-out after:pointer-events-none after:absolute after:inset-0 after:z-10 after:rounded-full after:content-[''] after:shadow-[inset_0_0_0_1px_rgb(0_0_0_/_10%)] motion-reduce:transform-none motion-reduce:transition-none dark:after:shadow-[inset_0_0_0_1px_rgb(255_255_255_/_10%)]">
    <img
      class="size-full rounded-full object-cover"
      src="https://images.unsplash.com/photo-1494790108377-be9c29b29330?w=160&h=160&fit=crop&crop=face&auto=format&q=80"
      alt="Olivia Martin">
  </span>
  <span class="relative inline-flex size-10 shrink-0 rounded-full transition-transform duration-200 ease-in-out group-hover:translate-x-2 after:pointer-events-none after:absolute after:inset-0 after:z-10 after:rounded-full after:content-[''] after:shadow-[inset_0_0_0_1px_rgb(0_0_0_/_10%)] motion-reduce:transform-none motion-reduce:transition-none dark:after:shadow-[inset_0_0_0_1px_rgb(255_255_255_/_10%)]">
    <img
      class="size-full rounded-full object-cover"
      src="https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=160&h=160&fit=crop&crop=face&auto=format&q=80"
      alt="Noah Williams">
  </span>
  <span class="relative inline-flex size-10 shrink-0 rounded-full transition-transform duration-200 ease-in-out group-hover:translate-x-4 after:pointer-events-none after:absolute after:inset-0 after:z-10 after:rounded-full after:content-[''] after:shadow-[inset_0_0_0_1px_rgb(0_0_0_/_10%)] motion-reduce:transform-none motion-reduce:transition-none dark:after:shadow-[inset_0_0_0_1px_rgb(255_255_255_/_10%)]">
    <img
      class="size-full rounded-full object-cover"
      src="https://images.unsplash.com/photo-1438761681033-6461ffad8d80?w=160&h=160&fit=crop&crop=face&auto=format&q=80"
      alt="Emma Davis">
  </span>
  <span class="relative inline-flex size-10 shrink-0 items-center justify-center rounded-full bg-neutral-100 text-xs font-medium text-neutral-600 transition-transform duration-200 ease-in-out group-hover:translate-x-6 after:pointer-events-none after:absolute after:inset-0 after:z-10 after:rounded-full after:content-[''] after:shadow-[inset_0_0_0_1px_rgb(0_0_0_/_10%)] motion-reduce:transform-none motion-reduce:transition-none dark:bg-neutral-800 dark:text-neutral-300 dark:after:shadow-[inset_0_0_0_1px_rgb(255_255_255_/_10%)]" aria-label="3 more project members">
    +3
  </span>
</div>

Table of contents

Powered by

Get notified when new components come out