· Documentation  · 2 min read

BEM Methodology

The BEM (Block, Element, Modifier) methodology is a naming convention for CSS classes that helps you build web interfaces in a more organized, reusable, and maintainable way. Created by the team at Yandex, BEM makes it easier to develop reusable components and maintain clear, scalable code.

The BEM (Block, Element, Modifier) methodology is a naming convention for CSS classes that helps you build web interfaces in a more organized, reusable, and maintainable way. Created by the team at Yandex, BEM makes it easier to develop reusable components and maintain clear, scalable code.

BEM Principles

  1. Block:A block is an independent entity that represents a fundamental component of the interface. Think of it as a container for a specific piece of functionality, like a button, a menu, or a header.Example: .button, .menu, .header

  2. Element:An element is a part of a block that doesn’t make sense on its own. It’s a subordinate component within a block. Example: .button__icon, .menu__item, .header__title

  3. Modifier:A modifier is a flag on a block or element. It changes the appearance or behavior of that block or element.Example: .button—primary, .menu__item—active, .header—large

Benefits of BEM

  1. Clarity and Consistency:BEM’s naming conventions provide a clear and consistent structure, making the code easy to read and understand, which is particularly useful in large teams.

  2. Reusability:Blocks and elements defined with BEM can be easily reused throughout the project, reducing code duplication and promoting modular development.

  3. Maintainability:Following BEM makes CSS easier to maintain. Developers can quickly locate the code related to a specific component and make changes without affecting other parts.

  4. Scalability:BEM is perfect for projects of any size, but it shines in large, complex projects. Its modular, clear structure supports scalability and growth without cluttering the code.

  5. Collaboration:BEM’s standardized naming improves collaboration between developers and designers. Everyone can understand and work with the code more efficiently.

Example of BEM in HTML and CSS

HTML

<div class="menu">
  <ul class="menu__list> 
    <li class="menu__item menu__item-active>Home</li>
    <li class="menu__item>About</li>
    <li class="menu__item>Contact</li>
  </ul>
</div>  

CSS

.menu {
  /*Styles for the menu block*/
} 
.menu__list {
  /*Styles for the list element within the menu block*/
}
.menu__Item {
  /*Styles for the item element within the menu block*/
}
.menu__Item--active {
  /*Styles for the active modifier applied to the item element*/
}

Benefits When Developing a Product

  1. Name Conflict Reduction:BEM minimizes name conflicts in CSS by providing a clear convention for naming blocks, elements, and modifiers.

  2. Componentization:Allows developers to break the interface into independent, reusable components, making maintenance and updates easier.

  3. Performance Improvement:Facilitates selective loading of styles and components, enhancing page performance.

  4. Ease of Refactoring:The clear structure of BEM makes code refactoring simpler and safer since changes to one component don’t affect others.

  5. Agile Development:BEM supports agile methodologies by enabling rapid iteration and improvement of components, aligning with continuous development and delivery cycles.

Additional Resources

For a deeper dive into BEM, check out these resources:

BEM Official Documentation
CSS-Tricks on BEM
Smashing Magazine on BEM
Back to Blog

Related Posts

View All Posts »
Managing a UX Team; My Experience and Tips

Managing a UX Team; My Experience and Tips

Managing a UX team is an exciting and challenging adventure. From creating a shared vision to implementing innovative solutions, every step requires a mix of leadership skills, creativity, and empathy.

Article Design System

Article Design System

Improve the user experience on the CT Article to increase the time our users spend on the site, this project impact to multiple sites of Televisa, principally TUDN and Las Estrellas.

Performance Improve

Performance Improve

When users surf a website, they generally look for visual information to confirm that everything is working as expected.Improve the user experience on the CT Gallery by focusing on performance metrics that are centered on the user.

Redesign the referral program at Aprende Institute

Redesign the referral program at Aprende Institute

One of my challenging tasks at Aprende Institute was to redesign the referral program. This program is important because it generates part of the revenue, and we need to understand the motivations of the students to refer others, as well as the needs of guests to convert them into students. This is an end-to-end product that was required careful consideration.