Blog

An Introduction to Block Element Modifiers (BEM)

  • Articles
  • October 28 2022
  • 2 min read
Share

There are various methodologies that are found today with the aim of reducing CSS code and making it more maintainable. Well, in this article, we will learn one such example of methodology, called BEM. This methodology is excellent in speeding up the development process and also eases the teamwork of developers by efficiently arranging CSS classes into independent modules. BEM Methodology enhances code maintainability and also speeds up the development process.

Let’s look into the various aspects of this methodology and adapt it to our work processes in order to achieve our work endeavor. 

What is Block Element Modifier (BEM)?

BEM stands for Block Element Modifier. It is a design methodology that helps in creating reusable components and code sharing in front-end development. It is a system of methods that help in writing HTML and CSS code so it’s easy to reuse and even share with other parts of code. In large independent teams, it increases productivity and facilitates teamwork.

Let’s understand it in a much more detailed way below.

Blocks:  A block represents an object on a website. We can think of it as bigger structural chunks of code. Today the most common blocks on every website are content, header, footer, sidebar, and search. Blocks in BEM are a starting point for chaining CSS classes. A content, menu, search form, are some block examples. 

Element: An element is a component within the block that performs a specific function. The parts of a block that have no semantic meaning outside of the block are elements. Content article, a menu item, a search input field, are a few examples.

Modifier: A modifier is a way in which we represent the variations of a block. If anyone has used Bootstrap, then the finest example would be button sizes. Well, button sizes are size variations of the button itself, which makes it the modifier. A content featured article, a menu link, a search field with or without icon, are a few examples. 

Why Choose BEM?

Let’s now look at some of the advantages of this methodology.

  • BEM is exceptional when it comes to maintenance. Very commonly it is found that professionals find it difficult to work after someone on a large-scale project and make changes without something unknown collapsing. But while using BEM, one exactly gets to know the purpose of the element and also in which block it might appear.
  • We get to find that class names are logical and intuitive, and each and every member of the team is aware of what exactly the element does on the website. So, BEM tends to give everyone on a project a declarative syntax that they can share so that they are on the same page.
  • BEM helps in eliminating nested CSS selectors. Every single HTML element has its own CSS class, and by its name, one gets to know about its purpose. 

Conclusion

To sum up, BEM is a collection of methods and ideas, a methodology that every company and team can integrate into their existing workflow in a gradual manner and identify what works best for them.
 

Become our reader!

Get hand picked blogs directly in your inbox.
The subscriber's email address.