Do you avoid adding unnecessary CSS classes?

Last updated by Geordie Robinson [SSW] 3 months ago.See history

When making or editing CSS or HTML content it is important to avoid adding classes and ID's unnecessarily.

It can be tempting to add classes on elements, as it is often the most obvious solution to CSS problems... but doing so will lead to overly cluttered code and a host of overly specific solutions. When working on CSS it is almost always better to reuse rather than adding additional classes.

You should use a front-end framework, like Bootstrap or Tailwind. The best front-end frameworks will include most of the clases you will need on a project. Basically you will only need new classes for very specific layout elements.


<a class="view-all-link" href="">View All</a>


  margin-top: 0;

Figure: Bad example - The "view-all-link" class was added unnecessarily


<a class="mt-0" href="">View All</a>

Figure: Good example - Using Bootstrap's class "mt-0" has the same affect without adding any class

We open source. Powered by GitHub