5 rules to organize your CSS code

Writing CSS code is not as easy as it seems to be. Without some coding rules, we cannot
quickly find a code that is difficult to read and want to debug. Having a better coding rule is
essential for maintaining clean coding practices and making future website coding tasks
easy. If you are a web design company Sri Lanka, here is a list of best practices and rules
that will help you create and maintain a clear and neat CSS style sheet. Not all projects lend
themselves to this type of control. Here are some of the best practices that can lay a solid
foundation for writing a readable and extensible CSS code.
1 – Segment CSS into multiple files
It is best to divide the CSS code into several files each corresponding to a module, a view or
a page of your application. It’s up to you to choose how to cut your style sheet. Cutting into
files makes it easier to navigate when expanding, modifying or creating new declarations.
2 – Establish a naming convention
Having a naming convention for your elements is essential. There are many
recommendations on what is the best way to name these blocks, just choose the standard
method and stick to it while coding the entire website.
3 – Use BEM (Block, Element, Modify)
BEM is a naming methodology that tends to split the entities of your page into blocks and
elements. To make it simple, a page can contain several blocks; each of these blocks can
include one or more aspects of its own. Finally, each of these elements can have a state
which is modified according to an event or action of the user.
4 – Understanding the Open / Closed Principle
This principle goes hand in hand with the example approach in the previous point. When
choosing an OOCSS method, one must always remember this simple principle.
5 – Being DRY
This is a principle that aims to reduce the amount of written code and consolidate
statements into the duplicate. It must be applied if two declarations very often coexist
together. The DRY principle can be beneficial when one codes in Less or Sass.