CSS any-hover Media Feature

Beginner
⏱️ 7 min read
📚 Updated: Jul 2026
🎯 4 Examples
Media Queries

What You’ll Learn

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.

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.

📝 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).

Basic Example

any-hover-basic.css
button {
  padding: 0.65rem 1.25rem;
  font-size: 1rem;
}

@media (any-hover: hover) {
  button {
    background-color: #93c5fd;
  }
}

@media (any-hover: none) {
  button {
    background-color: #fca5a5;
  }
}

any-hover vs hover Media Feature

(hover: hover) Describes the primary input only. On a hybrid device, the primary input might be touch even when a mouse is connected.
(any-hover: hover) Checks all inputs. If a mouse is available anywhere, this matches — usually the safer choice for enabling hover enhancements.

Default Value

There is no CSS default value for any-hover. The browser reports the actual device capability at runtime.

Syntax Rules

  • Use inside an @media block with parentheses: (any-hover: hover).
  • Only two values are valid: hover and none.
  • Combine with other media features: @media (any-hover: hover) and (min-width: 768px).
  • Do not confuse with the :hover pseudo-class — they solve different problems.
  • Prefer any-hover over hover when hybrid devices matter.

Related Topics

@media (any-hover: hover) @media (any-hover: none) @media (any-hover: hover) and (min-width: 48rem)

⚡ Quick Reference

QuestionAnswer
Feature nameany-hover
Valueshover, none
What it detectsWhether any input can hover
Typical hover matchDesktop/laptop with mouse or trackpad
Typical none matchPhones, tablets (touch-only use)
Browser supportAll modern browsers

When to Use any-hover

Reach for any-hover when interaction method matters more than screen size:

  • Progressive enhancement — Add hover-only animations when a pointing device is available.
  • Navigation menus — Use dropdown-on-hover for desktop and tap-to-open for touch.
  • Tooltips — Show extra info on hover-capable devices; keep labels visible on touch.
  • Card actions — Reveal edit/delete buttons on hover; keep them always visible on touch.
  • Hybrid laptops — Prefer any-hover over hover when both touch and mouse may be present.

👀 Live Preview

This button changes color based on your device’s hover capability. On a mouse-driven desktop it appears blue; on touch-only devices it appears coral:

Capability detected by any-hover

Examples Gallery

Practice any-hover with buttons, navigation, cards, and media feature comparisons.

📜 Core Patterns

Adapt styles based on whether the device supports hovering.

Example 1 — Button color by hover capability

Apply a different background color depending on whether the device can hover — the classic introduction to any-hover.

any-hover-button.css
button {
  padding: 0.65rem 1.25rem;
  font-size: 1rem;
  border: none;
  border-radius: 0.4rem;
  cursor: pointer;
}

@media (any-hover: hover) {
  button {
    background-color: #93c5fd;
  }
}

@media (any-hover: none) {
  button {
    background-color: #fca5a5;
  }
}
Try It Yourself

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;
  }
}
Try It Yourself

How It Works

Hover underline effects are gated behind any-hover: hover. Touch users get tap feedback via :active instead.

Example 3 — Always-visible actions on touch

Hide card action buttons behind hover on desktop, but keep them visible on touch devices:

any-hover-card.css
.card {
  position: relative;
  padding: 1rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
}

.card-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

@media (any-hover: hover) {
  .card-actions {
    opacity: 0;
    transition: opacity 0.2s ease;
  }
  .card:hover .card-actions {
    opacity: 1;
  }
}

@media (any-hover: none) {
  .card-actions {
    opacity: 1;
  }
}
Try It Yourself

How It Works

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; }
}
Try It Yourself

How It Works

When in doubt on modern sites, prefer any-hover for enabling hover enhancements. Use any-hover: none to provide touch-safe fallbacks.

💬 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.

⚠️ Common Pitfalls

  • Hiding critical UI — Never hide essential buttons or links behind hover-only patterns without a touch fallback.
  • Confusing with :hoverany-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.

♿ 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.

🖥 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 feature 96% supported

Bottom line: any-hover is safe for responsive interaction patterns in modern projects. Always provide touch fallbacks for critical UI.

🎉 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.

💡 Best Practices

✅ Do

  • Use any-hover for device capability checks
  • Provide touch-safe defaults first
  • Prefer any-hover over hover on hybrid devices
  • Combine with :focus for keyboard users
  • Test on real phones and desktops

❌ Don’t

  • Hide essential actions behind hover only
  • Confuse any-hover with :hover
  • Assume wide screens mean mouse users
  • Skip touch fallbacks on any-hover: none
  • Rely on hover for critical navigation

Key Takeaways

Knowledge Unlocked

Five things to remember about any-hover

Use these points when adapting UI for touch vs hover devices.

5
Core concepts
H 02

hover / none

Two values.

Values
Any 03

All inputs

vs primary.

Compare
:h 04

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.

Practice in the Live Editor

Open the HTML editor and experiment with @media (any-hover: hover) and touch-safe fallback patterns.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful