CSS hover Media Feature

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

Definition and Usage

The hover media feature tests whether the user’s primary input can conveniently hover over elements.

Use @media (hover: hover) for mouse/trackpad-first devices and @media (hover: none) for touch-first phones and tablets (or when there is no primary pointing input). It is not the same as the :hover pseudo-class — the media feature is a capability query; :hover is live pointer-over styling.

Baseline · Widely available.

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

Caveat Some devices mis-report

Certain Android OEMs and hybrid devices can report hover incorrectly. Do not hide essential UI behind hover-only styles.

CSS Syntax

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

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

Feature Values

ValueDescriptionTry it
hoverPrimary input can conveniently hover (mouse, trackpad)Try it
nonePrimary input cannot hover conveniently (typical touch), or no primary pointerTry it
Combined queryPair with a media type or another feature (e.g. pointer)Try it
vs any-hoverPrimary-only vs any hover-capable inputTry it

How to Use hover

Ship usable defaults first, then add hover-only enhancements.

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

Live Preview

This device’s primary hover capability, via matchMedia. The sample button only gets a hover color change when (hover: hover) matches.

Detected hover queries

Try hovering the sample button. On touch-primary devices the hover style may never apply.

Hover detection
(hover: hover) (hover: none)

Checking…

CSS Examples

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

Example 1 — Hover-Capable Devices

Apply a hover color change only when primary input can hover.

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

  @media (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 capability. @media (hover: hover) matches mouse/trackpad-first devices.
  3. Add :hover inside. Green background only while the pointer is over the button.
  4. Touch stays stable. On hover: none, sticky :hover bugs are avoided.

Example 2 — Touch-First Affordance

Show a permanent hint when primary input cannot hover.

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

  @media (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. Desktop users do not need the tap hint.
  2. Match hover: none. Typical phones and tablets report this.
  3. Reveal the hint. Visible copy replaces hover-only discovery.
  4. Keep the control usable. The button works either way.

Example 3 — Screen + Hover

Combine a media type with the hover feature.

CSS
<style>
  a {
    color: #1d4ed8;
    text-decoration: underline;
  }

  @media screen and (hover: hover) {
    a:hover {
      color: #16a34a;
    }
  }
</style>

<a href="#">Learn more</a>
Try It Yourself

How It Works

  1. Default link styles. Readable without hover.
  2. Add screen. Limits the rule to screen (not print).
  3. AND hover capability. Both conditions must match.
  4. Then use :hover. Color shifts only for hover-capable primary inputs.

Edge Cases & Pitfalls

If hover styles feel “stuck” on phones, check these first.

vs :hover

Media feature ≠ pseudo-class

@media (hover) asks “can the primary input hover?” :hover styles the element while the pointer is over it. Use both together.

primary

Only the primary input

A touchscreen laptop may report hover: none even with a mouse attached. Check any-hover when any hover-capable device matters.

bugs

Mis-reported hover on some devices

Some Android builds have reported hover incorrectly. Keep critical actions visible without hover.

sticky

Ungated :hover sticks on touch

Without (hover: hover), first tap can leave :hover styles stuck until another tap. 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

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

✓ Baseline · Widely available

hover

Widely supported since about Chrome 38+, Firefox 64+, Safari 9+, Edge 12+. IE does not support interaction media features. Treat device reporting quirks as progressive-enhancement caveats.

97% Core support
Google Chrome 38+
Full support
Mozilla Firefox 64+
Full support
Apple Safari 9+
Full support
Microsoft Edge 12+
Full support
Opera 25+
Full support
Samsung Internet 5+
Full support*
Internet Explorer —
No support
@media (hover) Widely supported

Bottom line: *Some Android OEMs have mis-reported hover. Safe for progressive enhancement; never hide essential UI behind hover-only styles. It is not a runtime API.

Key Takeaways

  • Role: detect whether the primary input can hover.
  • Values: hover and none inside @media (…).
  • vs :hover: capability query first, then live pointer styles.
  • Practice: defaults for touch; enhance for (hover: hover).

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

Frequently Asked Questions

It tests whether the primary input mechanism can conveniently hover over elements. Use @media (hover: hover) for mouse/trackpad-first devices and @media (hover: none) for touch-first devices.
Two keywords: hover (primary input can hover) and none (primary input cannot hover conveniently, or there is no primary pointing input).
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.
hover checks only the primary input. any-hover checks whether any available input can hover — useful on hybrid devices with both touch and a mouse.
Yes. Some Android OEMs and hybrid devices mis-report primary hover. Prefer progressive enhancement: usable without hover, enhanced when (hover: hover) matches.
No. It is a CSS media feature evaluated by the browser layout engine, not a Node.js or server runtime feature.

Next: inverted-colors

Learn the inverted-colors media feature for accessibility-aware styling.

inverted-colors 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