agyanadda@gmail.com

Tailwind Hover, Focus and States

Tailwind Basics 1 min read Updated Dec 1, 2026 Topic 5 of 27

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>

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which class must the parent have for group-hover: to work?

Exercise 2 True / False

peer-invalid: styles an element when a sibling input with class peer is invalid.

Exercise 3 Fill in the Blank

___:bg-gray-100 colours every other row starting from the first.

Frequently Asked Questions

focus-visible shows the outline only for keyboard users, so mouse users don't see a ring on every click while keyboard users stay supported.