Applied when the user's pointer (mouse) is over an element
User hovers mouse over the element
hover:{property}-{value}
Hover over elements to see effects
<!-- Basic hover example -->
<button class="bg-blue-600 text-white px-4 py-2 rounded-lg
hover:bg-blue-700 hover:scale-105
hover:shadow-lg transition duration-300">
Hover Me
</button>
<!-- Group hover example -->
<div class="group cursor-pointer">
<div class="px-4 py-2 bg-gray-200 rounded-lg
group-hover:bg-green-500 group-hover:text-white
transition duration-300">
Group Hover
</div>
<div class="opacity-0 group-hover:opacity-100 ...">
Tooltip appears
</div>
</div>
Applied when element receives focus (keyboard navigation or click)
Element receives focus via Tab key or click
focus:{property}-{value}
Essential for keyboard navigation users
<!-- Input with focus styles -->
<input type="text"
class="border border-gray-300 rounded-lg
focus:border-blue-500
focus:ring-2 focus:ring-blue-200
focus:outline-none transition"
placeholder="Enter text...">
<!-- Button with focus ring -->
<button class="bg-purple-600 text-white px-4 py-2 rounded-lg
focus:outline-none
focus:ring-2 focus:ring-purple-300
focus:ring-offset-2">
Click Me
</button>
Never remove outline without providing alternative focus styles.
Use focus:outline-none
together with
focus:ring or other visible styles.
Creates focus rings and attention indicators around elements
ring-1
ring-2
ring-4
Creates space between element and ring
ring-offset-2
ring-offset-4
Click and hold to see active state
<!-- Basic ring -->
<button class="focus:outline-none focus:ring-2 focus:ring-blue-500">
Basic Ring
</button>
<!-- Ring with offset -->
<button class="focus:outline-none
focus:ring-2 focus:ring-green-500
focus:ring-offset-2">
With Offset
</button>
<!-- Custom ring color -->
<button class="focus:outline-none
focus:ring-2 focus:ring-red-500
focus:ring-offset-2 focus:ring-offset-white">
Custom Color
</button>
Applied while element is being activated (mouse down or touch)
Click and hold the green box
Watch it rotate and scale
Try: Hover, then click, then focus with Tab
Mouse button down or touch press on element
active:{property}-{value}
On touch devices, active state shows while touching
<!-- Button with active state -->
<button class="bg-blue-600 text-white px-4 py-2 rounded-lg
active:bg-blue-800 active:scale-95
transition duration-150">
Click Me
</button>
<!-- Combined states example -->
<button class="bg-indigo-600 text-white px-4 py-2 rounded-lg
hover:bg-indigo-700
active:bg-indigo-800 active:scale-98
focus:outline-none focus:ring-2 focus:ring-indigo-300
transition duration-200">
Interactive Button
</button>
Understanding when each state triggers and their typical use cases
Mouse Hover
hover:
Mouse Down
active:
Keyboard Focus
focus:
Hover State
Mouse pointer over element
Active State
Mouse down or touch press
Focus State
Tab key navigation or click
| State | Trigger | Duration | Common Uses | Example Classes |
|---|---|---|---|---|
| Hover | Mouse pointer over element | 200-300ms transitions | Buttons, cards, navigation | hover:bg-blue-700 |
| Focus | Keyboard tab or click | Until loses focus | Forms, buttons, links | focus:ring-2 focus:ring-blue-500 |
| Active | Mouse down / touch press | 100-200ms | Buttons, toggles | active:scale-95 |
This button demonstrates all interactive states working together.
<button class="px-6 py-4 bg-gradient-to-r from-blue-600 to-cyan-600
text-white font-bold rounded-xl
hover:from-blue-700 hover:to-cyan-700
hover:shadow-lg hover:-translate-y-0.5
active:from-blue-800 active:to-cyan-800
active:translate-y-0 active:shadow-inner
focus:outline-none focus:ring-2 focus:ring-cyan-400
focus:ring-offset-2 focus:ring-offset-gray-900
transition duration-300 ease-in-out">
Launch Application
</button>