determine which elements in the DOM tree will be styled by the defined properties. Selectors can match HTML elements, as well as an element's class, ID, or any of its attributes. Here are some examples of selectors:
a rule declaration their style. Properties are key-value pairs, and a rule declaration can contain one or more property declarations. Property declarations look like this:
Prefer dashes over camelCasing in class names. ◇ Underscores and PascalCasing are okay if you are using BEM ◇ Do not use ID selectors ◇ When using multiple selectors in a rule declaration, give each selector its own 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
comments. ◇ Prefer comments on their own line. Avoid end-of-line comments. ◇ Write detailed comments for code that isn't self- documenting: ■ Uses of z-index ■ Compatibility or browser-specific hacks
BEM for these reasons: ◇ It helps create clear, strict relationships between CSS and HTML ◇ It helps us create reusable, composable components ◇ It allows for less nesting and lower specificity ◇ It helps in building scalable stylesheets
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.
your CSS and JavaScript. Conflating the two often leads to, at a minimum, time wasted during refactoring when a developer must cross-reference each class they are changing, and at its worst, developers being afraid to make changes for fear of breaking functionality. We recommend creating JavaScript-specific classes to bind to, prefixed with .js-:
snake_cased variable names. It is acceptable to prefix variable names that are intended to be used only within the same file with an underscore (e.g. $_my-variable).
deep! When selectors become this long, you're likely writing CSS that is: ◇Strongly coupled to the HTML (fragile) —OR— ◇Overly specific (powerful) —OR— ◇Not reusable