The hover media feature detects whether the primary input can hover. Style buttons, nav, and tooltips differently for mouse users vs touch-only devices.
01
@media
Media query.
02
hover
Can hover.
03
none
Touch-first.
04
Primary
Main input.
05
vs :hover
Query vs state.
06
vs any-hover
All inputs.
Fundamentals
Introduction
Not every device supports hovering. A desktop mouse can rest over a button without clicking, triggering :hover styles. A phone touchscreen cannot — the finger touches and lifts, with no persistent hover state.
The @media (hover) feature lets you detect this before the user interacts. Apply hover-dependent effects only on capable devices, and provide tap-friendly alternatives on touch screens.
Definition and Usage
Write @media (hover: hover) for devices whose primary input can hover, or @media (hover: none) for touch-first devices. Wrap :hover rules inside (hover: hover) so they never run on touch-only hardware.
💡
Beginner Tip
Do not confuse this with the :hover selector, which styles an element while the pointer is over it. The media feature checks device capability, not current pointer position.
Foundation
📝 Syntax
Use hover: hover or hover: none inside an @media rule:
syntax.css
/* Primary input can hover (mouse/trackpad) */@media(hover:hover){/* Safe to use :hover effects */}/* Primary input cannot hover (touchscreen) */@media(hover:none){/* Tap-friendly defaults */}
Accepted Values
hover: hover — Primary input can hover (typical desktop with mouse).
Hover dropdowns work on desktop. Touch users see nested links expanded — no unreachable submenu items.
Example 4 — hover vs any-hover
See how primary-input hover differs from all-input any-hover on hybrid devices:
hover-vs-any-hover.css
/* Primary input only */@media(hover:hover){.primary-badge{background:#dbeafe;color:#1d4ed8;}}/* Any available input */@media(any-hover:hover){.any-badge{background:#dcfce7;color:#15803d;}}.badge{padding:0.4rem 0.65rem;border-radius:0.35rem;font-size:0.8125rem;font-weight:600;}
The hover media feature is supported in all modern browsers and is essential for touch-friendly responsive design.
✓ Baseline · Modern browsers
Hover capability queries
Works in Chrome, Firefox, Safari, Edge, and Opera.
98%Global support
hover media feature98% supported
Bottom line: Use (hover: hover) to gate hover effects and (hover: none) for touch-safe defaults. Test on real phones and desktops.
Wrap Up
🎉 Conclusion
The hover media feature detects whether the primary input can hover, letting you tailor interactive UI for desktop mice and touchscreens alike. Wrap :hover rules inside (hover: hover) for safe, progressive enhancement.
Always provide touch-friendly alternatives for hidden menus, tooltips, and hover-only actions. When devices have multiple inputs, consider any-hover for broader capability detection.
Use these points when building touch-friendly interactive UI.
5
Core concepts
H01
hover: hover
Can hover.
Desktop
N02
hover: none
Touch-first.
Mobile
P03
Primary
Main input.
Scope
:04
vs :hover
Query vs state.
Compare
🌐05
98% support
Modern browsers.
Compat
❓ Frequently Asked Questions
The hover media feature detects whether the primary input mechanism can hover over elements. Use @media (hover: hover) for mouse/trackpad devices and @media (hover: none) for touch-first devices like phones and tablets.
Two values: hover (primary input can hover, typical of desktops with a mouse) and none (primary input cannot hover, typical of touchscreens).
The media feature is a capability query — it runs before interaction to choose defaults and layouts. The :hover pseudo-class applies styles while the pointer is actively over an element. Use both: the media feature to gate hover-dependent UI, :hover for live feedback.
hover checks only the primary input mechanism. any-hover checks whether any available input can hover. A laptop with touch + mouse reports hover: none (touch may be primary) but any-hover: hover (mouse exists).
Yes. hover is supported in all modern browsers including Chrome, Firefox, Safari, Edge, and Opera. It is essential for touch-friendly responsive design.