Style Guide CSS Methodologies
Print this Page
CSS Methodologies

It is a known fact that the right styleguide can significantly increase productivity for development, debugging, and implementation of new features in legacy code. Sadly, most CSS codebases are sometimes developed without any structures or rules. This leads to an unmaintainable CSS codebase in the long term. To address this issue, we need to understand better CSS methodologies and choose some specific techniques to set up a conventional standard for our team to follow.

CSS Writing Methodologies
The way we write CSS has changed a lot in last few years, and over times, the efforts are to write CSS that are more flexible, reusable, comprehensible and manageable. The fomulated methodologies include:
ACSS Example

ACSS is a method of using one class for one CSS property so that same property can be used in different parts of a site. This eliminates the possibility of duplicating that property in the stylesheet since the class itself is being used multiple times in the HTML. This results in smaller, 'drier' stylesheets, and is also a great way to quick a way for prototype layout and components on a web page.

Example of ACSS Coding Style

CSS
'custom' : {
'brandColor' : '#0280ae',
'columnWidth' : '20px',
}
html
<div class="Pos(a) Bgc(brandColor) W(columnWidth) H(90px)"></div>
<div class="C(brandColor) BdB Bdc(brandColor) Mstart(columnWidth) P(10px)">
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
</div>

To learn more about ACSS, please visit Atomic CSS site.
BEM (Block, Element, Modifer)

Block, Element, Modifier — more commonly called BEM — is a CSS class-naming system devised by the dev team at Yandex (the Google of Russia). The idea behind BEM is to differentiate CSS classes that fulfill different roles. This is done by naming CSS classes in a way that indicates their role.

In BEM terminology, a block is an independent, modular UI component. A block may be composed of multiple HTML elements, or even multiple blocks. An example of a block might be your navigation menu or search form.

An element is a component of a block. An element serves a singular purpose. For example, if you have a navigation menu block, then elements of it might be your navigation menu’s links, which, in turn, might be in the form of list items (li elements) and links (a elements).

A modifier is a CSS class that changes the default presentation of a block or element.

BEM Example

CSS
/* Block component */
.btn { }
/* Element that depends upon the block */
.btn__price { }
/* Modifier that changes the style of the block */
.btn__price--big { }
html
<a class="btn btn__price" href="http://www.naming_convention.html">
<span class="btn__price--big">$9.99</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
</p>
</a>

To learn more about BEM, please visit BEM Info Methodology Site.
OOCSS (Object Oriented CSS)

Nicole Sullivan’s Object-Oriented CSS was launched in 2009. It was really the first CSS methodology to become widely adopted. It’s still hugely influential today.

One goal of the OOCSS methodology is to reduce duplication of the same properties throughout your various style rules. In other words, OOCSS can help maintain dry stylesheets. The methodology attempts to achieve this goal by using lots of small, modular, specialist CSS classes.

OOCSS advocates the separation of structure from skin. The methodology makes a clear distinction between content and its containers. In OOCSS, style rules are written exclusively using CSS class selectors.

For example, the style of the button elements might be set via two classes.

OOCSS Example

CSS
.button {
padding: 5px 10px;
  } /* provides the button’s basic structure */

.button-grey {
background-color: #eee;
border: 1px solid #ddd;
color: #555;
  } /* applies colors and other visual properties */
html
<button class="button button-grey">

To learn more about OOCSS, please visit oocss.org site .
SMACSS (Scalable and Modular Architecture for CSS)

Developed in 2011 by Jonathan Snook, SMACSS works by identifying the styles into 5 categories: base, layout, module, state and themes. Each of these categories come with a set of usage rules.

The different style rules can be identified using a prefix in the class name, for example: l-header (for layout) or t-header (for theme). These different types of rules can also be organized by placing them in separate files and folders.

SMACSS Example

CSS
div#featured ul {
margin: 0;
padding: 0;
list-style-type: none;
  }

div#featured li {
float: left;
height: 100px;
margin-left: 10px;
  }
html
<div>
<h2> Featured </h2>
<ul>
<li>Featured Item 1 </li>
<li>Featured Item 2 </li>
<li>Featured Item 3 </li>
</ul>

To learn more about OOCSS, please visit SMACSS site .
The above CSS methodologies explain us a system to manage and optimize the CSS codes. They can be combined together, like OOCSS-SMACSS, or OOCSS-BEM, or BEM-SAMCSS to suit our needs. Among thoses methodologies, OOCSS is quite similar to Boostrap CSS structure.