#1 Data Analytics Program in India
₹2,499₹1,499Enroll Now
3 min read
Question 7 of 38easy

How to handle Hover and Focus states?

State variants in Tailwind CSS.

What You'll Learn

  • State prefixes
  • Combining states
  • Common patterns

State Prefixes

index.htmlHTML
<button class="bg-blue-500 hover:bg-blue-600 focus:ring-2">
  Hover and focus styles
</button>

Available States

PrefixApplies when
hover:Mouse over
focus:Element focused
active:Being clicked
disabled:Disabled state
focus-visible:Keyboard focus

Group Hover

index.htmlHTML
<div class="group">
  <span class="group-hover:text-blue-500">
    Changes when parent hovered
  </span>
</div>

Peer States

index.htmlHTML
<input class="peer" type="checkbox" />
<label class="peer-checked:text-green-500">
  Changes when checkbox checked
</label>