Full answer
On a touch screen there is no pointer to hover with. Many phones fake it: after a tap, the element keeps the :hover style until the user taps somewhere else. A menu or button can look stuck in its hover state. Also, a menu that opens only on hover cannot be opened by touch.
Interaction media features let CSS ask what the device can do:
(hover: hover)is true when the main input can hover, such as a mouse.(hover: none)is true for a typical touch screen.(pointer: fine)means a precise pointer such as a mouse.(pointer: coarse)means a finger or a similar low-precision input.any-hoverandany-pointercheck all inputs, not only the main one. A laptop with a touch screen has both. Do not treat the device as one or the other. Use the primary input features for style, and let the other controls still work.
Rules of thumb:
- Wrap hover-only effects in
@media (hover: hover) { ... }, so they apply only where hover exists. - Never hide important content or actions behind hover. Everything must also work with focus and tap.
- For
pointer: coarse, make targets bigger: about 44 by 44 CSS pixels is a common guideline, with space between them. - Show focus styles with
:focus-visiblefor keyboard users in every case.
These checks give hints about input, not certainty, so keep the page usable without them.
In a desktop browser, the button turns blue on hover and keeps its small size. On a phone, the hover rule is not used, so there is no stuck blue state, and the button is at least 44px high.
The check here ran with a mouse only. The coarse pointer rule was not run on a touch device, so test on a phone or with device emulation.
<style>
.btn { padding: 4px 8px; min-height: 24px; background: #eee; border: 1px solid #999; }
@media (hover: hover) { .btn:hover { background: #cde; } }
@media (pointer: coarse) { .btn { min-height: 44px; padding: 12px 16px; } }
</style>
<button class="btn" id="b" type="button">Add</button>The check ran with a mouse only. The rule for a coarse pointer was not run on a touch device. Run in Chrome 156 (headless) as a page; the snippet is wrapped in a minimal HTML document with doctype, charset and viewport meta tag. Two full runs gave identical results, and the measured values in the answer come from them.
Key points
- Touch devices can leave :hover stuck after a tap.
- @media (hover: hover) limits hover styles to devices that can hover.
- pointer: coarse signals finger input; make targets large.
- any-hover and any-pointer check all inputs.
- Do not hide essential content behind hover.
Common mistakes
- Showing menus or essential actions only on :hover.
- Assuming a screen with touch has no mouse and removing hover styles for it.
- Making small touch targets with no space between them.
Follow-ups
- What is the difference between hover and any-hover?
- What size should touch targets be?
Tips
- Explain the sticky hover problem on touch screens in one sentence.
- Name hover and pointer, and the any- versions.