CSS any-hover Media Feature

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The any-hover media feature tests whether any available input can conveniently hover over elements.

Use @media (any-hover: hover) when a mouse, trackpad, or another hover-capable device is present. Use @media (any-hover: none) when nothing can hover (typical phones without a mouse). Unlike hover, it is not limited to the primary input — useful on hybrid touch + mouse devices. It is not the same as the :hover pseudo-class.

Baseline · Widely available.

Not deprecated. Standard-track interaction media feature (Media Queries Level 4). Widely available since December 2018. Prefer touch-friendly defaults, then enhance when (any-hover: hover) matches.

Caveat Capability can change

Plugging in a mouse can flip any-hover from none to hover. Keep essential UI usable without hover, then enhance.

CSS Syntax

syntax.css
@media (any-hover: none | hover) { … }

Always wrap the feature in parentheses. Invalid forms like @media any-hover(hover) do not work.

Feature Values

ValueDescriptionTry it
hoverAt least one input can conveniently hoverTry it
noneNo input can hover conveniently, or no pointing inputTry it
vs hoverAny input vs primary input onlyTry it
Combined queryPair with pointer or a media typeTry it

How to Use any-hover

Ship usable defaults first, then add hover-only enhancements for any hover-capable input.

  1. Design controls that work with tap/click without relying on hover.
  2. Wrap hover-dependent styles in @media (any-hover: hover).
  3. Optionally style no-hover UX with @media (any-hover: none).
  4. Use :hover inside that query for live pointer feedback.
PieceRequired?Role
@mediaYesWraps the media feature
any-hover keywordYeshover or none
Default stylesYesMust work when no input can hover
:hover rulesOptionalLive feedback once capability is confirmed

Live Preview

This device’s any-hover result via matchMedia. The sample button only gets a hover color change when (any-hover: hover) matches.

Detected any-hover queries

Try hovering the sample button. On devices with no hover-capable input, the hover style may never apply.

any-hover detection
(any-hover: hover) (any-hover: none)

Checking…

CSS Examples

Each snippet focuses on the any-hover media feature. Pair with :hover only when some input can hover. Use Try It Yourself for a live editor.

Example 1 — Any Hover-Capable Input

Apply a hover color change when at least one input can hover.

CSS
<style>
  button {
    background: #2563eb;
    color: #fff;
    border: 0;
    padding: 12px 16px;
  }

  @media (any-hover: hover) {
    button:hover {
      background: #16a34a;
    }
  }
</style>

<button type="button">Save</button>
Try It Yourself

How It Works

  1. Set a solid default. Blue button works for every input.
  2. Query any input. @media (any-hover: hover) matches if a mouse, trackpad, or similar exists.
  3. Add :hover inside. Green background only while a pointer is over the button.
  4. Hybrid-friendly. A tablet with a Bluetooth mouse can still get the hover style.

Example 2 — No Hover-Capable Input

Show a permanent hint when no input can hover.

CSS
<style>
  .hint {
    display: none;
    color: #64748b;
  }

  @media (any-hover: none) {
    .hint {
      display: block;
    }
  }
</style>

<button type="button">Menu</button>
<p class="hint">Tap to open</p>
Try It Yourself

How It Works

  1. Hide by default. Hover-capable users do not need the tap hint.
  2. Match any-hover: none. Typical phones without a mouse report this.
  3. Reveal the hint. Visible copy replaces hover-only discovery.
  4. Keep the control usable. The button works either way.

Example 3 — any-hover vs hover

Compare primary-only hover with any-input any-hover.

CSS
<style>
  .box {
    padding: 12px;
    border: 1px solid #64748b;
  }

  .primary::after {
    content: " primary: unknown";
  }

  .any::after {
    content: " any: unknown";
  }

  @media (hover: hover) {
    .primary::after { content: " primary: hover"; }
  }

  @media (hover: none) {
    .primary::after { content: " primary: none"; }
  }

  @media (any-hover: hover) {
    .any::after { content: " any: hover"; }
  }

  @media (any-hover: none) {
    .any::after { content: " any: none"; }
  }
</style>

<p class="box primary">hover</p>
<p class="box any">any-hover</p>
Try It Yourself

How It Works

  1. Query primary hover. hover reflects the main pointing device.
  2. Query any hover. any-hover scans all available inputs.
  3. Compare the results. A touch-first laptop with a mouse may show none vs hover.
  4. Pick the right feature. Use any-hover when accessory pointers matter.

Edge Cases & Pitfalls

Hybrid devices are where any-hover and hover most often disagree.

vs hover

Any input vs primary input

hover is primary-only. any-hover is true if any connected input can hover. Prefer any-hover for accessory mice and pens.

vs :hover

Media feature ≠ pseudo-class

@media (any-hover) asks “can something hover?” :hover styles the element while a pointer is over it. Use both together.

sticky

Ungated :hover sticks on touch

Without (any-hover: hover), first tap can leave :hover styles stuck. Gate hover chrome with the media feature.

a11y

Keyboard users still need focus

Pair interactive styles with :focus-visible. Hover capability does not replace keyboard focus indicators.

Browser Support

any-hover is a browser media feature. Node.js, Deno, and Bun do not evaluate it.

✓ Baseline · Widely available since Dec 2018

any-hover

Chrome 41+, Edge 16+, Firefox 64+, Safari 9+, Opera 28+, Samsung Internet 5+. Internet Explorer has no support.

97% Global reach
Google Chrome 41+
Full support
Mozilla Firefox 64+
Full support
Apple Safari 9+
Full support
Microsoft Edge 16+
Full support
Opera 28+
Full support
Samsung Internet 5+
Full support
Internet Explorer —
No support
@media (any-hover) Widely supported

Bottom line: Safe for progressive enhancement. Never hide essential UI behind hover-only styles. It is not a server runtime API.

Key Takeaways

  • Role: detect whether any available input can hover.
  • Values: hover and none inside @media (…).
  • vs hover: any input, not only the primary one.
  • Practice: defaults for touch; enhance for (any-hover: hover).

One line: ask if any input can hover, then decide whether :hover styles are safe to rely on.

Frequently Asked Questions

It tests whether any available input mechanism can conveniently hover over elements. Use @media (any-hover: hover) when at least one input can hover, and @media (any-hover: none) when none can.
Two keywords: hover (one or more inputs can hover) and none (no input can hover conveniently, or there is no pointing input).
hover checks only the primary input. any-hover checks all inputs — so a touchscreen laptop with a mouse often matches (any-hover: hover) even if (hover: none).
The media feature is a capability query evaluated before interaction. The :hover pseudo-class styles an element while the pointer is over it. Gate hover-only UI with the media feature; use :hover for live feedback.
Prefer any-hover when hover-capable accessories matter (external mouse on a tablet, trackpad on a convertible). Prefer hover when you care only about the primary input.
No. It is a CSS media feature evaluated by the browser layout engine, not a Node.js or server runtime feature.

Next: any-pointer

Learn the any-pointer media feature for fine vs coarse pointing across devices.

any-pointer tutorial →

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.

8 people found this page helpful