Tailwind applies styles in different states with variant prefixes.
Common variants
| Variant | When |
|---|---|
hover: |
mouse over |
focus: |
input or button focused |
focus-visible: |
focused by keyboard |
active: |
while clicking |
disabled: |
disabled element |
first: / last: |
first or last child |
odd: / even: |
alternate rows |
placeholder: |
the placeholder text |
Group
Style a child when the parent is hovered: add group to the parent and group-hover: to the child.
Peer
Style an element based on a sibling's state: add peer to an input and peer-invalid: to the message after it.
Stack variants
Combine them: md:hover:bg-blue-700, dark:hover:text-white.
Example
Example — Hover, focus, group and peer
HTML
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
<div class="p-6 space-y-6 max-w-md">
<button class="bg-indigo-600 hover:bg-indigo-700 active:scale-95 focus-visible:outline-4 focus-visible:outline-indigo-300 text-white px-5 py-2 rounded-lg transition">Hover and click me</button>
<input class="w-full border border-gray-300 rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-indigo-500 placeholder:text-gray-400" placeholder="Focus me">
<a href="#" class="group block border rounded-xl p-4 hover:bg-indigo-600 transition">
<h3 class="font-semibold group-hover:text-white">Group hover card</h3>
<p class="text-gray-500 group-hover:text-indigo-100">Hover anywhere on the card.</p>
</a>
<div>
<input type="email" class="peer w-full border rounded-lg px-3 py-2" placeholder="Type an invalid email">
<p class="invisible peer-invalid:visible text-rose-600 text-sm mt-1">Please enter a valid email.</p>
</div>
<ul class="border rounded-lg">
<li class="px-3 py-2 odd:bg-gray-100">Row 1</li>
<li class="px-3 py-2 odd:bg-gray-100">Row 2</li>
<li class="px-3 py-2 odd:bg-gray-100">Row 3</li>
</ul>
</div>