Course contentsShow
← Web Development
Lesson 1322 of 2,98224. CSS Architecture and MaintainabilityFree lesson

BEM Element Naming with Double Underscores

Naming child elements within a block using the block__element syntax.

BEM Element Naming with Double Underscores

You'll learn how to name child elements within a BEM block using the double-underscore syntax.

The Core Idea

In BEM, elements are the parts that make up a block. They're the children that live inside the parent block and help it function. To name these elements, you use a simple pattern: block__element. The double underscore (__) connects the block name to the element name, making their relationship crystal clear.

Think of it like a family name system: if "Smith" is your block (the family), then "Smith__kitchen" and "Smith__bedroom" are elements (rooms in that family's house). The double underscore shows these rooms belong to the Smith house.

Why Double Underscores?

The __ separator is distinctive and unlikely to appear accidentally in your naming. It creates a visual boundary that makes it instantly obvious which block owns which element.

Practical Example

/* Block */
.card { }

/* Elements within the card block */
.card__header { }
.card__title { }
.card__body { }
.card__footer { }
.card__image { }

Notice how every element name starts with the block name (card), followed by __, then the element's specific name. This tells you immediately that these elements are part of the card block and shouldn't exist independently.

Important Rules

  • Elements are always written as block__element, never just element
  • Elements belong to their block and shouldn't be used outside of it
  • Don't chain elements: use block__element, not block__element__subelement

Key Takeaway: Use the block__element naming pattern with double underscores to identify child elements that belong to a specific block, creating clear, self-documenting CSS class names.