Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Modular CSS Using BEM Methodology

Avatar for Muhammad Naufal Muhammad Naufal
December 21, 2019

Modular CSS Using BEM Methodology

BEM (Block, Element, Modifier) is a naming convention to write CSS in a component-based approach. BEM helps to write a more understandable, reusable and scalable CSS.

Avatar for Muhammad Naufal

Muhammad Naufal

December 21, 2019
Tweet

Other Decks in Design

Transcript

  1. When you use BEM, you should avoid using id for

    CSS selector, always use class to maintain low-level specificity
  2. Block is the outmost parent of a component, block defines

    the purpose (“What is it?” - button, modal, etc) not the state (“How does it look?” - blue, big, etc)
  3. The block shouldn’t influence its environment, do not set external

    geometry like margin and position for the block
  4. Element defines the purpose ("What is it?" - item, text,

    etc) not the state ("How does it look like?" - bold, red, etc).
  5. Element is always a part of a block, and shouldn’t

    be used without or separately from a block
  6. Correct, you can have any number of nested elements Incorrect,

    never include more than one element in a class name Nested Element
  7. Use Block when a section of code might be reused

    and does not depend on parent entity Use Element when a section of code can’t be used separately without the parent entity
  8. Modifier defines the state, behavior, and appearance of block or

    element ("How does it look?" - red, big, etc).
  9. Correct, you can use dash or camel case to separate

    multiword name, this also applies to block and element Incorrect, button—outlineprimary is hard to read Multiword Modifier
  10. Element with Modifier When there are block, element, and modifier

    on a class name, it would look like this: [Block]__[Element]—[Modifier]