Lexington has been awarded a grant from Astro, to celebrate. Get a 30% discount. Apply code LEXINGTON30 ( uppercase ) at checkout.
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.
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.
Team Members Display:
User Interactions:
Project Contributors:
Event Participants:
Customer Testimonials:
Followers/Following Lists:
Notifications:
Collaborative Documents:
Online Courses:
Game Lobbies:
These use cases can enhance user experience by providing interactive and visually appealing ways to display groups of people.
Here’s an example of an avatar stack widget using Tailwind CSS:
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 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="#_" />
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>
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
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!