Introduction
Introduction > What is BEM?
[block]__[element]--[modifier]
Introduction > Why BEM
// Examples:
header
container
checkbox
Block
Names may consist of Latin letters, digits, dashes and underscores
// HTML
<header class="block"></header>
// CSS
.block {
}
Block > Naming conventions
// Examples:
list item
header title
checkbox caption
Element
// HTML
<header class="block">
<span class="block__element"></span>
</header>
// CSS
.block {
}
.block__element {
}
Element > Naming conventions
// Examples:
disabled
checked
fixed
color
Modifier
Modifier > Naming conventions
// HTML
<header class="block block--big">
<span class="block__element"></span>
</header>
// CSS
.block {
}
.block--big {
}
.block__element {
}
Examples
Examples > Example 1: Blocks and elements
<form class="search">
<label class="search__label"></label>
<input type="text" class="search__input">
<button type="submit" class="search__submit">Search</button>
</form>
.search {
}
.search__label {
}
.search__input {
}
.search__submit {
}
Examples > Example 2: Blocks, elements and a modifier
<form class="search">
<label class="search__label"></label>
<input type="text" class="search__input">
<input type="text" class="search__input search__input--border">
<button type="submit" class="search__submit">Search</button>
</form>
.search {
}
.search__label {
}
.search__input {
}
.search__input--border {
}
.search__submit {
}
Examples > Example 3: Block and elements
<div class="block">
<div class="block__elem1">
<div class="block__elem2">
<div class="block__elem3"></div>
</div>
</div>
</div>
.block {
}
.block__elem3 {
}
.block__elem3 {
}
.block__elem3 {
}