SlideShare a Scribd company logo
by Varya Stepanova
@varya_en http://varya.me
BEM it!
Introduction to BEM Methodology
Why bother?
There is no unified semantic model
across different FE technologies
● HTML stands for hypertext
I've heard we mostly do web apps...
● CSS offers no structure out of the box
Usually a pile of rules put together. Sorry.
● JavaScript uses its own approaches.
...a new one comes with every framework.
● ≈ 8,500 packages in Bower registry
● JavaScript:
the most popular language on GitHub
Repositories created:
≈ 264,000 in 2013
≈ 296,000 in 2012
Frameworks are not enough
BEM to the rescue
What is BEM?
BEM claims that simple semantic model
(Blocks, Elements, and Modifiers)
is enough to define the way you author
HTML / CSS / JavaScript, structure code
and components, set up interaction
and scale your project to build
an industry-leading service.
What is BEM?
● BEM is a methodology, not a framework
Semantic model + best practices
for all things frontend
● BEM is a fix for web app semantics
...the same as jQuery is a fix for DOM APIs
● Originally introduced by Yandex
— 19 million daily audience
— 200+ web services
— tools, code, tutorials, conferences
— open source
Some theory
What is BEM?
BLOCK
– Standalone part of an interface:
● button
● text field
● flyout
● heading
● menu
What is BEM?
BLOCK
– Standalone part of an interface:
● button
● text field
● flyout
● heading
● menu
– Re-usable in different contexts
– Self-sufficient
What is BEM?
ELEMENT
– An integral part of a block:
● button
● text field
● flyout
● heading
● menu
What is BEM?
ELEMENT
– An integral part of a block:
● button — contains no elements
● text field label
● flyout title
● heading logo
● menu item
What is BEM?
ELEMENT
– An integral part of a block:
● button — contains no elements
● text field label
● flyout title
● heading logo
● menu item
– No standalone meaning outside of a block
– Some blocks have no elements
What is BEM?
MODIFIER
– Defines property or state on a block or
element:
● button
● text field
● flyout
● heading
● menu item
What is BEM?
MODIFIER
– Defines property or state on a block or
element:
● button theme
● text field editable state
● flyout alignment
● heading level
● menu item bullet type
What is BEM?
MODIFIER
– Defines property or state on a block or
element:
● button theme
● text field editable state
● flyout alignment
● heading level
● menu item bullet type
– Multiple modifiers may co-exist
on a single block/element
BEM forms a semantic overlay over
the existing DOM structure.
This overlay is called a BEM tree.
DOM tree → BEM tree
How does BEM map to DOM?
● Blocks/elems/mods are denoted
with CSS classes using a naming
convention.
● DOM nodes can be shared:
— block1 + block2 may occupy the same
container;
— element1 + block2 may co-exist on
the same node.
● DOM is encapsulated:
— complex DOM structure may constitute
a single element
BEM HOWTO
for your beloved project
with benefits explained
HOWTO: HTML / CSS
CSS naming conventions
“BEM uses CSS class names to
denote blocks, elements and
modifiers.”
CSS naming conventions
BLOCK
.button
.text-field
.flyout
.heading
.menu
or with prefix
.b-button
.b-text-field
.b-flyout
.b-heading
.b-menu
CSS naming conventions
<ul class=”menu”>
<li>
<a href=”/more”>Read More</a>
</li>
<li>
<a href=”/buy”>Buy Online</a>
</li>
<li>
<a href=”/buy”>Contact</a>
</li>
</ul>
CSS naming conventions
ELEMENT
.button__icon
.text-field__label
.flyout__title
.heading__logo
.menu__item
CSS naming conventions
<ul class=”menu”>
<li class=”menu__item”>
<a href=”/more”>Read More</a>
</li>
<li class=”menu__item”>
<a href=”/buy”>Buy Online</a>
</li>
<li class=”menu__item”>
<a href=”/buy”>Contact</a>
</li>
</ul>
CSS naming conventions
MODIFIER
.button_theme_dark
.text-field_editable
.flyout_align_top
.heading_level_alpha
.menu__item_promo
CSS naming conventions
MODIFIER
.button--theme--dark
.text-field--editable
.flyout--align--top
.heading--level--alpha
.menu__item--promo
as you wish
CSS naming conventions
<ul class=”menu”>
<li class=”menu__item”>
<a href=”/more”>Read More</a>
</li>
<li class=”menu__item”>
<a href=”/buy”>Buy Online</a>
</li>
<li class=”menu__item”>
<a href=”/buy”>Contact</a>
</li>
</ul>
CSS naming conventions
<ul class=”menu”>
<li class=”menu__item menu__item_promo”>
<a href=”/more”>Read More</a>
</li>
<li class=”menu__item”>
<a href=”/buy”>Buy Online</a>
</li>
<li class=”menu__item”>
<a href=”/buy”>Contact</a>
</li>
</ul>
so structure
much semantics
wow
much semantics
very code
such frontend
BEM CSS: best practices
1. Map the whole document to BEM blocks
2. No CSS outside of blocks
3. Independent blocks → no global CSS
resets
Benefits!
Drop tag names and IDs
● Faster selectors
● Re-use same semantics on any tag:
— <DIV class=”block”>
— <SPAN class=”block”>
— <TABLE class=”block”>
Benefits!
CSS specificity magic solved
Priority of CSS rules:
by specificity first, then by rule order
td.data { background-color: gray }
td.summary { background-color: white }
.total-summary { background-color: yellow }
<TD class="summary total-summary">
<!-- Still gray, baby :-( -->
</TD>
Benefits!
CSS specificity magic solved
Priority of CSS rules:
by specificity first, then by rule order
td.data { background-color: gray }
td.summary { background-color: white }
td.total-summary { background-color: yellow }
<TD class="summary total-summary">
<!-- This works, I'm yellow now -->
</TD>
Benefits!
Bye-bye CSS cascade?!
Only one CSS class needed to:
● style a block container
● style any element within a block
● add extras/overrides with a modifier
Doesn't it cover 90% of your styling
needs?
Benefits!
Bye-bye CSS cascade?!
...well, not exactly.
Example of an element affected by a block
modifier:
/* theme menu items for a dark theme */
.menu_theme_dark .menu__item
{
color: white;
background-color: darkgray;
}
HOWTO:
Block dependencies
LoginLoginpassword
Main
username
Download Help Contact
LoginLoginpassword
Main
username
Download Help Contact
headerheader
text inputtext input text inputtext input buttonbutton
menumenu
LoginLoginpassword
Main
username
Download Help Contact
_size_small _size_small _primary
LoginLoginpassword
Main
username
Download Help Contact
.header .input { font-size: 0.85em }
.header .button { background: navy }
LoginLoginpassword
Main
username
Download Help Contact
.header .input { font-size: 0.85em }
.header .button { background: navy } !
HOWTO: JavaScript
JavaScript
Components → Blocks
Work with BEM tree, not DOM tree
JavaScript deals with BEM
blockObj
blockObj.setMod('active');
// <div class=”block block_active”>
blockObj.delMod('active);
// <div class=”block”>
JavaScript deals with BEM
BlockObj.do({
'active': function() {
// do smth when active
},
'disabled': function() {
// do something when disabled
}
});
JavaScript
i-bem.js framework by Yandex +
tutorial
http://bit.ly/bem-js-tutorial/
● First English docs (expect more!)
● 100% BEM-based declarative API
● Part of a larger bem-core library
HTML is no longer semantic.
JavaScript is.
HOWTO: Design / UX
BEM is the universal language
for developers and designers,
the bridge across technology
gaps.
Build your block library.
The code itself is the styleguide.
UX + Frontend
● Live style guide
● Always up-to-date
● Prototyping mapped to code from
day one
● Designers and devs speak the
same language
● Good for making early estimates
HOWTO: File
structure
File and folder structure
Flat block structure with a folder for each block.
Simple structure for BEM beginners:
/block
block.css
block.js
block.tpl
...whatever you need
File and folder structure
Advanced structure to expose semantics
/block
/__elem1
block__elem1.css
block__elem1.tpl
/_mod
block_mod.css
block.css
block.js
block.tpl
Bundles for browsers
page.css:
@import url(“header/header.css”);
@import url(“button/button.css”);
@import url(“button/button_promo.css”);
page.js:
/* include: button.js */
/* include: login.js */
Build process and deployment
Use a build tool!
Borschik:
an open-source build tool by Yandex
Code:
https://github.com/bem/borschik
English docs:
http://bem.info/articles/borschik
http://bem.info
Thank you Booking!
@varya_en
http://varya.me

More Related Content

PDF
CSS - OOCSS, SMACSS and more
PDF
CSS For Backend Developers
PDF
BEM it! Introduction to BEM
PDF
BEM - CSS, Seriously
PDF
Learn BEM: CSS Naming Convention
PDF
BEM It! for Brandwatch
PDF
CSS Best practice
PPTX
An introduction to bootstrap
CSS - OOCSS, SMACSS and more
CSS For Backend Developers
BEM it! Introduction to BEM
BEM - CSS, Seriously
Learn BEM: CSS Naming Convention
BEM It! for Brandwatch
CSS Best practice
An introduction to bootstrap

What's hot (20)

PPTX
Introducing CSS Grid
PDF
Introduction to HTML and CSS
PPTX
Html training slide
PPT
Cascading Style Sheets (CSS) help
PDF
PDF
Flexbox and Grid Layout
PDF
The benefits of BEM CSS
PDF
Introduction to CSS3
PDF
OOCSS, SMACSS or BEM?
PDF
Intro to HTML and CSS basics
PPTX
Presentation about html5 css3
PPTX
(Fast) Introduction to HTML & CSS
PPTX
Bootstrap 3
PDF
Responsive Web Design Tutorial PDF for Beginners
PPTX
Bootstrap - Basics
PPTX
Html5 and-css3-overview
PPT
PDF
DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...
PPT
Intro Html
PPTX
Bootstrap Framework
Introducing CSS Grid
Introduction to HTML and CSS
Html training slide
Cascading Style Sheets (CSS) help
Flexbox and Grid Layout
The benefits of BEM CSS
Introduction to CSS3
OOCSS, SMACSS or BEM?
Intro to HTML and CSS basics
Presentation about html5 css3
(Fast) Introduction to HTML & CSS
Bootstrap 3
Responsive Web Design Tutorial PDF for Beginners
Bootstrap - Basics
Html5 and-css3-overview
DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...
Intro Html
Bootstrap Framework
Ad

Viewers also liked (19)

PDF
Foss economic-aspects-1
PDF
Introduction & Session 1 - Innovation
PDF
Magpie InsurTech Award Presentation
PPT
How much do our social roles impact our decisions?
PDF
Session 6 - Poll
PPT
Cicle formatiu de grau superior
PPT
Is the ideal worth pursuing?
PDF
археологическаякритика[1]
PPTX
trabajo 23/09/11
PPTX
Lessons for Africa’s Integration inspired by the EU Integration
PDF
nguyen ly co ban cua may dien
PPTX
Resume paket kab hal 63 66
PPTX
FailSafe IaaS
PDF
The Do-Gooder Industrial Complex?
PDF
Session 2 - Q&A
DOCX
Bdci u1 a1_rogp
PPTX
Ho w to get your dream job – the
PPTX
Apache solr i finn.no
PPT
Магический квадрат
Foss economic-aspects-1
Introduction & Session 1 - Innovation
Magpie InsurTech Award Presentation
How much do our social roles impact our decisions?
Session 6 - Poll
Cicle formatiu de grau superior
Is the ideal worth pursuing?
археологическаякритика[1]
trabajo 23/09/11
Lessons for Africa’s Integration inspired by the EU Integration
nguyen ly co ban cua may dien
Resume paket kab hal 63 66
FailSafe IaaS
The Do-Gooder Industrial Complex?
Session 2 - Q&A
Bdci u1 a1_rogp
Ho w to get your dream job – the
Apache solr i finn.no
Магический квадрат
Ad

Similar to BEM it! Introduction to BEM methodology (20)

PDF
BEM it!
PPTX
BEM methodology overview
PDF
PPTX
Let's BEM together
PDF
The Thinking behind BEM
PPTX
Bliblidotcom - Reintroduction BEM CSS
PDF
Workshop SASS for BEM development
PDF
BEM Methodology — @Frontenders Ticino —17/09/2014
PDF
BEM for Javascript at CampJS III
PPTX
Functional Css
PDF
Introduction to BEM Methodology
PDF
Maintainable Frontend Development with BEM
PDF
Bem methodology
PDF
BEM and Component Development
PDF
What is Modular CSS?
PPTX
MDN Development & Web Documentation
PDF
Managing Complex Projects with Design Components - Drupalcon Austin 2014
PDF
Css Systems
PPTX
BEVM ( block__element--variation -modifier)
BEM it!
BEM methodology overview
Let's BEM together
The Thinking behind BEM
Bliblidotcom - Reintroduction BEM CSS
Workshop SASS for BEM development
BEM Methodology — @Frontenders Ticino —17/09/2014
BEM for Javascript at CampJS III
Functional Css
Introduction to BEM Methodology
Maintainable Frontend Development with BEM
Bem methodology
BEM and Component Development
What is Modular CSS?
MDN Development & Web Documentation
Managing Complex Projects with Design Components - Drupalcon Austin 2014
Css Systems
BEVM ( block__element--variation -modifier)

More from Varya Stepanova (9)

PDF
Design systems on the web
PDF
SC5 Style Guide Generator
PDF
Modular development
PDF
BEM. What you can borrow from Yandex frontend dev
PDF
Тема для WordPress в БЭМ
PDF
Шаблонизатор BEMHTML
PDF
Использование библиотеки bem-bl
PDF
JavaScript в БЭМ терминах
KEY
Использование библиотеки bem-bl
Design systems on the web
SC5 Style Guide Generator
Modular development
BEM. What you can borrow from Yandex frontend dev
Тема для WordPress в БЭМ
Шаблонизатор BEMHTML
Использование библиотеки bem-bl
JavaScript в БЭМ терминах
Использование библиотеки bem-bl

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Encapsulation theory and applications.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
cuic standard and advanced reporting.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Electronic commerce courselecture one. Pdf
PPTX
Cloud computing and distributed systems.
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Spectroscopy.pptx food analysis technology
PPTX
MYSQL Presentation for SQL database connectivity
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Encapsulation theory and applications.pdf
A Presentation on Artificial Intelligence
Assigned Numbers - 2025 - Bluetooth® Document
cuic standard and advanced reporting.pdf
Machine learning based COVID-19 study performance prediction
20250228 LYD VKU AI Blended-Learning.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Electronic commerce courselecture one. Pdf
Cloud computing and distributed systems.
Review of recent advances in non-invasive hemoglobin estimation
Spectral efficient network and resource selection model in 5G networks
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Spectroscopy.pptx food analysis technology
MYSQL Presentation for SQL database connectivity
gpt5_lecture_notes_comprehensive_20250812015547.pdf

BEM it! Introduction to BEM methodology