The any-hover media feature lets you detect whether any input on the device can hover. Adapt layouts for touch screens vs mouse-driven desktops without guessing from screen width alone.
01
@media
Media query.
02
hover
Can hover.
03
none
Touch-only.
04
vs hover
Primary input.
05
vs :hover
Capability vs state.
06
A11y
Touch-safe UI.
Fundamentals
Introduction
The @media rule in CSS applies styles based on device characteristics. The any-hover media feature answers a simple question: can any input mechanism on this device hover over elements?
This is especially useful for responsive design. A wide tablet might look like a desktop by screen size, but if the user is touching the screen, hover-only menus and tooltips will feel broken. any-hover helps you choose the right default experience.
Definition and Usage
Wrap CSS rules inside @media (any-hover: hover) or @media (any-hover: none). The browser evaluates the device’s available inputs — mouse, trackpad, stylus, touch screen — and applies matching styles.
💡
Beginner Tip
Think of any-hover as a device capability check, not a real-time hover state. Use it to set defaults (visible buttons on touch, hover-reveal on desktop). Use the :hover pseudo-class for pointer-over feedback.
Foundation
📝 Syntax
The syntax for the any-hover media feature inside an @media rule is:
syntax.css
@media(any-hover:value){/* CSS rules here */}
Accepted Values
hover — At least one input mechanism can hover over elements (typical desktop with a mouse or trackpad).
none — No input mechanism can hover, or there is no pointing device (typical phones and tablets).
Blue on hover-capable devices; coral on touch-only.
How It Works
The browser evaluates device inputs once. Desktop users see blue; touch-only users see coral — no JavaScript required.
Example 2 — Hover-only underline on navigation
Only add underline-on-hover effects when hovering is actually possible:
any-hover-nav.css
nav a{color:#334155;text-decoration:none;padding:0.5rem 0.75rem;}@media(any-hover:hover){nav a:hover{text-decoration:underline;color:#2563eb;}}@media(any-hover:none){nav a:active{color:#2563eb;}}
Touch users never need to discover hidden controls. Desktop users get a cleaner card with actions revealed on hover.
Example 4 — any-hover vs hover on hybrid devices
On a touchscreen laptop, hover may report none while any-hover reports hover when a mouse is connected:
any-hover-vs-hover.css
/* Primary input only — may miss connected mouse */@media(hover:hover){.tip{display:none;}.item:hover .tip{display:block;}}/* Any input — safer for hybrid devices */@media(any-hover:hover){.enhanced{cursor:pointer;}.enhanced:hover{background:#eff6ff;}}@media(any-hover:none){.tip{display:block;}}
When in doubt on modern sites, prefer any-hover for enabling hover enhancements. Use any-hover: none to provide touch-safe fallbacks.
Tips
💬 Usage Tips
Pair with :hover — Use any-hover to decide whether to enable hover effects; use :hover for the actual pointer-over styling.
Touch-safe defaults — Start with styles that work without hover, then enhance with @media (any-hover: hover).
Do not use width alone — Large touch screens break the assumption that wide viewports mean mouse users.
Combine media features — Mix with min-width, prefers-reduced-motion, or any-pointer for finer control.
Test real devices — Emulators may not report hover capability accurately; verify on phones and laptops.
Watch Out
⚠️ Common Pitfalls
Hiding critical UI — Never hide essential buttons or links behind hover-only patterns without a touch fallback.
Confusing with :hover — any-hover does not fire when the user moves the mouse; it is evaluated once based on device capability.
Assuming mobile = none — Some tablets with styluses or connected mice may report hover.
Replacing accessibility — Keyboard users still need :focus styles regardless of hover capability.
Overusing media queries — Simple sites may not need hover detection; use it when interaction patterns genuinely differ.
A11y
♿ Accessibility
Progressive enhancement — Ensure all actions are reachable without hovering, especially on any-hover: none devices.
Visible focus indicators — Mirror interactive affordances with :focus or :focus-visible styles.
No hover-only information — Tooltips and extra details must have a non-hover way to access them.
Large touch targets — On touch devices, make buttons and links at least 44×44 CSS pixels.
Reduced motion — Respect prefers-reduced-motion when adding hover animations.
🧠 How any-hover Works
1
Browser scans inputs
The user agent checks all available input mechanisms: mouse, trackpad, touch, stylus, etc.
Detect
2
Capability is reported
If any input can hover, any-hover: hover matches. Otherwise any-hover: none matches.
Match
3
@media rules apply
CSS inside matching @media (any-hover: …) blocks is applied to the page.
Apply
=
📱
Right experience per device
Touch users get tap-friendly UI; mouse users get hover enhancements.
Compatibility
🖥 Browser Compatibility
The any-hover media feature is supported in all modern browsers.
✓ Baseline · Modern browsers
Hover detection in production
any-hover works in Chrome, Firefox, Safari, Edge, and Opera.
96%Global support
any-hover media feature96% supported
Bottom line:any-hover is safe for responsive interaction patterns in modern projects. Always provide touch fallbacks for critical UI.
Wrap Up
🎉 Conclusion
The any-hover media feature is a powerful tool for building adaptive interfaces. By detecting whether any input on the device can hover, you can tailor layouts for touch screens and mouse-driven desktops without relying on screen width alone.
Combine it with the :hover pseudo-class for pointer feedback and any-hover: none fallbacks for touch-safe defaults. Your users get an experience that matches how they actually interact with your site.
Use these points when adapting UI for touch vs hover devices.
5
Core concepts
@01
Media query
Device check.
Syntax
H02
hover / none
Two values.
Values
Any03
All inputs
vs primary.
Compare
:h04
Not :hover
Capability.
Distinction
🌐05
96% support
Modern browsers.
Compat
❓ Frequently Asked Questions
The any-hover media feature reports whether any available input mechanism on the device can hover over elements. Use @media (any-hover: hover) or @media (any-hover: none) to adapt styles for mouse/trackpad vs touch-only environments.
The hover media feature describes the primary input mechanism only. The any-hover feature checks all input mechanisms — so a laptop with both a touchscreen and a mouse evaluates as hover because the mouse can hover, even if touch cannot.
any-hover accepts two values: hover (at least one input can hover) and none (no input can hover, typical of phones and tablets without a mouse).
:hover applies styles while the pointer is over an element. any-hover is a media query that detects device capability before interaction — use it to choose layouts or defaults, not to replace :hover for real-time feedback.
Yes. any-hover is supported in all modern browsers including Chrome, Firefox, Safari, Edge, and Opera. It is safe for production responsive design.