Salesforce Certified Platform User Experience Designer free question 10 / 10 · Domain 6: Salesforce Lightning Design System (SLDS)
A developer builds a new component whose block class is .slds-media-card. The component has a header part and a compact variation. Which pair of class names follows the Lightning Design System naming?
- .slds-media-card__header for the part and .slds-media-card__compact for the variation
- .slds-media-card__header for the part and .slds-media-card_compact for the variation
- .slds-media-card_header for the part and .slds-media-card__compact for the variation
- .slds-media-card-header for the part and .slds-media-card_compact for the variation
Show the answer and explanation
Answer: B
Why this is correct
The Markup and Style page builds on BEM. A block is the main component name, an element is a part of the component separated by two underscores, and a modifier is a variation of the component or of an element separated by a single underscore. The header part is therefore .slds-media-card__header and the compact variation is .slds-media-card_compact, which is added next to the base class.
Why the other options are wrong
".slds-media-card-header for the part and .slds-media-card_compact for the variation" … A single dash does not mean an element in BEM. The page says a single dash can be used for compound naming only, so a header part needs the double underscore to show that it belongs to the block.
".slds-media-card__header for the part and .slds-media-card__compact for the variation" … The variation uses two underscores here. The page gives modifiers a single underscore, and its example adds a modifier next to the base class, as in .house_gray beside .house.
".slds-media-card_header for the part and .slds-media-card__compact for the variation" … The two separators are swapped. The page gives the double underscore to elements and the single underscore to modifiers, so the part would be written with two underscores and the variation with one.
Underscores carry meaning
The page's house example uses .house as the block, .house__door as an element, and .house_gray as a modifier. It says to avoid names such as .house__stair__step and to use .house__stair-step instead.