CSS hover Media Feature

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

What You’ll Learn

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.

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.

📝 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: none — Primary input cannot hover (typical phone or tablet).

hover vs :hover Selector

@media (hover: hover) Capability query — “Can this device hover at all?” Runs once at load/resize.
button:hover { } Interaction state — “Is the pointer over this button right now?”

hover vs any-hover

(hover: hover) Checks the primary input only. A hybrid laptop in tablet mode may report none.
(any-hover: hover) Checks any input. Same laptop with a mouse attached reports hover even if touch is primary.

Basic Example

hover-basic.css
button {
  padding: 0.65rem 1.25rem;
  background: #16a34a;
  color: #fff;
  border: none;
  border-radius: 0.45rem;
  cursor: pointer;
}

@media (hover: hover) {
  button:hover {
    background: #2563eb;
  }
}

Default Value

There is no CSS default. The browser reports the primary input’s hover capability based on the device and current input mode.

Syntax Rules

  • Always nest :hover rules inside (hover: hover) for touch safety.
  • Use (hover: none) for always-visible controls on touch devices.
  • Combine with width: @media (hover: hover) and (min-width: 48rem).
  • For hybrid devices, consider any-hover when any input may hover.
  • Never hide essential actions behind hover-only UI on (hover: none) devices.

Related Topics

@media (hover: hover) @media (hover: none) @media (any-hover: hover)

⚡ Quick Reference

QuestionAnswer
Feature namehover
Valueshover (can hover), none (cannot hover)
What it checksPrimary input mechanism hover capability
Desktop with mouse(hover: hover)
Phone / tablet touch(hover: none)
Hybrid devicesConsider any-hover instead
Browser supportAll modern browsers

When to Use hover

Reach for the hover media feature when input type affects UX:

  • Conditional :hover effects — Enable button color changes only on hover-capable devices.
  • Hover-only dropdowns — Show submenus on mouse-over; use tap menus on touch.
  • Tooltips — Display on hover for desktop; show on tap or always on mobile.
  • Touch-safe defaults — Ensure controls are visible without requiring hover on phones.
  • Cursor styling — Apply cursor: pointer meaningfully on hover devices.

👀 Live Preview

On hover-capable devices (desktop), the button is blue and lifts on hover. On touch-first devices it stays green with no hover lift:

@media (hover) — primary input capability

Examples Gallery

Practice the hover media feature with conditional button styles, touch-safe tooltips, navigation menus, and comparisons to any-hover.

📜 Core Patterns

Apply hover effects only when the primary input supports hovering.

Example 1 — Button hover on capable devices

Green button by default; blue hover effect only when the device supports hover:

hover-button.css
button {
  padding: 0.65rem 1.25rem;
  background: #16a34a;
  color: #fff;
  border: none;
  border-radius: 0.45rem;
  cursor: pointer;
}

@media (hover: hover) {
  button:hover {
    background: #2563eb;
  }
}

@media (hover: none) {
  button {
    background: #16a34a;
  }
}
Try It Yourself

How It Works

Touch users see a consistent green button. Desktop users get a blue hover state without sticky hover bugs on mobile.

Example 2 — Tooltip on hover devices only

Show a tooltip on hover for desktop; keep help text always visible on touch:

hover-tooltip.css
.help-wrap {
  position: relative;
  display: inline-block;
}

.tooltip {
  display: none;
  position: absolute;
  bottom: 100%;
  padding: 0.35rem 0.55rem;
  background: #1e293b;
  color: #fff;
  font-size: 0.75rem;
  border-radius: 0.3rem;
  white-space: nowrap;
}

@media (hover: hover) {
  .help-wrap:hover .tooltip {
    display: block;
  }
}

@media (hover: none) {
  .tooltip {
    display: block;
    position: static;
    margin-top: 0.35rem;
  }
}
Try It Yourself

How It Works

Desktop users discover help on hover. Touch users always see the hint below the label — no hidden information.

Example 3 — Hover dropdown navigation

Reveal submenu on hover for desktop; show submenu always on touch devices:

hover-nav.css
.nav-item {
  position: relative;
}

.submenu {
  display: none;
  position: absolute;
  top: 100%;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 0.4rem;
  padding: 0.35rem 0;
  min-width: 8rem;
}

@media (hover: hover) {
  .nav-item:hover .submenu {
    display: block;
  }
}

@media (hover: none) {
  .submenu {
    display: block;
    position: static;
    border: none;
    padding: 0.25rem 0 0 1rem;
  }
}
Try It Yourself

How It Works

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

How It Works

On a touchscreen laptop using touch as primary, hover may be none while any-hover is hover because a mouse is connected.

💬 Usage Tips

  • Wrap :hover rules — Put interactive hover inside (hover: hover) blocks.
  • Visible on touch — Use (hover: none) to show menus and hints by default.
  • Test real devices — Emulators may not match actual hover reporting.
  • Hybrid laptops — Prefer any-hover when a mouse might be attached.
  • Focus states too — Pair hover styles with :focus-visible for keyboard users.

⚠️ Common Pitfalls

  • Confusing with :hover — Media feature = capability; pseudo-class = current state.
  • Hover-only navigation — Touch users cannot reach hidden submenu items.
  • Sticky hover on touch — Unwrapped :hover can stick after tap on some devices.
  • Assuming desktop = hover — Touchscreen laptops may report hover: none.
  • Ignoring keyboard — Hover effects alone exclude keyboard-only users.

♿ Accessibility

  • No hover-only content — All information must be reachable without hovering.
  • Focus-visible — Mirror hover highlights with keyboard focus styles.
  • Touch targets — On (hover: none), ensure buttons are at least 44×44px.
  • Tooltips — Provide persistent or tappable alternatives on touch devices.
  • Reduced motion — Respect prefers-reduced-motion for hover animations.

🧠 How hover Works

1

Browser detects input

The user agent identifies the primary input mechanism (mouse, touch, pen).

Detect
2

Hover capability evaluated

Returns hover or none for the primary input.

Evaluate
3

@media rules apply

Matching blocks enable or disable hover-dependent layouts and effects.

Apply
=

Input-aware UI

Desktop gets hover polish; touch gets always-accessible controls.

🖥 Browser Compatibility

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 feature 98% supported

Bottom line: Use (hover: hover) to gate hover effects and (hover: none) for touch-safe defaults. Test on real phones and desktops.

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

💡 Best Practices

✅ Do

  • Wrap :hover in (hover: hover)
  • Show controls on touch
  • Add :focus-visible styles
  • Test phones and desktops
  • Use any-hover for hybrids

❌ Don’t

  • Confuse with :hover selector
  • Hide nav behind hover only
  • Assume desktop can hover
  • Skip keyboard accessibility
  • Rely on hover for core UX

Key Takeaways

Knowledge Unlocked

Five things to remember about hover

Use these points when building touch-friendly interactive UI.

5
Core concepts
N 02

hover: none

Touch-first.

Mobile
P 03

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.

Practice in the Live Editor

Open the HTML editor and experiment with @media (hover: hover) and touch-safe button styles.

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