<div class="my-block my-block__my-element my-block__my-element--my-modifier">
becomes <div my-block="my-element my-modifier">
This solves for specificity, and uses built-in CSS features instead of a "manual" workaround. <div class="my-block my-block__my-element my-block__my-element--my-modifier">
becomes <div my-block="my-element my-modifier">
This solves for specificity, and uses built-in CSS features instead of a "manual" workaround. <div class="block">
<div class="block__item">
I am an item
</div>
<div class="block__item block__item--danger">
I am a dangerous item
</div>
</div>
Your simplification relies on an HTML hack and can potentially be more confusing when modifier names start colliding.https://www.smashingmagazine.com/2013/08/semantic-css-with-i...
<div data-my-block="my-element my-modifier">
It's still shorter, more readable and avoids repetitions. The difference becomes even more pronounced as the complexity of your styling goes up.To be fair, I don't know the latest performance figures on attribute selection.
The problem with this argument is that just a few years ago everything ReactJS does now was the wrong way, but for some reason today, it's the best way. So which is it?
It seems to me, that unless it's broken, or goes against an explicit rule from the browser/code designers of html/css etc... it's totally valid. And if it doesn't "feel correct", then maybe it's a trend waiting to happen. <sigh>inline javascript styles</sigh>
As far as I know right now, custom attributes goes against the html standard.
Inline styles for one... created with javascript no less. This was totally verboten not long ago. But then became a "best practice" only because React started doing it.