
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
npm install bem-utilsbem-utils adds some sugar to writing out BEM-style classNames and CSS through the use of tagged template strings. BEM is great for your codebase, but it's hard to read and annoying to write. This module attempts
to make both of the aforementioned actually kind of fun :)
Start by importing the module and setting the block for the classNames or cssText you want to generate.
bem-utils has two main methods -- classNames(...) and css(...):
import BEM from 'bem-utils'
const BLOCK = 'Button'
let { classNames: cx, css } = BEM(BLOCK)
The @ symbol can be used to produce Block+Element classNames:
cx`@`
// -> Button
cx`@content`
// -> Button__content
cx`@content/text`
// -> Button__content__text
You may include any number of comma-separated modifiers following a trailing whitespace:
cx`@ default`
// -> Button--default
cx`@ big, active`
// -> Button--big Button--active
cx`@content dark outlined`
// -> Button__content--dark--outlined
cx`@content/text large, purple`
// -> Button__content__text--large Button__content__text--purple
When +@ is used at the start of the classString, the block+element className will always be printed in addition to modifier classNames:
cx`+@ default`
// -> Button Button--default
cx`+@content dark outlined`
// -> Button__content Button__content--dark--outlined
cx`+@content/text large, purple`
// -> Button__content__text Button__content__text--large Button__content__text--purple
If the leading +@ or @ is omitted, modifiers will be applied to the block:
cx`default`
// -> Button--default
cx`big, active`
// -> Button--big Button--active
cx`big, active, dark outlined`
// -> Button--big Button--active Button--dark--outlined
css`
.default ${`
color: #000;
`}
.default .content .icon.pink ${`
color: #fff;
background: pink;
border-radius: 4px 8px;
`}
.default.big span .text:hover .purple ${`
color: purple;
text-align: center;
text-decoration: none;
`}
`
The code above outputs the following css:
.Button--default {
color: #000;
}
.Button--default .Button__content .Button__content__icon--pink {
color: #fff;
background: pink;
border-radius: 4px 8px;
}
.Button--default--big span .Button__text:hover .Button__text__purple {
color: purple;
text-align: center;
text-decoration: none;
}
FAQs
Sugar for writing BEM-style classNames and CSS
We found that bem-utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.