From the course: CSS: Selectors

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Why can't I use CSS classes exclusively? Selectors best practices

Why can't I use CSS classes exclusively? Selectors best practices - CSS Tutorial

From the course: CSS: Selectors

Start my 1-month free trial

Why can't I use CSS classes exclusively? Selectors best practices

- [Instructor] Now that you know all of these fabulous ways to make selectors, what should you do? Should you try out all of them or should you just throw up classes everywhere you go? It might seem easier especially to a beginner to use classes for all of your styles everywhere. Let's look at some best practices in CSS selector choice. Generally speaking in CSS, less is more. Simple selectors with the least amount of specificity for what you are trying to select is what you want to use. Classes everywhere means cluttering up your HTML with potentially unneeded CSS classes reducing code reusability. And with every selector at the same level of specificity, all of your styles may fight with each other frequently. The big C in CSS stands for Cascade and when combined with inheritance, this is your friend. It makes styling simple, easy to override styles with other options under different conditions. If every selector is the same specificity, such as when everything is styled with the…

Contents