Group Hover and Focus
You'll learn how to style child elements based on their parent's hover or focus state using Tailwind's group utilities.
Sometimes you want multiple elements to change appearance when you hover over a parent container, not just the element you're directly hovering. Tailwind's group class solves this elegantly.
The Core Idea
Add the group class to a parent element, then use group-hover: or group-focus: prefixes on child elements. When the parent is hovered or focused, those child styles activate.
Think of it like a team uniform rule: when the coach (parent) raises their hand, all players (children) raise theirs too—even though you only signaled the coach.
Basic Pattern
<div class="group border p-4">
<h3 class="text-gray-700 group-hover:text-blue-600">
Card Title
</h3>
<p class="opacity-50 group-hover:opacity-100">
This description fades in when you hover the card
</p>
</div>
When you hover anywhere over the div, both the heading color and paragraph opacity change—creating a coordinated effect.
Common Use Cases
Interactive cards: Hover over a card to reveal buttons, change image brightness, or animate icons inside it.
Navigation menus: Focus on a parent link to highlight child dropdown items.
Complex components: Coordinate multiple visual changes across icons, text, and backgrounds simultaneously.
Combining with Other States
You can stack group utilities with responsive prefixes:
<div class="group">
<button class="md:group-hover:scale-110">
Scales on hover at medium screens and up
</button>
</div>
Key Takeaway: The group class on a parent plus group-hover: or group-focus: prefixes on children let you create sophisticated, coordinated hover effects without writing custom CSS or JavaScript.