Tailwind CSS provides the group and group-hover utilities to conditionally apply styles to child elements based on the state of a parent. This is especially useful when you want to change the appearance of nested elements when a container is hovered, focused, or active.
In plain CSS, styling a child element based on the hover state of its parent typically requires a selector like this:
.card:hover .card-icon {
color: red;
}
With utility-first CSS, you want to avoid custom selectors and keep everything inline in your markup.
The group utility
Tailwind solves this with the group class. You mark the parent element as a group, and then reference that state from any descendant using group-hover:*.
<div class="group p-4 border rounded">
<span class="text-gray-400 group-hover:text-red-500">
Hover me
</span>
</div>
When the parent div is hovered, the span receives the text-red-500 class.
The group class itself does not add any styles. It only acts as a named hook that allows child elements to react to the parent’s state. Tailwind expands group-hover:text-red-500 into a CSS selector that targets the child when the parent is hovered.
This keeps your behavior explicit in the markup without writing custom CSS.
Beyond hover
The same pattern works for other state variants:
<div class="group focus-within:border-blue-500">
<input class="border p-2" />
<p class="text-sm text-gray-400 group-focus-within:text-blue-500">
Input is focused
</p>
</div>
Commonly used variants include:
group-hovergroup-focusgroup-focus-withingroup-active
Named groups
When you have nested groups, you can give them explicit names to avoid conflicts:
<div class="group/card">
<h3 class="group-hover/card:underline">
Card title
</h3>
</div>
This makes it clear which parent controls which child styles.
Conclusion
Tailwind’s group utilities let child elements respond to parent state changes without custom CSS. By marking a parent as a group and using group-hover (or related variants) on descendants, you can build rich interactive components while staying within Tailwind’s utility-first approach.
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.