`hover` CSS media feature
Baseline Widely available
This feature is well established and works across many devices and browser versions. It's been available across browsers since December 2018.
The hover CSS media feature can be used to test whether the user's primary input mechanism can hover over elements.
Syntax
The hover feature is specified as a keyword value chosen from the list below.
-
none - The primary input mechanism cannot hover at all or cannot conveniently hover (e.g., many mobile devices emulate hovering when the user performs an inconvenient long tap), or there is no primary pointing input mechanism.
-
hover - The primary input mechanism can conveniently hover over elements.
Examples
HTML
<a href="#">Try hovering over me!</a>
CSS
/* default hover effect */
a:hover {
color: black;
background: yellow;
}
@media (hover: hover) {
/* when hover is supported */
a:hover {
color: white;
background: black;
}
}
Result
Specifications
| Specification |
|---|
| Media Queries Level 4 # hover |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on iOS | Samsung Internet | WebView Android | WebView on iOS | |
hover |
38Before Chrome 41, the implementation was buggy and reported(hover: none) on non-touch-based computers with a mouse/trackpad. See bug 40397980. |
12 |
64 |
25Before Opera 28, the implementation was buggy and reported(hover: none) on non-touch-based computers with a mouse/trackpad. See bug 40397980. |
9 |
50On some Android devices, such as certain Samsung models, the(hover: hover) media query may incorrectly match. See bug 41445959. |
64 |
37On some Android devices, such as certain Samsung models, the(hover: hover) media query may incorrectly match. See bug 41445959. |
9 |
5.0On some Android devices, such as certain Samsung models, the(hover: hover) media query may incorrectly match. See bug 41445959. |
50On some Android devices, such as certain Samsung models, the(hover: hover) media query may incorrectly match. See bug 41445959. |
9 |
See also
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@media/hover