:hover CSS Pseudo Class
Description
The :hover pseudo-class in CSS is used to apply styles to an element when the user designates it with a pointing device, typically a mouse. It is one of the most commonly used pseudo-classes for creating interactive and responsive designs, allowing developers to change the appearance of elements on user interaction without the need for JavaScript. The :hover state is triggered when the cursor is positioned over the element, and it ceases once the cursor moves away. This pseudo-class is widely supported across modern browsers and can be applied to almost any visible element, including div, a, button, and img.
One of the most common uses of :hover is for enhancing user experience through visual feedback. For example, developers often use it to change the color, background-color, border, or transform properties when a user hovers over an element. This can include effects like changing the button color, underlining links, or scaling images slightly to indicate interactivity. :hover can also be combined with transitions defined using the transition property to create smooth animations that enhance visual appeal and usability.
It is important to note that :hover works differently on touch devices, as they typically do not have a persistent pointing device. In such cases, some devices emulate hover effects on the first tap, but this behavior can vary widely. Best practice is to ensure that essential functionality is accessible without relying solely on :hover. Additionally, :hover can be combined with other pseudo-classes like :focus or :active to handle multiple interactive states of an element.
Example usage:
<a href="#" class="button">Hover me!</a>
.button {
background-color: #3498db;
color: white;
padding: 10px 20px;
text-decoration: none;
border-radius: 5px;
transition: background-color 0.3s ease;
}
.button:hover {
background-color: #2980b9;
}
In this example, the button's background color changes smoothly when the user hovers over it, thanks to the combination of :hover and the transition property. This is a fundamental pattern in modern web design to provide immediate visual feedback to users.
Syntax
:hover {
/* ... */
}
Example
Browser Support
The following information will show you the current browser support for the CSS :hover pseudo class. Hover over a browser icon to see the version that first introduced support for this CSS psuedo class.
This psuedo class is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 31st December 2025
