← Back to all tutorials

How to create an animated avatar stack widget with Tailwind CSS

Animated Avatar Stack Widget
Published and written on Aug 04 2024 by Michael Andreuzza

Today we are going to create an animated avatar stack widget with Tailwind CSS. This tutorial will show you how to create a widget that displays a stack of avatars that animates when you hover over them.

What are Avatar Stacks?

Avatar stacks are a visually appealing and interactive way to display a group of users or team members. This widget presents a stack of overlapping avatar images, which represent individual users. The primary feature of an avatar stack is its animation effect: when you hover over the stack, the avatars spread out or animate in a specified way, revealing more details about each user.

This type of widget is especially useful for compactly showcasing a list of people in a limited space while still allowing for interactivity and additional information to be revealed on hover. Avatar stacks can enhance the user experience by providing a clean, modern, and engaging way to represent groups of individuals in various contexts.

Benefits of Using Avatar Stacks

  • Space Efficiency: Avatar stacks allow you to display multiple avatars in a compact area without cluttering the interface.
  • Interactivity: The hover animation effect makes the widget engaging and interactive, encouraging user interaction.
  • Aesthetic Appeal: A well-designed avatar stack can enhance the visual appeal of your webpage, making it look more dynamic and modern.
  • Informative: By animating on hover, avatar stacks can reveal additional information, such as user names, roles, or other details, without taking up extra space initially.
  • Versatility: Avatar stacks can be used in a variety of contexts, from team pages to social media interactions, making them a versatile addition to any web project.

Use Cases

  1. Team Members Display:

    • Use the avatar stack widget on a company’s “About Us” or “Team” page to showcase team members. When users hover over the avatars, they could see the full list of team members in a visually appealing way.
  2. User Interactions:

    • On social media platforms or forums, the avatar stack can be used to show people who have liked or commented on a post. Hovering over the stack could reveal all the users who interacted with the post.
  3. Project Contributors:

    • In project management or collaboration tools, use the avatar stack to display contributors to a specific project or task. Hovering over the stack reveals all members working on it.
  4. Event Participants:

    • For events, webinars, or online meetings, the avatar stack can show the list of participants. Hovering over the stack provides a quick way to see who is attending.
  5. Customer Testimonials:

    • On e-commerce sites or service platforms, an avatar stack can display customer testimonials or reviews. Hovering over the stack shows detailed feedback from each customer.
  6. Followers/Following Lists:

    • On personal profiles or user dashboards, use the avatar stack to represent followers or people the user is following. Hovering reveals the entire list without cluttering the interface.
  7. Notifications:

    • In notification centers, the avatar stack can indicate users who have sent messages, friend requests, or other notifications. Hovering over the stack provides more information about each notification.
  8. Collaborative Documents:

    • In document editing tools, use the avatar stack to show who is currently viewing or editing a document. Hovering over the stack shows the full list of collaborators.
  9. Online Courses:

    • For online learning platforms, the avatar stack can display students enrolled in a course. Hovering over the stack provides additional details like progress or grades.
  10. Game Lobbies:

    • In online gaming platforms, the avatar stack can show players in a game lobby. Hovering over the stack reveals details like player names, ranks, or statuses.

These use cases can enhance user experience by providing interactive and visually appealing ways to display groups of people.

Code Example

Here’s an example of an avatar stack widget using Tailwind CSS:

The wrapper

The wrapper of the avatar stack widget is a flex container (flex) that stacks the avatars vertically (-space-x-2). This creates a visually appealing effect and ensures that the avatars are evenly spaced.

  • isolate: This class ensures that the widget is positioned independently of other elements on the page.
  • flex: This class creates a flex container, allowing the avatars to stack vertically.
  • -space-x-2: This class adds horizontal spacing between the avatars, creating a more visually appealing effect.
  <div class="isolate flex -space-x-2 ">
   <!--- Avatars go here -->
 </div>

The avatars

The avatars are represented by <img> tags, which are used to display the individual users. Each avatar is a relatively positioned (relative) image (inline-block), with a size of 24 pixels (size-24), rounded corners (rounded-full), and an object cover (object-cover). The ring-2 class adds a 2px border to the image, while the ring-white class sets the border color to white.

  • relative: This class ensures that the image is positioned relative to its parent container.
  • inline-block: This class sets the image to be displayed as an inline block element, allowing it to be positioned within the flex container.
  • transition-all: This class applies a transition effect to all CSS properties.
  • duration-300: This class sets the duration of the transition effect to 300 milliseconds.
  • ease-in-out: This class sets the easing function for the transition effect to ease in and out.
  • hover:-translate-y-3: This class applies a translation effect to the image when the user hovers over it.
  • hover:scale-110: This class applies a scaling effect to the image when the user hovers over it.

Note: Classes that style the avatars are not included in the code example for brevity.

<img class="relative inline-block transition-all duration-300 ease-in-out hover:-translate-y-3 hover:scale-110" src="#_" alt="#_" />

The full markup

Here’s the full markup for the avatar stack widget. This includes the wrapper, the avatars, and any additional styling or functionality you may want to add.

  <div class="isolate flex -space-x-2 ">
   <img class="relative inline-block size-24 rounded-full object-cover ring-2 ring-white transition-all duration-300 ease-in-out hover:-translate-y-3 hover:scale-110" src="#_" alt="#_" />
   <!--- More avatars here -->
 </div>

Conclusion

In this tutorial, we explored the concept of avatar stacks and how to create a visually appealing and interactive widget using Tailwind CSS. By combining the animation effect with the size and spacing of the avatars, you can create a dynamic and engaging way to display a list of users or team members. The code example provided in this tutorial serves as a starting point for further customization and styling, allowing you to create a unique and personalized avatar stack widget for your website or application.

Have a good day and hope you enoyed this tutorial!

/Michael Andreuzza

Did you like this tutorial? Please share it with your friends!

Reviews and opinions

Get lifetime access to every theme available today for $199 and own them forever. Plus, new themes, lifetime updates, use on unlimited projects and enjoy lifetime support.

No subscription required!

Lexington

Beautifully designed HTML, Astro.js and Tailwind themes! Save months of time and build your startup landing page in minutes.