Avatar

A Tailwind CSS avatar component for displaying user profile images.

User
<img
  class="avatar"
  src="https://images.unsplash.com/photo-1494790108377-be9c29b29330?w=150&h=150&fit=crop&crop=face"
  alt="User"
/>

With fallback

When no image is available, display initials or an icon as a fallback.

JD
<span class="avatar-fallback">JD</span>
<span class="avatar-fallback"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="size-4"><path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></svg></span>

Sizes

Avatars come in multiple sizes.

User User User
<img
  class="avatar avatar-sm"
  src="https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=150&h=150&fit=crop&crop=face"
  alt="User"
/>
<img
  class="avatar"
  src="https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=150&h=150&fit=crop&crop=face"
  alt="User"
/>
<img
  class="avatar avatar-lg"
  src="https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=150&h=150&fit=crop&crop=face"
  alt="User"
/>

Fallbacks also scale with the size.

JD JD JD
<span class="avatar-fallback avatar-sm">JD</span>
<span class="avatar-fallback">JD</span>
<span class="avatar-fallback avatar-lg">JD</span>

Avatar group

Display multiple avatars in a stacked group.

User 1 User 2 User 3 User 4
<div class="avatar-group">
  <img
    class="avatar"
    src="https://images.unsplash.com/photo-1534528741775-53994a69daeb?w=150&h=150&fit=crop&crop=face"
    alt="User 1"
  />
  <img
    class="avatar"
    src="https://images.unsplash.com/photo-1539571696357-5a69c17a67c6?w=150&h=150&fit=crop&crop=face"
    alt="User 2"
  />
  <img
    class="avatar"
    src="https://images.unsplash.com/photo-1517841905240-472988babdf9?w=150&h=150&fit=crop&crop=face"
    alt="User 3"
  />
  <img
    class="avatar"
    src="https://images.unsplash.com/photo-1524504388940-b1c1722653e1?w=150&h=150&fit=crop&crop=face"
    alt="User 4"
  />
</div>

Avatar groups work with different sizes.

User 5 User 6 User 7 +5
<div class="avatar-group">
  <img
    class="avatar avatar-lg"
    src="https://images.unsplash.com/photo-1500648767791-00dcc994a43e?w=150&h=150&fit=crop&crop=face"
    alt="User 5"
  />
  <img
    class="avatar avatar-lg"
    src="https://images.unsplash.com/photo-1506794778202-cad84cf45f1d?w=150&h=150&fit=crop&crop=face"
    alt="User 6"
  />
  <img
    class="avatar avatar-lg"
    src="https://images.unsplash.com/photo-1438761681033-6461ffad8d80?w=150&h=150&fit=crop&crop=face"
    alt="User 7"
  />
  <span class="avatar-fallback avatar-lg">+5</span>
</div>

Customization

Combine avatar classes with Tailwind utilities for custom styling.

User User User
<img
  class="avatar rounded-md"
  src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?w=150&h=150&fit=crop&crop=face"
  alt="User"
/>
<img
  class="avatar size-16 rounded-lg"
  src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?w=150&h=150&fit=crop&crop=face"
  alt="User"
/>
<img
  class="avatar ring-2 ring-primary ring-offset-2 ring-offset-background"
  src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?w=150&h=150&fit=crop&crop=face"
  alt="User"
/>

How it works

The avatar component is a CSS-only component that styles images and fallback content. It includes size variants and an avatar group for displaying multiple avatars in a stacked layout.

Structure

An avatar can be either an image or a fallback element:

<!-- Image avatar -->
<img class="avatar" src="..." alt="User" />
 
<!-- Fallback avatar -->
<span class="avatar-fallback">JD</span>

For groups of avatars, wrap them in an .avatar-group container:

<div class="avatar-group">
  <img class="avatar" src="..." alt="User 1" />
  <img class="avatar" src="..." alt="User 2" />
  <span class="avatar-fallback">+3</span>
</div>

Class reference

All available classes for the avatar component.

ClassDescription
avatarAdd to <img> element to apply base avatar styles
avatar-fallbackAdd to <span> element to display initials or an icon when no image is available
avatar-smAdd to .avatar or .avatar-fallback for small size
avatar-baseAdd to .avatar or .avatar-fallback for base size (default)
avatar-lgAdd to .avatar or .avatar-fallback for large size
avatar-groupAdd to container element to stack avatars with overlapping edges
<img class="avatar avatar-lg" src="..." alt="User" />
<span class="avatar-fallback avatar-sm">AB</span>
<div class="avatar-group">...</div>