NOTE I now use the conventions detailed in the SUIT framework
Used to provide structural templates.
Pattern
t-template-name
t-template-name--modifier-name
t-template-name__subcomponent-name--subcomponent-modifier-name
Examples
t-icon
t-icon--large
t-btn
t-btn--large
t-media
t-media__img
t-media__img--large
t-media__opt
t-media__body
Used to indicate the state of a component
Pattern
is-state-type
Examples
is-hidden
is-collapsed
is-expanded
is-selected
Used to provide JS-only hooks for a component. Can be used to provide a JS-enhanced UI or to abstract other JS behaviours.
Pattern
js-action-name
Examples
js-submit
js-action-save
js-ui-collapsible
js-ui-dropdown
js-ui-dropdown--control
js-ui-dropdown--menu
js-ui-carousel
Could reuse the Template Component naming convention, for example:
specific-name
specific-name--modifier-name
specific-name__subcomponent-name
specific-name__subcomponent-name--subcomponent-modifier-name
Or just let anything go.
@asakurayoh Looking at the jsperf tests for querying class selectors vs. data attribute selectors, I lean towards keep JS hooks as classes. It would be nice if querying performance was the same or at least not as big of a diff between the two. It would be nice to keep JS hooks separate from CSS hooks in the HTML markup.
I've started to adopt this BEM like syntax as well and mixing it with my understanding of SMACSS.
I've seen Jonathan Snook talk about using a syntax like:
I like this naming convention as well, though I like the double dash for modifiers.
Another naming convention I've thought about similar to the one above looks like:
The issue I see with this is it is hard to see the difference between modules and components when module names are made up of multiple words like product rating.
One way to get around this would be to use camelCase for module names and not use dashes in module names, only for modifiers (double) and components (single)
All of the naming conventions look odd at first. I think it is important to remind others the overall goal of a HTML class naming convention would be to add clarity for developers, I prefer the BEM like syntax the most, though it can take a while for other developers to understand the thinking behind it and go accustom to it .
I've put together a repo with a collection of common class naming patterns I've seen. CSS-Modules-Subcomponents-And-Modifiers-Collection