How to use ‘hover’ in CSS

If you want the underline to be present while the mouse hovers over the link, then:

a:hover {text-decoration: underline; }

is sufficient, however you can also use a class-name of ‘hover’ if you wish, and the following would be equally applicable:

a.hover:hover {text-decoration: underline; }

Incidentally it may be worth pointing out that the class name of ‘hover’ doesn’t really add anything to the element, as the psuedo-element of a:hover does the same thing as that of a.hover:hover. Unless it’s just a demonstration of using a class-name.

Leave a Comment