Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a good practice to add prefixes to all css classes? [closed]

Tags:

css

Is it a good practice to add prefixes to all css classes to avoid conflicts with possible third party widgets/CMS/etc? Isn't this bad as it adds to file size ? How far should I go ? For example if my name is John Doe and I work on a business theme should I use JDBT-menu? Any article on this subject would be great. Thanks

like image 469
Emanuel Mocean Avatar asked Feb 01 '14 20:02

Emanuel Mocean


2 Answers

In my opinion, it's a very good idea to prefix CSS class names, along with implementing a strategy to follow logical naming conventions.

Whilst prefixes can be considered overkill for small projects, the lack of proper CSS namespace support can lead to conflicts on larger projects, especially when using third-party libraries. You can easily avoid such conflicts by prefixing CSS classes with your initials or a short abbreviation of your project name. Even on large CSS files you are only likely to add a few hundred bytes, and there are much better ways of minimising file size.

Take a look at the free online book, Scalable and Modular Architecture for CSS, for advice on CSS naming best practices. http://smacss.com

like image 122
monkeyhybrid Avatar answered Sep 30 '22 15:09

monkeyhybrid


Personally, I don't think is a bad idea. It may come in handy for future developers working on the project, if they can identify your code from the CMS/Framework code nice and easy.

I work a lot with Bootstrap, and I always use prefix.

like image 27
Eric Mitjans Avatar answered Sep 30 '22 15:09

Eric Mitjans