BEM Methodology Jacek Spławski
Poznań, January 2016
We are not designing pages, we are designing systems of components.
— Stephen Hay
Modularity is requirement of maintainable systems.
— Ben Callahan
OOCSS / SMACSS / BEM / Atomic / SUITCSS
BEM is a naming convention for classes in HTML and CSS.
Created by Yandex — one of the leading internet companies in Russia.
Block Element Modifier
Block is standalone entity that is meaningful on its own.
Blocks can be nested and interact with each other, semantically they remain equal; there is no precedence or hierarchy.
Block names may consist of lowercase Latin letters, digits, and dashes. Individual
words within names are separated by a dash.
.block
Block name should identify block and say what it is responsible for. The block name
replaces IDs.
Element is parts of a block and have no standalone meaning. They are semantically tied to its block.
Element names may consist of Latin letters, digits, dashes and underscores. CSS class is formed as block name plus
two underscores plus element name.
.block__element
Modifier are flags on blocks or elements. Use them to change appearance or
behavior.
Modifier names may consist of Latin letters, digits, dashes and underscores.
CSS class is formed as block’s or element’s name plus two dashes.
.block__element——modifier
DOM Tree → BEM Tree
Sass ♥ BEM
.block { &——modifier {} &__element {} }
=
.block {}
.block——modifier {}
.block__element {}
BEM ? JS
jQuery BEM Helpers jQuery BEM Plugin i-BEM framework by Yandex
no dependencies on other elements reduce cascading problems reduce amount of CSS code create ready blocks library simple and understandable structure in CSS and HTML code Sass loves BEM drop tag names and IDs
long class names which could look’s weird develop the habit to properly name class modular thinking
https://css-tricks.com/bem-101/ http://getbem.com/ https://en.bem.info/https://www.smashingmagazine.com/2012/04/a-new-front-end-methodology-bem/