The :hover pseudo-class styles elements when the user moves a mouse or pointer over them. It is one of the most common tools for interactive web design.
01
Mouse-over
Pointer on element.
02
Buttons
Color changes.
03
Links
Underline & color.
04
transition
Smooth effects.
05
:active
Press vs hover.
06
Touch tips
Mobile awareness.
Fundamentals
Introduction
The :hover selector in CSS applies styles to an element when the user hovers over it with a pointing device, such as a mouse.
It is commonly used to enhance the interactivity of buttons, links, navigation items, and cards by changing their appearance on mouse-over, giving users immediate visual feedback.
Definition and Usage
Append :hover to a selector with no space before the colon: a:hover, button:hover, or .card:hover. Styles apply only while the pointer is over the element and revert when it moves away.
💡
Beginner Tip
Put transition on the base element (e.g. .button), not just on :hover, so the color or size change animates smoothly both when entering and leaving hover.
Foundation
📝 Syntax
The syntax for the :hover pseudo-class is:
syntax.css
element:hover{/* CSS properties */}
The :hover pseudo-class can be used on any HTML element, though it is most commonly applied to interactive elements like <a>, <button>, and navigation items.
Specificity order — If :active is declared before :hover, hover may override the pressed state unexpectedly.
Sticky hover on touch — On some mobile browsers, the first tap triggers hover and a second tap activates the link. Test on real devices.
A11y
♿ Accessibility
Do not rely on hover alone — Essential information and actions must be available without hovering.
Provide :focus styles — Mirror or complement hover styles with visible :focus or :focus-visible indicators for keyboard users.
Sufficient contrast — Hover color changes must still meet WCAG contrast requirements.
Large touch targets — On mobile, ensure buttons and links are easy to tap without needing hover feedback.
Reduced motion — Consider @media (prefers-reduced-motion: reduce) to disable large hover animations for sensitive users.
🧠 How :hover Works
1
Pointer enters element
The user moves a mouse, trackpad, or stylus over the target element.
Enter
2
:hover rule matches
The browser applies styles from element:hover declarations.
Match
3
Visual feedback renders
Color, shadow, or transform changes give the user immediate feedback.
Render
=
👉
Interactive experience
Users know which elements respond to their pointer.
Compatibility
🖥 Browser Compatibility
The :hover pseudo-class is supported in all modern browsers on desktop and mobile.
✓ Baseline · Universal support
Hover styling everywhere
:hover works reliably in Chrome, Firefox, Safari, Edge, and Opera.
99%Universal support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions
Full support
OperaAll modern versions
Full support
:hover pseudo-class99% supported
Bottom line::hover is safe everywhere. Remember touch devices may not trigger hover consistently.
Wrap Up
🎉 Conclusion
The :hover selector is a simple yet powerful tool in CSS that helps create dynamic, interactive web pages. Whether it is changing the color of a button or adding a visual effect to cards, :hover enhances user interaction with immediate visual feedback.
Combine it with transition for smooth effects, pair it with :focus and :active for complete interaction coverage, and always consider touch-device users when designing hover-dependent UI.
The :hover pseudo-class applies styles to an element when the user moves a pointing device (such as a mouse) over it. It provides immediate visual feedback for interactive elements like buttons and links.
:hover is designed for pointer devices like a mouse. On touchscreens, hover may not trigger consistently, or it may stick after a tap. Do not rely on hover alone for essential functionality on mobile.
:hover applies while the pointer rests over an element. :active applies only while the user is pressing or clicking. Use both together for polished button interactions.
Yes. While :hover is most common on links and buttons, it works on any element including div, img, and li. This enables card highlights, image zoom effects, and menu styling.
Yes, when you want smooth color, size, or shadow changes. Add transition on the base selector (not only :hover) so the effect animates both in and out.