HTML Introduction to HTML and CSS Getting Familiar with HTML and CSS Building Web Pages with HTML and CSS

Amandeep Pasricha
Amandeep Pasricha
14,928 Points

Why doesn't the CSS file contain the specific tags attached to the class names?

Amandeep Pasricha [10:09 PM]In the CSS file, why are the class names not shown with their specific tags (such as <h1, <p,<img). Its usually the big tag, such as the header tag along with the class name that gets shown, but wouldn’t it make sense if the specifc tags were shown next to the class names (ex. tag, location, etc)?

1 Answer

Steven Parker
Steven Parker
172,268 Points

Using just a class name as a CSS selector can help make the code more compact, and allow tags of different types to share the same styling. It is considered a "best practice".

Using more selectors than needed is excessive specificity and can have unintended side-effects on the styling.

Amandeep Pasricha
Amandeep Pasricha
14,928 Points

When you say tags of different types, do you mean the bigger tags such as header? As opposed to the tags inside of it such as the h1 tag and the p tag?