The two selectors are designed for completely different purposes, despite the fact that, at least in practice, they seem to do the same thing.
I would say that to determine the state of hovering :hover (at least on devices without a touch screen, see below) would be best practice because:
This makes finding and understanding your style more visible in large CSS blocks.
It uses a specially assigned selector (which can be extended in the specification later, what will happen to your functionality then?)
If you later add a default style for .class , your states are clearly separated accordingly
What happens if you transfer the responsibility of your CSS to another person? Having :hover defined functionality defined under the correct selector greatly simplifies code understanding.
If you have more complex CSS, you will probably use :hover elsewhere, so it should be used for consistency purposes
Two selectors represent the same element, but in different states you should semantically use :hover
But wait a minute. , you may notice that if you set the cursor style for a to default , then the usual hand icon will not appear when you hover ... this indicates that there is preliminary evidence not specifically for the styles :hover ( see this in action here )
In general, there is no reason to break the game, not to use just .class in some cases - it, of course, uses fewer bytes, and if you have a fairly simple setup, then only when developing by you ... then why not, but be careful, best avoided if you want to adhere to strict rules and better support ongoing development.
In addition, do not forget touch screen devices MDN makes an important point here
on touch screens: freezing is problematic or impossible. Parameter: hover pseudo-class never matches or corresponds to a short moment after touching an element. Since touch screen devices are very common, it is important that the web developer does not have access to the content only when it hangs over it, since this content will be hidden to users of such devices.
As such, depending on your requirement, it might not be better to use :hover , as if you used it in your CSS for a touch-screen device, which it may bake depending on unsupported or poor functionality.
source share