Skip to content

CSS & SASS Standards

Cosmin Doroftei edited this page Sep 25, 2018 · 33 revisions
  1. Formatting
  2. Comments
  3. OOCSS and BEM

Formatting

  • Use soft tabs (2 spaces) for indentation
  • Prefer dashes over camelCasing in class names.

Bad

.componentTopHeroPanel {
  //
}
.component_top_hero_panel {
  //
}

Good

.component--top-hero-panel {
  //
}
  • Do not use ID selectors. While it is possible to select elements by ID in CSS, it should generally be considered an anti-pattern. ID selectors introduce an unnecessarily high level of specificity to your rule declarations, and they are not reusable. For more details, please read CSS Wizardry's article

Bad

#btn-orange {
  //
}
  • When using multiple selectors in a rule declaration, give each selector its own line.

Bad

.class-no, .class-not-good, .class-not-good-at-all {
    // ...
}

Good

.class-good, 
.class-one, 
.class-one-per-line {
    // ...
}
  • Put a space before the opening brace { in rule declarations
  • In properties, put a space after, but not before, the : character.
  • Put closing braces } of rule declarations on a new line
  • Put blank lines between rule declarations

Clone this wiki locally