Why do we need pseudo-classes?

I just completed the “Adjust the Hover State of an Anchor Tag” using a pseudo-class to make it so the text turns blue when hovering. No problem.

My question is, why do we use pseudo-classes in CSS? Why isn’t there a way to apply a hover color directly to a class using something like
a { color: black; hover-color: blue;
}

Hope this make sense.

Think about this. Your suggestion literally doubles the number of attributes needed in CSS (you need all the attributes) – hover-color, hover-background-color, hover-border, etc. Then you have all the other pseudo-classes (:link, :focus and so on). Most of those also need to duplicate every single attribute in CSS – focus-color, link-color, etc. There are about 30. Some are for specific input tags so can only take certain attributes. But realistically what you’re saying would multiply the size of the CSS language by a factor of 15-20

vs simply adding a tiny amount of extra syntax to the language to represent states.

3 Likes

Thank you,
That makes sense. I didn’t realize you have to specify all the attributes.