Hover and Pointer Media Features
You'll learn how to detect whether a user has a mouse or is using touch, so you can design interfaces that match their input method.
What This Solves
Not all devices interact the same way. Desktop users have precise mouse cursors and can hover over elements. Mobile users tap with fingers—no hovering possible, and less precision. These media features let you detect input capabilities and adapt your design accordingly.
The Four Media Features
hover
Detects if the primary input device can hover.
/* Mouse users see hover effects */
@media (hover: hover) {
button:hover {
background: blue;
}
}
/* Touch users don't - avoid hover-only UI */
@media (hover: none) {
button {
/* Show all options by default */
}
}
any-hover
Detects if any available input can hover (like a touchscreen laptop with a mouse plugged in).
pointer
Detects the primary input precision:
fine= mouse/trackpad (precise)coarse= touch (finger-sized targets needed)none= no pointing device
/* Touch devices: bigger tap targets */
@media (pointer: coarse) {
button {
min-height: 44px; /* Apple's recommended minimum */
}
}
any-pointer
Checks if any input has fine/coarse precision.
Real-World Example
/* Touch-first: always show menu */
.nav-submenu {
display: block;
}
/* Mouse users: hide until hover */
@media (hover: hover) and (pointer: fine) {
.nav-submenu {
display: none;
}
.nav-item:hover .nav-submenu {
display: block;
}
}
Key Takeaway: Use hover and pointer media features to detect input capabilities—design touch-friendly interfaces for (hover: none) and (pointer: coarse), and enhance with hover effects only when (hover: hover) is true.