BEM, for real?

Yes, it's a Drake reference

Wed, 19 Dec 2018

Unsplash While I was working on building up my resume as a web page I found myself trying to figure out a nice way to name selectors in my CSS so they would be easy to figure out as I worked between the HTML and CSS. I came across a bunch of options but BEM - Block, Element, Modifier - seems to be simplest and easiest to pick up.

I’m going to use my resume as the basis of my example to explain BEM. I divided it into sections - profile, experience, skills and education. The first part of BEM is the Block which I like to think of as the parent. In my case that would be each section of my resume I’ve listed here. So for education you could have something like this:

.education {}

Now within the education section of my resume I list out the schools I attended. This leads us to the second part of BEM - the Element (or for me the child). To separate the two we use two underscores. The CSS for this would look something like this:

.education__school {}

The final part of BEM is the Modifier. These are used to modify the block to do things like apply color or change its size. We use two dashes to separate the block from the modifier. Keeping with our current example we might have something like this:

.education--big {}
.education--blue {}

This is a very basic example and breakdown of BEM. You can get a full detailed explanation of BEM at getbem.com.

SHARE
André Wanlin

André Wanlin is a Full Stack Developer and Team Leader at Petline Insurance Company, where André leads application development, including system administration and support. André has worked in .NET since 2008 and is passionate about DevOps and development methodologies like Lean, Agile, Scrum and Kanban. He loves to talk about Azure DevOps (formerly Team Foundation Server). André is a dog owner, an avid concert goer, and traveler from Winnipeg, Manitoba. You can reach him at andre@wanlin.ca or go to andre.wanlin.ca or you can catch him walking his dog at one of the many dog parks in the city.