BEM Syntax for CSS

Michael Walsh
By Michael WalshPublished

Why we've adopted the BEM syntax for our CSS classes and the advantages it brings to our web design work.

At the beginning of this year we adopted the BEM syntax for our CSS classes. BEM is an abbreviation for Block, Element and Modifier and it’s a syntax we apply to our CSS classes that is very well suited to object-oriented CSS. The BEM approach was first devised by front-end developers at Russian search engine Yandex but I first came across it by reading a post by Nicolas Gallagher.

So by using the BEM syntax, the CSS for a particular component will follow a pattern as follows:

.block {}
.block__element {}
.block--modifier {}

For example for each of our service areas on the services page we have the following CSS classes:

.service {}
.service__heading {}
.service__links {}

If we wanted to style a particular service area differently, perhaps with a border around it we could add a modifier to the class as follows:

.service--bordered {}

So the HTML markup for a service area with a border would be as follows:

<section class="service service--bordered">
<h2 class="service__heading">
...
</h2>
<div class="service__links">
...
</div>
</section>

The advantages of using BEM syntax for CSS are:

  • Our CSS classes are easier for other team members to understand as they can easily identify the components in the HTML and also the purpose of the CSS classes.
  • As classes are prefixed with the block it reduces the likelihood of accidentally having two classes with the same name, useful for larger projects.
  • Using a naming convention gives your CSS and HTML more consistency making it easier to share code between projects.

We use cookies to make this website work, to understand how it's used, and to measure our advertising. Find out more about cookies.

Cookie preferences

make an enquiry

Quick form · 3 steps · 1 min

How can we help?

Pick the closest match. We reply within one business day.

I am looking for

Website

New marketing website, microsite or redesign

E-commerce

Shopify store, new or rebuilt

Web application From £10,000 + VAT

Bespoke software and internal tools

AI implementation From £10,000 + VAT

Practical AI in your existing systems

Data visualisation From £10,000 + VAT

Dashboards and data pipelines

Migrations, hosting & support

Website migrations, web hosting and ongoing support

Something else / not sure yet

Let's talk it through

Prefer to talk?Book a call

Step 1 of 3

We'll be in touch within one business day to discuss your project. In the meantime, feel free to drop us a line at hello@enovate.co.uk if anything else comes up.

book directly

Book a discovery call with Michael

Michael Walsh, Founder & Managing Director. Pick a time that suits you, add your name and email, and the calendar invitation is yours.

Loading available times…

You can still book through the full calendar, orsend us a message.

Times shown in . The calendar invitation lands in your inbox the moment you confirm.

Booking is handled by Calendly; see our privacy policy.

You're booked in

(). The calendar invitation is on its way to .

RescheduleCancel